Showing
2 changed files
with
68 additions
and
55 deletions
@@ -29,67 +29,16 @@ const fav = { | @@ -29,67 +29,16 @@ const fav = { | ||
29 | 29 | ||
30 | const tab = req.query.tab; | 30 | const tab = req.query.tab; |
31 | const page = req.query.page; | 31 | const page = req.query.page; |
32 | - const result = []; | ||
33 | - let isend = true; | ||
34 | 32 | ||
35 | if (tab === 'brand') { | 33 | if (tab === 'brand') { |
36 | const gender = '1,2,3'; // todo 获取频道的性别 | 34 | const gender = '1,2,3'; // todo 获取频道的性别 |
37 | 35 | ||
38 | favModel.getFavBrandData(uid, gender, page, 10).then(data => { | 36 | favModel.getFavBrandData(uid, gender, page, 10).then(data => { |
39 | - if (data && page <= data.page_total) { | ||
40 | - data.brand_list.forEach(function(d) { | ||
41 | - result.push({ | ||
42 | - fav_id: d.brand_id, | ||
43 | - link: '', // todo | ||
44 | - imgUrl: d.brand_ico ? helpers.image(d.brand_ico, 160, 125) : '', | ||
45 | - brandName: d.brand_name, | ||
46 | - down: d.status === 0 | ||
47 | - }); | ||
48 | - }); | ||
49 | - | ||
50 | - if (page < data.page_total) { | ||
51 | - isend = false; | ||
52 | - } | ||
53 | - } | ||
54 | - return res.json({ | ||
55 | - isend: isend, | ||
56 | - list: result | ||
57 | - }); | 37 | + return res.json(data); |
58 | }); | 38 | }); |
59 | } else { | 39 | } else { |
60 | favModel.getFavProductData(uid, page, 10).then(data => { | 40 | favModel.getFavProductData(uid, page, 10).then(data => { |
61 | - if (data && page <= data.page_total) { | ||
62 | - data.product_list.forEach(function(d) { | ||
63 | - if (!d.product_skn) { | ||
64 | - return; | ||
65 | - } | ||
66 | - | ||
67 | - let link = ''; | ||
68 | - | ||
69 | - if (d.goodsId && d.cnAlphabet) { | ||
70 | - link = helpers.urlFormat(`/product/pro_${d.product_id}_${d.goodsId}/${d.cnAlphabet}.html`); | ||
71 | - } | ||
72 | - | ||
73 | - result.push({ | ||
74 | - fav_id: d.product_id, | ||
75 | - link: link, | ||
76 | - imgUrl: d.image ? helpers.image(d.image) : '', | ||
77 | - title: d.product_name, | ||
78 | - price: '¥' + Number(Math.max(d.market_price, 0)).toFixed(2), | ||
79 | - discountPrice: (Number(d.market_price) - Number(d.sales_price) > 0) ? '¥' + Number(Math.max(d.sales_price, 0)).toFixed(2) : false, | ||
80 | - sellOut: d.storage < 0, | ||
81 | - invalidGoods: d.status === 0 | ||
82 | - }); | ||
83 | - }); | ||
84 | - | ||
85 | - if (page < data.page_total) { | ||
86 | - isend = false; | ||
87 | - } | ||
88 | - } | ||
89 | - return res.json({ | ||
90 | - isend: isend, | ||
91 | - list: result | ||
92 | - }); | 41 | + return res.json(data); |
93 | }).catch(next); | 42 | }).catch(next); |
94 | } | 43 | } |
95 | }, | 44 | }, |
1 | 'use strict'; | 1 | 'use strict'; |
2 | const api = global.yoho.API; | 2 | const api = global.yoho.API; |
3 | +const helpers = global.yoho.helpers; | ||
3 | 4 | ||
4 | /** | 5 | /** |
5 | * 处理用户收藏的商品数据 | 6 | * 处理用户收藏的商品数据 |
@@ -16,7 +17,47 @@ exports.getFavProductData = (uid, page, limit) => { | @@ -16,7 +17,47 @@ exports.getFavProductData = (uid, page, limit) => { | ||
16 | page: page, | 17 | page: page, |
17 | limit: limit | 18 | limit: limit |
18 | }).then(result => { | 19 | }).then(result => { |
19 | - return result.data; | 20 | + var isend = true, |
21 | + list = [], | ||
22 | + data = result.data; | ||
23 | + | ||
24 | + if (data && page <= data.page_total) { | ||
25 | + data.product_list.forEach(function(d) { | ||
26 | + if (!d.product_skn) { | ||
27 | + return; | ||
28 | + } | ||
29 | + | ||
30 | + let link = ''; | ||
31 | + let discountPrice = false; | ||
32 | + | ||
33 | + if (d.goodsId && d.cnAlphabet) { | ||
34 | + link = helpers.urlFormat(`/product/pro_${d.product_id}_${d.goodsId}/${d.cnAlphabet}.html`); | ||
35 | + } | ||
36 | + | ||
37 | + if (Number(d.market_price) - Number(d.sales_price) > 0) { | ||
38 | + discountPrice = '¥' + Number(Math.max(d.sales_price, 0)).toFixed(2); | ||
39 | + } | ||
40 | + | ||
41 | + list.push({ | ||
42 | + fav_id: d.product_id, | ||
43 | + link: link, | ||
44 | + imgUrl: d.image ? helpers.image(d.image) : '', | ||
45 | + title: d.product_name, | ||
46 | + price: '¥' + Number(Math.max(d.market_price, 0)).toFixed(2), | ||
47 | + discountPrice: discountPrice, | ||
48 | + sellOut: d.storage < 0, | ||
49 | + invalidGoods: d.status === 0 | ||
50 | + }); | ||
51 | + }); | ||
52 | + | ||
53 | + if (page < data.page_total) { | ||
54 | + isend = false; | ||
55 | + } | ||
56 | + } | ||
57 | + return { | ||
58 | + isend: isend, | ||
59 | + list: list | ||
60 | + }; | ||
20 | }); | 61 | }); |
21 | }; | 62 | }; |
22 | 63 | ||
@@ -37,7 +78,30 @@ exports.getFavBrandData = (uid, gender, page, limit) => { | @@ -37,7 +78,30 @@ exports.getFavBrandData = (uid, gender, page, limit) => { | ||
37 | page: page, | 78 | page: page, |
38 | limit: limit | 79 | limit: limit |
39 | }).then(result => { | 80 | }).then(result => { |
40 | - return result.data; | 81 | + var isend = true, |
82 | + list = [], | ||
83 | + data = result.data; | ||
84 | + | ||
85 | + if (data && page <= data.page_total) { | ||
86 | + data.brand_list.forEach(function(d) { | ||
87 | + list.push({ | ||
88 | + fav_id: d.brand_id, | ||
89 | + link: '', // todo | ||
90 | + imgUrl: d.brand_ico ? helpers.image(d.brand_ico, 160, 125) : '', | ||
91 | + brandName: d.brand_name, | ||
92 | + down: d.status === 0 | ||
93 | + }); | ||
94 | + }); | ||
95 | + | ||
96 | + if (page < data.page_total) { | ||
97 | + isend = false; | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + return { | ||
102 | + isend: isend, | ||
103 | + list: list | ||
104 | + }; | ||
41 | }); | 105 | }); |
42 | }; | 106 | }; |
43 | 107 |
-
Please register or login to post a comment