Showing
2 changed files
with
10 additions
and
36 deletions
@@ -9,7 +9,6 @@ const channels = { | @@ -9,7 +9,6 @@ const channels = { | ||
9 | 9 | ||
10 | exports.productLst = function(req, res, next) { | 10 | exports.productLst = function(req, res, next) { |
11 | let keys = ['sort', 'misort', 'msort', 'gender', 'brand'], | 11 | let keys = ['sort', 'misort', 'msort', 'gender', 'brand'], |
12 | - enumParam = {}, | ||
13 | params = { | 12 | params = { |
14 | uid: req.query.uid, | 13 | uid: req.query.uid, |
15 | udid: req.query.udid, | 14 | udid: req.query.udid, |
@@ -29,21 +28,17 @@ exports.productLst = function(req, res, next) { | @@ -29,21 +28,17 @@ exports.productLst = function(req, res, next) { | ||
29 | 28 | ||
30 | if (params.specified_sort) { | 29 | if (params.specified_sort) { |
31 | if (params.brand) { | 30 | if (params.brand) { |
32 | - enumParam.brands = params.brand.split(','); | ||
33 | - params.limit = enumParam.brands.length; | 31 | + params.limit = params.brand.split(',').length; |
34 | } else if (params.sort) { | 32 | } else if (params.sort) { |
35 | - enumParam.sorts = params.sort.split(','); | ||
36 | - params.limit = enumParam.sorts.length; | 33 | + params.limit = params.sort.split(',').length; |
37 | } else if (params.misort) { | 34 | } else if (params.misort) { |
38 | - enumParam.misorts = params.misort.split(','); | ||
39 | - params.limit = enumParam.misorts.length; | 35 | + params.limit = params.misort.split(',').length; |
40 | } else if (params.msort) { | 36 | } else if (params.msort) { |
41 | - enumParam.msorts = params.msort.split(','); | ||
42 | - params.limit = enumParam.msorts.length; | 37 | + params.limit = params.msort.split(',').length; |
43 | } | 38 | } |
44 | } | 39 | } |
45 | 40 | ||
46 | - model.productLst(params, enumParam).then((result) => { | 41 | + model.productLst(params).then((result) => { |
47 | res.jsonp(result); | 42 | res.jsonp(result); |
48 | }).catch(next); | 43 | }).catch(next); |
49 | }; | 44 | }; |
@@ -3,9 +3,6 @@ | @@ -3,9 +3,6 @@ | ||
3 | const api = global.yoho.API; | 3 | const api = global.yoho.API; |
4 | 4 | ||
5 | let _getProduct = function(o) { | 5 | let _getProduct = function(o) { |
6 | - if (!o) { | ||
7 | - return {}; | ||
8 | - } | ||
9 | return { | 6 | return { |
10 | small_sort_id: o.small_sort_id, | 7 | small_sort_id: o.small_sort_id, |
11 | middle_sort_id: o.middle_sort_id, | 8 | middle_sort_id: o.middle_sort_id, |
@@ -27,34 +24,16 @@ let _getProduct = function(o) { | @@ -27,34 +24,16 @@ let _getProduct = function(o) { | ||
27 | }; | 24 | }; |
28 | 25 | ||
29 | module.exports = { | 26 | module.exports = { |
30 | - productLst: function(params, enumParam) { | 27 | + productLst: function(params) { |
31 | return api.get('', Object.assign({ | 28 | return api.get('', Object.assign({ |
32 | method: 'app.search.newPromotion' | 29 | method: 'app.search.newPromotion' |
33 | }, params)).then(res => { | 30 | }, params)).then(res => { |
34 | - var data = new Array(Number(params.limit)), | 31 | + var data = [], |
35 | lst = (res.data && res.data.product_list) || []; | 32 | lst = (res.data && res.data.product_list) || []; |
36 | 33 | ||
37 | - for (var i = 0; i < data.length; i++) { | ||
38 | - var o = lst[i] || {}; | ||
39 | - | ||
40 | - if (params.specified_sort) { | ||
41 | - // 枚举类型 | ||
42 | - if (enumParam.brands && Number(enumParam.brands[i]) === Number(o.brand_id)) { | ||
43 | - data[i] = _getProduct(o); | ||
44 | - } else if (enumParam.sorts && Number(enumParam.sorts[i]) === Number(o.small_sort_id)) { | ||
45 | - data[i] = _getProduct(o); | ||
46 | - } else if (enumParam.misorts && Number(enumParam.misorts[i]) === Number(o.middle_sort_id)) { | ||
47 | - data[i] = _getProduct(o); | ||
48 | - } else if (enumParam.msorts && Number(enumParam.msorts[i]) === Number(o.max_sort_id)) { | ||
49 | - data[i] = _getProduct(o); | ||
50 | - } else { | ||
51 | - lst.splice(i, 0, {}); | ||
52 | - data[i] = {}; | ||
53 | - } | ||
54 | - } else { | ||
55 | - data[i] = _getProduct(o); | ||
56 | - } | ||
57 | - } | 34 | + lst.forEach(function(o) { |
35 | + o && data.push(_getProduct(o)); | ||
36 | + }); | ||
58 | return data; | 37 | return data; |
59 | }); | 38 | }); |
60 | } | 39 | } |
-
Please register or login to post a comment