update for optimising code
Showing
2 changed files
with
36 additions
and
11 deletions
@@ -8,6 +8,20 @@ | @@ -8,6 +8,20 @@ | ||
8 | const outletModel = require('../models/outlet'); | 8 | const outletModel = require('../models/outlet'); |
9 | const headerModel = require('../../../doraemon/models/header'); | 9 | const headerModel = require('../../../doraemon/models/header'); |
10 | 10 | ||
11 | +const yhChannelEmpty = 0; | ||
12 | + | ||
13 | +const willEndActivity = { | ||
14 | + type: 2, | ||
15 | + template: 'outlet/will-end', | ||
16 | + page: 'outlet-will-end' | ||
17 | +} | ||
18 | + | ||
19 | +const willStartActivity = { | ||
20 | + type: 3, | ||
21 | + template: 'outlet/will-start', | ||
22 | + page: 'outlet-will-start' | ||
23 | +} | ||
24 | + | ||
11 | // 奥莱首页控制器 | 25 | // 奥莱首页控制器 |
12 | exports.index = (req, res, next) => { | 26 | exports.index = (req, res, next) => { |
13 | let headerData = headerModel.setNav({ | 27 | let headerData = headerModel.setNav({ |
@@ -16,7 +30,7 @@ exports.index = (req, res, next) => { | @@ -16,7 +30,7 @@ exports.index = (req, res, next) => { | ||
16 | }); | 30 | }); |
17 | 31 | ||
18 | let categoryId = req.query.category_id; | 32 | let categoryId = req.query.category_id; |
19 | - let yhChannel = req.query.yh_channel || 0; | 33 | + let yhChannel = req.query.yh_channel || yhChannelEmpty; |
20 | let contentcode = req.query.content_code; | 34 | let contentcode = req.query.content_code; |
21 | 35 | ||
22 | outletModel.getContent(categoryId, yhChannel, contentcode).then(result => { | 36 | outletModel.getContent(categoryId, yhChannel, contentcode).then(result => { |
@@ -48,15 +62,27 @@ exports.activityList = (req, res, next) => { | @@ -48,15 +62,27 @@ exports.activityList = (req, res, next) => { | ||
48 | navTitle: 'OUTLET', | 62 | navTitle: 'OUTLET', |
49 | navBtn: false | 63 | navBtn: false |
50 | }); | 64 | }); |
65 | + | ||
51 | let categoryId = req.query.category_id; | 66 | let categoryId = req.query.category_id; |
52 | - let type = req.query.type || 2; | ||
53 | - let template = parseInt(type, 10) === 2 ? 'outlet/will-end' : 'outlet/will-start'; | ||
54 | - let page = parseInt(type, 10) === 2 ? 'outlet-will-end' : 'outlet-will-start'; | 67 | + let type = req.query.type || willEndActivity.type; |
68 | + | ||
69 | + let template; | ||
70 | + let page; | ||
55 | 71 | ||
56 | if (!categoryId) { | 72 | if (!categoryId) { |
57 | throw new Error('No parent_id for OUTLET channel page!'); | 73 | throw new Error('No parent_id for OUTLET channel page!'); |
58 | } | 74 | } |
59 | 75 | ||
76 | + // 根据请求的类型确定要渲染的是即将结束页面还是上线预告页面 | ||
77 | + if (parseInt(type, 10) === willEndActivity.type) { | ||
78 | + template = willEndActivity.template; | ||
79 | + page = willEndActivity.page; | ||
80 | + } else { | ||
81 | + template = willStartActivity.template; | ||
82 | + page = willStartActivity.page; | ||
83 | + } | ||
84 | + | ||
85 | + | ||
60 | outletModel.getRecentActivity(type, categoryId).then(result => { | 86 | outletModel.getRecentActivity(type, categoryId).then(result => { |
61 | res.render(template, Object.assign({ | 87 | res.render(template, Object.assign({ |
62 | page: page, | 88 | page: page, |
@@ -97,7 +97,6 @@ const _convertNavData = (list) => { | @@ -97,7 +97,6 @@ const _convertNavData = (list) => { | ||
97 | */ | 97 | */ |
98 | const _getNavData = (categoryId) => { | 98 | const _getNavData = (categoryId) => { |
99 | const params = { | 99 | const params = { |
100 | - v: 7, | ||
101 | parent_id: categoryId | 100 | parent_id: categoryId |
102 | }; | 101 | }; |
103 | 102 | ||
@@ -162,10 +161,10 @@ const _convertActicityData = (data) => { | @@ -162,10 +161,10 @@ const _convertActicityData = (data) => { | ||
162 | const _getActivityDetail = (id) => { | 161 | const _getActivityDetail = (id) => { |
163 | var params = { | 162 | var params = { |
164 | method: 'app.outlets.activityGet', | 163 | method: 'app.outlets.activityGet', |
165 | - sort: 1, | ||
166 | - platform: 3, | 164 | + sort: 1, // 接口规定传1 |
165 | + platform: 3, // h5平台代号 | ||
167 | id: id, | 166 | id: id, |
168 | - type: 0 | 167 | + type: 0 // 接口规定传0 |
169 | }; | 168 | }; |
170 | 169 | ||
171 | 170 | ||
@@ -187,7 +186,7 @@ const _getActivityDetail = (id) => { | @@ -187,7 +186,7 @@ const _getActivityDetail = (id) => { | ||
187 | const _getHomeActivity = (data) => { | 186 | const _getHomeActivity = (data) => { |
188 | var params = { | 187 | var params = { |
189 | method: 'app.outlets.activityGet', | 188 | method: 'app.outlets.activityGet', |
190 | - platform: 3 | 189 | + platform: 3 // h5平台代号 |
191 | }; | 190 | }; |
192 | 191 | ||
193 | return api.get('', sign.apiSign(_.assign(params, data))).then(res => { | 192 | return api.get('', sign.apiSign(_.assign(params, data))).then(res => { |
@@ -204,7 +203,7 @@ const _getHomeActivity = (data) => { | @@ -204,7 +203,7 @@ const _getHomeActivity = (data) => { | ||
204 | */ | 203 | */ |
205 | const getContent = (categoryId, channel, code) => { | 204 | const getContent = (categoryId, channel, code) => { |
206 | let params = { | 205 | let params = { |
207 | - type: 0, | 206 | + type: 0, // 获取全部奥莱活动列表, 不区分是否将开始或结束 |
208 | yh_channel: channel | 207 | yh_channel: channel |
209 | }; | 208 | }; |
210 | 209 | ||
@@ -231,7 +230,7 @@ const getActivity = (id) => { | @@ -231,7 +230,7 @@ const getActivity = (id) => { | ||
231 | activity: res, | 230 | activity: res, |
232 | productPool: res[0] && res[0].productPoolId || '', | 231 | productPool: res[0] && res[0].productPoolId || '', |
233 | activityTitle: res[0] && res[0].title || 'OUTLET', | 232 | activityTitle: res[0] && res[0].title || 'OUTLET', |
234 | - saleType: 4 | 233 | + saleType: 4 // 促销类型, 奥莱为4 |
235 | }; | 234 | }; |
236 | }); | 235 | }); |
237 | }; | 236 | }; |
-
Please register or login to post a comment