Showing
3 changed files
with
55 additions
and
27 deletions
@@ -13,13 +13,10 @@ const searchApi = require(`${mRoot}/search-api`); | @@ -13,13 +13,10 @@ const searchApi = require(`${mRoot}/search-api`); | ||
13 | 13 | ||
14 | // 店铺页 | 14 | // 店铺页 |
15 | const shop = (shopId, req, res, next) => { | 15 | const shop = (shopId, req, res, next) => { |
16 | + shopId = parseInt(shopId, 10); | ||
16 | 17 | ||
17 | list.getShopInfo(shopId, req.user.id).then(shopInfo => { | 18 | list.getShopInfo(shopId, req.user.id).then(shopInfo => { |
18 | - shopInfo.shopTemplateType = 2; | ||
19 | - | ||
20 | - if (shopInfo.shopTemplateType === 2) { | ||
21 | - | ||
22 | - // 经典模板 | 19 | + if (+shopInfo.shopTemplateType === 2) { // 经典模板 |
23 | list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => { | 20 | list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => { |
24 | Object.assign(result, { | 21 | Object.assign(result, { |
25 | page: 'shop', | 22 | page: 'shop', |
@@ -27,10 +24,7 @@ const shop = (shopId, req, res, next) => { | @@ -27,10 +24,7 @@ const shop = (shopId, req, res, next) => { | ||
27 | }); | 24 | }); |
28 | res.render('list/shop-index', result); | 25 | res.render('list/shop-index', result); |
29 | }).catch(next); | 26 | }).catch(next); |
30 | - | ||
31 | - } else { | ||
32 | - | ||
33 | - // 基础模板 | 27 | + } else { // 基础模板 |
34 | list.getBaseShopData(shopId, req.user.id, req.query).then(result => { | 28 | list.getBaseShopData(shopId, req.user.id, req.query).then(result => { |
35 | res.render('list/index', result); | 29 | res.render('list/index', result); |
36 | }).catch(next); | 30 | }).catch(next); |
@@ -77,17 +71,15 @@ exports.new = (req, res, next) => { | @@ -77,17 +71,15 @@ exports.new = (req, res, next) => { | ||
77 | * @return {[type]} [description] | 71 | * @return {[type]} [description] |
78 | */ | 72 | */ |
79 | exports.brand = (req, res, next) => { | 73 | exports.brand = (req, res, next) => { |
74 | + let brandDomain = req.brandDomain || 'sctest1'; | ||
75 | + let shopId = req.query.shopId; | ||
80 | let resData = {}; | 76 | let resData = {}; |
81 | 77 | ||
82 | - // req.shopId存在,直接走店铺 | ||
83 | - if (req.shopId) { | ||
84 | - return shop(req.shopId, req, res, next); | 78 | + // shopId存在,直接走店铺 |
79 | + if (shopId) { | ||
80 | + return shop(shopId, req, res, next); | ||
85 | } | 81 | } |
86 | 82 | ||
87 | - // let brandDomain = 'colormad'; | ||
88 | - | ||
89 | - let brandDomain = req.brandDomain || 'sctest1'; | ||
90 | - | ||
91 | // 获取品牌信息 | 83 | // 获取品牌信息 |
92 | list.getBrandInfo({domain: brandDomain}).then(brandInfo => { | 84 | list.getBrandInfo({domain: brandDomain}).then(brandInfo => { |
93 | switch (parseInt(brandInfo.type, 10)) { | 85 | switch (parseInt(brandInfo.type, 10)) { |
@@ -326,8 +326,7 @@ exports.getShopInfo = (shopId, uid) => { | @@ -326,8 +326,7 @@ exports.getShopInfo = (shopId, uid) => { | ||
326 | showShopName: result.data.is_show_shop_name === 'Y' | 326 | showShopName: result.data.is_show_shop_name === 'Y' |
327 | }; | 327 | }; |
328 | } else { | 328 | } else { |
329 | - | ||
330 | - // log | 329 | + return {}; |
331 | } | 330 | } |
332 | }); | 331 | }); |
333 | }; | 332 | }; |
@@ -375,6 +374,8 @@ exports.getShopData = (shopId, channel, params, shopInfo) => { | @@ -375,6 +374,8 @@ exports.getShopData = (shopId, channel, params, shopInfo) => { | ||
375 | name: '全部商品 ALL', | 374 | name: '全部商品 ALL', |
376 | sort: searchHandler.handleOptsData(params, _.get(result[2], 'data.total', 0)), | 375 | sort: searchHandler.handleOptsData(params, _.get(result[2], 'data.total', 0)), |
377 | list: productProcess.processProductList(_.get(result[2], 'data.product_list', []), { | 376 | list: productProcess.processProductList(_.get(result[2], 'data.product_list', []), { |
377 | + newCoverSort: true, | ||
378 | + showDiscount: false, | ||
378 | gender: gender | 379 | gender: gender |
379 | }) | 380 | }) |
380 | }; | 381 | }; |
@@ -417,6 +418,8 @@ exports.getShopData = (shopId, channel, params, shopInfo) => { | @@ -417,6 +418,8 @@ exports.getShopData = (shopId, channel, params, shopInfo) => { | ||
417 | let coverList = {}; | 418 | let coverList = {}; |
418 | 419 | ||
419 | prodList = productProcess.processProductList(_.get(subRes[0], 'data.product_list', []), { | 420 | prodList = productProcess.processProductList(_.get(subRes[0], 'data.product_list', []), { |
421 | + newCoverSort: true, | ||
422 | + showDiscount: false, | ||
420 | gender: gender | 423 | gender: gender |
421 | }); | 424 | }); |
422 | 425 | ||
@@ -515,6 +518,8 @@ exports.getShopListData = (channel, params) => { | @@ -515,6 +518,8 @@ exports.getShopListData = (channel, params) => { | ||
515 | filters: searchHandler.handleFilterData(_.get(result[2], 'data.filter', {}), params), | 518 | filters: searchHandler.handleFilterData(_.get(result[2], 'data.filter', {}), params), |
516 | opts: searchHandler.handleOptsData(params, tip.total), | 519 | opts: searchHandler.handleOptsData(params, tip.total), |
517 | goods: productProcess.processProductList(_.get(result[2], 'data.product_list', []), { | 520 | goods: productProcess.processProductList(_.get(result[2], 'data.product_list', []), { |
521 | + newCoverSort: true, | ||
522 | + showDiscount: false, | ||
518 | gender: _getGender(channel) | 523 | gender: _getGender(channel) |
519 | }), | 524 | }), |
520 | footPager: {tip: tip} | 525 | footPager: {tip: tip} |
@@ -12,11 +12,15 @@ const images = require(`${global.utils}/images`); | @@ -12,11 +12,15 @@ const images = require(`${global.utils}/images`); | ||
12 | * 否则优先从cover1 --》 cover2 -- 》 images_url | 12 | * 否则优先从cover1 --》 cover2 -- 》 images_url |
13 | * | 13 | * |
14 | */ | 14 | */ |
15 | -const procProductImg = (product, gender) => { | 15 | +const procProductImg = (product, gender, newSort) => { |
16 | if (gender === '2,3') { | 16 | if (gender === '2,3') { |
17 | return product.cover2 || product.cover1 || product.imagesUrl || ''; | 17 | return product.cover2 || product.cover1 || product.imagesUrl || ''; |
18 | } | 18 | } |
19 | 19 | ||
20 | + if (newSort && gender === '1,2,3') { | ||
21 | + return product.imagesUrl || ''; | ||
22 | + } | ||
23 | + | ||
20 | return product.cover1 || product.cover2 || product.imagesUrl || ''; | 24 | return product.cover1 || product.cover2 || product.imagesUrl || ''; |
21 | }; | 25 | }; |
22 | 26 | ||
@@ -39,7 +43,35 @@ const handleGoodsListData = (origin) => { | @@ -39,7 +43,35 @@ const handleGoodsListData = (origin) => { | ||
39 | }; | 43 | }; |
40 | 44 | ||
41 | /** | 45 | /** |
42 | - * 根据性别来决定 默认图片获取字段 如果是 2、3 | 46 | + * 处理搜索返回同一skc分男女封分别返回问题 |
47 | + * @param array $images | ||
48 | + * @return string 商品图片 | ||
49 | + */ | ||
50 | +const procGoodsList = (goodsList) => { | ||
51 | + let list = {}; | ||
52 | + | ||
53 | + if (!_.isEmpty(goodsList)) { | ||
54 | + let goods = _.cloneDeep(goodsList); | ||
55 | + | ||
56 | + _.forEach(goods, value => { | ||
57 | + if (!list[value.productSkc]) { | ||
58 | + list[value.productSkc] = value; | ||
59 | + } else { | ||
60 | + if (value.cover1) { | ||
61 | + list[value.productSkc].cover1 = value.cover1; | ||
62 | + } | ||
63 | + if (value.cover2) { | ||
64 | + list[value.productSkc].cover2 = value.cover2; | ||
65 | + } | ||
66 | + } | ||
67 | + }); | ||
68 | + } | ||
69 | + | ||
70 | + return _.toArray(list); | ||
71 | +}; | ||
72 | + | ||
73 | +/** | ||
74 | + * 处理 | ||
43 | * | 75 | * |
44 | * 2、3: cover2 --> images_url -> cover1 | 76 | * 2、3: cover2 --> images_url -> cover1 |
45 | * 1,3 :cover1 --> images_url -> cover2 | 77 | * 1,3 :cover1 --> images_url -> cover2 |
@@ -72,9 +104,8 @@ exports.processProductList = (list, options) => { | @@ -72,9 +104,8 @@ exports.processProductList = (list, options) => { | ||
72 | showTags: true, | 104 | showTags: true, |
73 | showNew: true, | 105 | showNew: true, |
74 | showSale: true, | 106 | showSale: true, |
75 | - | ||
76 | - // 显示折扣 | ||
77 | - showDiscount: true, | 107 | + showDiscount: true, // 显示折扣 |
108 | + newCoverSort: false, // 新封面排序 | ||
78 | width: 290, | 109 | width: 290, |
79 | height: 388, | 110 | height: 388, |
80 | isApp: false, | 111 | isApp: false, |
@@ -105,17 +136,17 @@ exports.processProductList = (list, options) => { | @@ -105,17 +136,17 @@ exports.processProductList = (list, options) => { | ||
105 | } | 136 | } |
106 | 137 | ||
107 | // 如果设置了默认图片,就取默认的图片 | 138 | // 如果设置了默认图片,就取默认的图片 |
108 | - _.forEach(product.goodsList, (goods) => { | 139 | + _.forEach(procGoodsList(product.goodsList), (goods) => { |
109 | 140 | ||
110 | // (颜色优先) | 141 | // (颜色优先) |
111 | if (options.color) { | 142 | if (options.color) { |
112 | if (goods.colorId === options.color) { | 143 | if (goods.colorId === options.color) { |
113 | - product.defaultImages = procProductImg(goods, options.gender); | 144 | + product.defaultImages = procProductImg(goods, options.gender, options.newCoverSort); |
114 | return; | 145 | return; |
115 | } | 146 | } |
116 | } else { | 147 | } else { |
117 | if (goods.isDefault === 'Y') { | 148 | if (goods.isDefault === 'Y') { |
118 | - product.defaultImages = procProductImg(goods, options.gender); | 149 | + product.defaultImages = procProductImg(goods, options.gender, options.newCoverSort); |
119 | return; | 150 | return; |
120 | } | 151 | } |
121 | } | 152 | } |
@@ -123,7 +154,7 @@ exports.processProductList = (list, options) => { | @@ -123,7 +154,7 @@ exports.processProductList = (list, options) => { | ||
123 | 154 | ||
124 | // 如果还未赋值,则取第一个skc产品的默认图片 | 155 | // 如果还未赋值,则取第一个skc产品的默认图片 |
125 | if (!product.defaultImages) { | 156 | if (!product.defaultImages) { |
126 | - product.defaultImages = procProductImg(product.goodsList[0]); | 157 | + product.defaultImages = procProductImg(product.goodsList[0], options.gender, options.newCoverSort); |
127 | } | 158 | } |
128 | 159 | ||
129 | product = Object.assign(product, { | 160 | product = Object.assign(product, { |
-
Please register or login to post a comment