Authored by biao

update for optimising code

... ... @@ -8,6 +8,20 @@
const outletModel = require('../models/outlet');
const headerModel = require('../../../doraemon/models/header');
const yhChannelEmpty = 0;
const willEndActivity = {
type: 2,
template: 'outlet/will-end',
page: 'outlet-will-end'
}
const willStartActivity = {
type: 3,
template: 'outlet/will-start',
page: 'outlet-will-start'
}
// 奥莱首页控制器
exports.index = (req, res, next) => {
let headerData = headerModel.setNav({
... ... @@ -16,7 +30,7 @@ exports.index = (req, res, next) => {
});
let categoryId = req.query.category_id;
let yhChannel = req.query.yh_channel || 0;
let yhChannel = req.query.yh_channel || yhChannelEmpty;
let contentcode = req.query.content_code;
outletModel.getContent(categoryId, yhChannel, contentcode).then(result => {
... ... @@ -48,15 +62,27 @@ exports.activityList = (req, res, next) => {
navTitle: 'OUTLET',
navBtn: false
});
let categoryId = req.query.category_id;
let type = req.query.type || 2;
let template = parseInt(type, 10) === 2 ? 'outlet/will-end' : 'outlet/will-start';
let page = parseInt(type, 10) === 2 ? 'outlet-will-end' : 'outlet-will-start';
let type = req.query.type || willEndActivity.type;
let template;
let page;
if (!categoryId) {
throw new Error('No parent_id for OUTLET channel page!');
}
// 根据请求的类型确定要渲染的是即将结束页面还是上线预告页面
if (parseInt(type, 10) === willEndActivity.type) {
template = willEndActivity.template;
page = willEndActivity.page;
} else {
template = willStartActivity.template;
page = willStartActivity.page;
}
outletModel.getRecentActivity(type, categoryId).then(result => {
res.render(template, Object.assign({
page: page,
... ...
... ... @@ -97,7 +97,6 @@ const _convertNavData = (list) => {
*/
const _getNavData = (categoryId) => {
const params = {
v: 7,
parent_id: categoryId
};
... ... @@ -162,10 +161,10 @@ const _convertActicityData = (data) => {
const _getActivityDetail = (id) => {
var params = {
method: 'app.outlets.activityGet',
sort: 1,
platform: 3,
sort: 1, // 接口规定传1
platform: 3, // h5平台代号
id: id,
type: 0
type: 0 // 接口规定传0
};
... ... @@ -187,7 +186,7 @@ const _getActivityDetail = (id) => {
const _getHomeActivity = (data) => {
var params = {
method: 'app.outlets.activityGet',
platform: 3
platform: 3 // h5平台代号
};
return api.get('', sign.apiSign(_.assign(params, data))).then(res => {
... ... @@ -204,7 +203,7 @@ const _getHomeActivity = (data) => {
*/
const getContent = (categoryId, channel, code) => {
let params = {
type: 0,
type: 0, // 获取全部奥莱活动列表, 不区分是否将开始或结束
yh_channel: channel
};
... ... @@ -231,7 +230,7 @@ const getActivity = (id) => {
activity: res,
productPool: res[0] && res[0].productPoolId || '',
activityTitle: res[0] && res[0].title || 'OUTLET',
saleType: 4
saleType: 4 // 促销类型, 奥莱为4
};
});
};
... ...