Showing
9 changed files
with
107 additions
and
152 deletions
@@ -358,22 +358,13 @@ const modifyPriceGift = (req, res, next) => { | @@ -358,22 +358,13 @@ const modifyPriceGift = (req, res, next) => { | ||
358 | * [获取赠品商品列表] | 358 | * [获取赠品商品列表] |
359 | */ | 359 | */ |
360 | const gift = (req, res, next) => { | 360 | const gift = (req, res, next) => { |
361 | - let uid = req.user && req.user.uid, | ||
362 | - shoppingKey = req.cookies._SPK || '', | ||
363 | - channel = req.cookies._Channel, | ||
364 | - cartType = req.cookies.cartType || 'ordinary', | ||
365 | - promotionId = req.query.promotion_id; | ||
366 | - | ||
367 | - // shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923'; | ||
368 | - // uid = 20422448; | ||
369 | - let promise; | 361 | + let cartType = req.cookies.cartType || 'ordinary', |
362 | + promotionIds = req.query.promotion_ids; | ||
370 | 363 | ||
371 | - if (promotionId) { | ||
372 | - promise = indexModel.getPriceGiftList(promotionId); | ||
373 | - } else { | ||
374 | - promise = indexModel.indexData(uid, shoppingKey, channel, cartType, true); | 364 | + if (!promotionIds) { |
365 | + return next(); | ||
375 | } | 366 | } |
376 | - return promise.then(data => { | 367 | + return indexModel.getPriceGiftList(promotionIds, 'Gift').then(data => { |
377 | res.render('gift', Object.assign(data, { | 368 | res.render('gift', Object.assign(data, { |
378 | title: '赠品', | 369 | title: '赠品', |
379 | module: 'cart', | 370 | module: 'cart', |
@@ -398,22 +389,13 @@ const gift = (req, res, next) => { | @@ -398,22 +389,13 @@ const gift = (req, res, next) => { | ||
398 | * [获取加价购商品列表] | 389 | * [获取加价购商品列表] |
399 | */ | 390 | */ |
400 | const advanceBuy = (req, res, next) => { | 391 | const advanceBuy = (req, res, next) => { |
401 | - let uid = req.user && req.user.uid, | ||
402 | - shoppingKey = req.cookies._SPK || '', | ||
403 | - channel = req.cookies._Channel, | ||
404 | - cartType = req.cookies.cartType || 'ordinary', | ||
405 | - promotionId = req.query.promotion_id; | ||
406 | - | ||
407 | - // shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923'; | ||
408 | - // uid = 20422448; | ||
409 | - let promise; | 392 | + let cartType = req.cookies.cartType || 'ordinary', |
393 | + promotionIds = req.query.promotion_ids; | ||
410 | 394 | ||
411 | - if (promotionId) { | ||
412 | - promise = indexModel.getPriceGiftList(promotionId); | ||
413 | - } else { | ||
414 | - promise = indexModel.indexData(uid, shoppingKey, channel, cartType, false, true); | 395 | + if (!promotionIds) { |
396 | + return next(); | ||
415 | } | 397 | } |
416 | - return promise.then(data => { | 398 | + return indexModel.getPriceGiftList(promotionIds, 'Needpaygift').then(data => { |
417 | res.render('gift', Object.assign(data, { | 399 | res.render('gift', Object.assign(data, { |
418 | title: '加价购', | 400 | title: '加价购', |
419 | module: 'cart', | 401 | module: 'cart', |
@@ -14,18 +14,16 @@ const cartProcess = require(global.utils + '/cart-process'); | @@ -14,18 +14,16 @@ const cartProcess = require(global.utils + '/cart-process'); | ||
14 | * @param integer $uid 用户ID | 14 | * @param integer $uid 用户ID |
15 | * @param string $shoppingKey 未登录用户唯一识别码 | 15 | * @param string $shoppingKey 未登录用户唯一识别码 |
16 | * @param string $cartType 购物车类型,默认是是所有购物车,ordinary为普通购物车,advance为预售购物车 | 16 | * @param string $cartType 购物车类型,默认是是所有购物车,ordinary为普通购物车,advance为预售购物车 |
17 | - * @param bool $onlyGift 只获取赠品的商品数据 | ||
18 | - * @param bool $onlyAdvanceBuy 只获取加价购的商品数据 | ||
19 | * @return array|mixed 处理之后的购物车数据 | 17 | * @return array|mixed 处理之后的购物车数据 |
20 | */ | 18 | */ |
21 | -const indexData = (uid, shoppingKey, saleChannel, cartType, onlyGift, onlyAdvanceBuy) => { | 19 | +const indexData = (uid, shoppingKey, saleChannel, cartType) => { |
22 | return api.get('', { | 20 | return api.get('', { |
23 | method: 'app.Shopping.queryCart', | 21 | method: 'app.Shopping.queryCart', |
24 | uid: uid, | 22 | uid: uid, |
25 | shopping_key: shoppingKey, | 23 | shopping_key: shoppingKey, |
26 | sale_channel: saleChannel | 24 | sale_channel: saleChannel |
27 | }).then((data) => { | 25 | }).then((data) => { |
28 | - return data.code === 200 ? cartProcess.processData(data, cartType, onlyGift, onlyAdvanceBuy) : undefined; | 26 | + return data.code === 200 ? cartProcess.processData(data, cartType) : undefined; |
29 | }); | 27 | }); |
30 | }; | 28 | }; |
31 | 29 | ||
@@ -238,12 +236,12 @@ const giftProductData = (skn, promotionId) => { | @@ -238,12 +236,12 @@ const giftProductData = (skn, promotionId) => { | ||
238 | /** | 236 | /** |
239 | * [获取赠品、加价购促销商品列表] | 237 | * [获取赠品、加价购促销商品列表] |
240 | */ | 238 | */ |
241 | -const getPriceGiftList = (promotionId) => { | 239 | +const getPriceGiftList = (promotionIds, promotionType) => { |
242 | return api.get('', { | 240 | return api.get('', { |
243 | - method: 'app.Shopping.queryPromotionGift', | ||
244 | - promotion_id: promotionId | 241 | + method: 'app.Shopping.queryPromotionGifts', |
242 | + promotion_ids: promotionIds | ||
245 | }).then((data) => { | 243 | }).then((data) => { |
246 | - return data.code === 200 ? cartProcess.procPriceGiftData(data.data) : undefined; | 244 | + return data.code === 200 ? cartProcess.procPriceGiftData(data.data, promotionType) : undefined; |
247 | }); | 245 | }); |
248 | }; | 246 | }; |
249 | 247 |
1 | <div class="gift-advance-page yoho-page"> | 1 | <div class="gift-advance-page yoho-page"> |
2 | - {{#if advanceBuyPage}} | ||
3 | - {{# advanceBuy}} | ||
4 | - <div class="advance-block" data-promotion-id="{{promotionId}}"> | ||
5 | - <p class="title">{{promotionTitle}}</p> | ||
6 | - {{#goods}} | ||
7 | - {{> cart/gift-advance-good}} | ||
8 | - {{/goods}} | ||
9 | - </div> | ||
10 | - {{/ advanceBuy}} | ||
11 | - {{else}} | ||
12 | - {{# freebie}} | ||
13 | - <div class="advance-block gift-block" data-promotion-id="{{promotionId}}"> | ||
14 | - <p class="title">{{promotionTitle}}</p> | ||
15 | - {{#goods}} | ||
16 | - {{> cart/gift-advance-good}} | ||
17 | - {{/goods}} | ||
18 | - </div> | ||
19 | - {{/ freebie}} | ||
20 | - {{/if}} | 2 | + {{#promotionTitle}}<p class="title">{{.}}</p>{{/promotionTitle}} |
3 | + {{# gifts}} | ||
4 | + <div class="advance-block{{#if isGift}} gift-block{{/if}}" data-promotion-id="{{promotionId}}"> | ||
5 | + {{#goods}} | ||
6 | + {{> cart/gift-advance-good}} | ||
7 | + {{/goods}} | ||
8 | + </div> | ||
9 | + {{/ gifts}} | ||
21 | <div id="chose-panel"></div> | 10 | <div id="chose-panel"></div> |
22 | </div> | 11 | </div> |
@@ -57,7 +57,7 @@ | @@ -57,7 +57,7 @@ | ||
57 | </div> | 57 | </div> |
58 | {{#if freebieOrAdvanceBuy}} | 58 | {{#if freebieOrAdvanceBuy}} |
59 | <div class="all-gift-box box"> | 59 | <div class="all-gift-box box"> |
60 | - {{#if giftCount}} | 60 | + {{#if freebie.length}} |
61 | <div class="gift-item freebie"> | 61 | <div class="gift-item freebie"> |
62 | <div class="flag"> | 62 | <div class="flag"> |
63 | <i class="iconfont gift"></i> | 63 | <i class="iconfont gift"></i> |
@@ -70,7 +70,7 @@ | @@ -70,7 +70,7 @@ | ||
70 | </div> | 70 | </div> |
71 | </div> | 71 | </div> |
72 | {{/if}} | 72 | {{/if}} |
73 | - {{#if advanceBuyCount}} | 73 | + {{#if advanceBuy.length}} |
74 | <div class="gift-item advanceBuy"> | 74 | <div class="gift-item advanceBuy"> |
75 | <div class="flag"> | 75 | <div class="flag"> |
76 | <i class="iconfont price-gift"></i> | 76 | <i class="iconfont price-gift"></i> |
@@ -44,11 +44,11 @@ function getProductInfo(skn, promotionId) { | @@ -44,11 +44,11 @@ function getProductInfo(skn, promotionId) { | ||
44 | chosePanel.setEditModeWithSknId(skn, true, true); | 44 | chosePanel.setEditModeWithSknId(skn, true, true); |
45 | chosePanel.disableNumEdit(); | 45 | chosePanel.disableNumEdit(); |
46 | chosePanel.show('', function() { | 46 | chosePanel.show('', function() { |
47 | - window.location.href = '/cart/index/index?cartType=' + queryString.cartType; | 47 | + window.location.href = '/cart/index/index'; |
48 | }); | 48 | }); |
49 | } else { | 49 | } else { |
50 | chosePanel.show(html, function() { | 50 | chosePanel.show(html, function() { |
51 | - window.location.href = '/cart/index/index?cartType=' + queryString.cartType; | 51 | + window.location.href = '/cart/index/index'; |
52 | }); | 52 | }); |
53 | } | 53 | } |
54 | 54 |
@@ -15,6 +15,7 @@ let $ = require('yoho-jquery'), | @@ -15,6 +15,7 @@ let $ = require('yoho-jquery'), | ||
15 | loading = require('../plugin/loading'); | 15 | loading = require('../plugin/loading'); |
16 | 16 | ||
17 | let indexObj = { | 17 | let indexObj = { |
18 | + cartData: {}, | ||
18 | editMode: false, | 19 | editMode: false, |
19 | posting: false, | 20 | posting: false, |
20 | init() { | 21 | init() { |
@@ -75,12 +76,15 @@ let indexObj = { | @@ -75,12 +76,15 @@ let indexObj = { | ||
75 | if (data.commonGoodsCount === 0 && data.ordinarySoldOut === 0) { | 76 | if (data.commonGoodsCount === 0 && data.ordinarySoldOut === 0) { |
76 | data.cartNav = false; | 77 | data.cartNav = false; |
77 | data.cartType = 'advance'; | 78 | data.cartType = 'advance'; |
79 | + self.cartData = data.preSellCart; | ||
78 | } else if (data.presellGoodsCount === 0 && data.advanceSoldOut === 0) { // 预售购物车空,则显示普通购物车 | 80 | } else if (data.presellGoodsCount === 0 && data.advanceSoldOut === 0) { // 预售购物车空,则显示普通购物车 |
79 | data.cartNav = false; | 81 | data.cartNav = false; |
80 | data.cartType = 'ordinary'; | 82 | data.cartType = 'ordinary'; |
83 | + self.cartData = data.commonCart; | ||
81 | } else { // 以上两个购物车中都有数据, 默认显示普通购物车 | 84 | } else { // 以上两个购物车中都有数据, 默认显示普通购物车 |
82 | data.cartNav = true; | 85 | data.cartNav = true; |
83 | data.cartType = cartType || 'ordinary'; | 86 | data.cartType = cartType || 'ordinary'; |
87 | + self.cartData = data.commonCart; | ||
84 | } | 88 | } |
85 | cookie.set('_cartType', data.cartType); | 89 | cookie.set('_cartType', data.cartType); |
86 | data.ordinaryCart = data.cartType === 'ordinary'; | 90 | data.ordinaryCart = data.cartType === 'ordinary'; |
@@ -62,45 +62,49 @@ let cartObj = { | @@ -62,45 +62,49 @@ let cartObj = { | ||
62 | status = $(e.currentTarget).data('status'), | 62 | status = $(e.currentTarget).data('status'), |
63 | promotionTitle = encodeURIComponent(`以下商品参加【${$(e.currentTarget).data('title')}】促销活动`); | 63 | promotionTitle = encodeURIComponent(`以下商品参加【${$(e.currentTarget).data('title')}】促销活动`); |
64 | 64 | ||
65 | - self.toPromotionPage({ | ||
66 | - promotionType, | ||
67 | - promotionId, | ||
68 | - promotionTitle, | ||
69 | - status | ||
70 | - }); | ||
71 | - }, | ||
72 | - toPromotionPage(opts) { | ||
73 | - let cartType = cookie.get('_cartType') || 'ordinary'; | ||
74 | - let title = encodeURIComponent('优惠活动商品'); | ||
75 | - let href; | ||
76 | - | ||
77 | - if (opts.status === 20 || opts.status === 0 || (opts.promotionType !== 'Gift' && opts.promotionType !== 'Needpaygift')) { | ||
78 | - href = `/product/index/index?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`; | ||
79 | - } else if (opts.promotionType === 'Gift') { | ||
80 | - href = `/cart/index/new/gift?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`; | ||
81 | - if (opts.status === 30) { | ||
82 | - href += '&edit=1'; | ||
83 | - } | ||
84 | - } else if (opts.promotionType === 'Needpaygift') { | ||
85 | - href = `/cart/index/new/advanceBuy?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`; | ||
86 | - if (opts.status === 30) { | ||
87 | - href += '&edit=1'; | ||
88 | - } | 65 | + if (status === 20 || status === 0 || (promotionType !== 'Gift' && promotionType !== 'Needpaygift')) { |
66 | + window.location.href = `/product/index/index?promotion_id=${promotionId}&title=优惠活动商品&intro_text=${promotionTitle}`; | ||
67 | + } else { | ||
68 | + self.toPromotionPage(promotionId, promotionType, status); | ||
89 | } | 69 | } |
90 | - window.location.href = href; | ||
91 | }, | 70 | }, |
92 | allGiftBoxClick(e) { | 71 | allGiftBoxClick(e) { |
93 | - let cartType = cookie.get('_cartType') || 'ordinary'; | 72 | + let self = this; |
73 | + let promotionIds; | ||
94 | 74 | ||
95 | if ($(e.currentTarget).find('.no-storage').length) { | 75 | if ($(e.currentTarget).find('.no-storage').length) { |
96 | return; | 76 | return; |
97 | } | 77 | } |
98 | if ($(e.currentTarget).hasClass('advanceBuy')) { | 78 | if ($(e.currentTarget).hasClass('advanceBuy')) { |
99 | - window.location.href = '/cart/index/new/advanceBuy?cartType=' + cartType; | 79 | + if (self.handle.cartData.selectAdvanceBuy) { |
80 | + promotionIds = self.handle.cartData.selectAdvanceBuy.map(advanceBuy => { | ||
81 | + return advanceBuy.promotion_id; | ||
82 | + }); | ||
83 | + self.toPromotionPage(promotionIds, 'Needpaygift'); | ||
84 | + } | ||
100 | } else { | 85 | } else { |
101 | - window.location.href = '/cart/index/new/gift?cartType=' + cartType; | 86 | + if (self.handle.cartData.selectFreebie) { |
87 | + promotionIds = self.handle.cartData.selectFreebie.map(freebie => { | ||
88 | + return freebie.promotion_id; | ||
89 | + }); | ||
90 | + self.toPromotionPage(promotionIds, 'Gift'); | ||
91 | + } | ||
102 | } | 92 | } |
103 | }, | 93 | }, |
94 | + toPromotionPage(promotioIds, promotionType, status) { | ||
95 | + let href; | ||
96 | + let cartType = cookie.get('_cartType') || 'ordinary'; | ||
97 | + | ||
98 | + if (promotionType === 'Gift') { | ||
99 | + href = `/cart/index/new/gift?promotion_ids=${promotioIds}&cartType=${cartType}`; | ||
100 | + } else { | ||
101 | + href = `/cart/index/new/advanceBuy?promotion_ids=${promotioIds}&cartType=${cartType}`; | ||
102 | + } | ||
103 | + if (status === 30) { | ||
104 | + href += '&edit=1'; | ||
105 | + } | ||
106 | + window.location.href = href; | ||
107 | + }, | ||
104 | balanceClick() { | 108 | balanceClick() { |
105 | let self = this; | 109 | let self = this; |
106 | let cartType = cookie.get('_cartType') || 'ordinary'; | 110 | let cartType = cookie.get('_cartType') || 'ordinary'; |
@@ -130,7 +134,7 @@ let cartObj = { | @@ -130,7 +134,7 @@ let cartObj = { | ||
130 | tip.show('请先勾选商品'); | 134 | tip.show('请先勾选商品'); |
131 | return false; | 135 | return false; |
132 | } | 136 | } |
133 | - if ($('.all-gift-box>.freebie').length || $('.promo-item[data-type="Gift"][data-status="10"]').length) { | 137 | + if (!cookie.get('_realyGift') && self.handle.cartData.matchGifts && self.handle.cartData.matchGifts.length) { |
134 | dialog.showDialog({ | 138 | dialog.showDialog({ |
135 | dialogText: '您还未选择赠品,是否去选择赠品', | 139 | dialogText: '您还未选择赠品,是否去选择赠品', |
136 | hasFooter: { | 140 | hasFooter: { |
@@ -138,7 +142,8 @@ let cartObj = { | @@ -138,7 +142,8 @@ let cartObj = { | ||
138 | rightBtnText: '去选择' | 142 | rightBtnText: '去选择' |
139 | } | 143 | } |
140 | }, function() { | 144 | }, function() { |
141 | - self.toGiftPromotion(cartType); | 145 | + cookie.set('_realyGift', true); // 提示去选择后不再提示 |
146 | + self.toOrderEnsureGift(); | ||
142 | }, function() { | 147 | }, function() { |
143 | self.toOrderEnsure(cartType); | 148 | self.toOrderEnsure(cartType); |
144 | }); | 149 | }); |
@@ -147,24 +152,15 @@ let cartObj = { | @@ -147,24 +152,15 @@ let cartObj = { | ||
147 | self.toOrderEnsure(cartType); | 152 | self.toOrderEnsure(cartType); |
148 | }, | 153 | }, |
149 | toOrderEnsure(cartType) { | 154 | toOrderEnsure(cartType) { |
155 | + cookie.get('_realyGift') && cookie.remove('_realyGift'); | ||
150 | cookie.get('order-info') && cookie.remove('order-info'); | 156 | cookie.get('order-info') && cookie.remove('order-info'); |
151 | window.location.href = '/cart/index/new/orderEnsure?cartType=' + cartType; | 157 | window.location.href = '/cart/index/new/orderEnsure?cartType=' + cartType; |
152 | }, | 158 | }, |
153 | - toGiftPromotion(cartType) { | 159 | + toOrderEnsureGift() { |
154 | let self = this; | 160 | let self = this; |
155 | - let promotionEles = $('.promo-item[data-type="Gift"][data-status="10"]'); | ||
156 | 161 | ||
157 | - if (promotionEles.length) { | ||
158 | - let promotionEle = promotionEles.eq(0); | ||
159 | - | ||
160 | - self.toPromotionPage({ | ||
161 | - promotionType: $(promotionEle).data('type'), | ||
162 | - promotionId: $(promotionEle).data('id'), | ||
163 | - promotionTitle: encodeURIComponent($(promotionEle).data('title')), | ||
164 | - status: $(promotionEle).data('status') | ||
165 | - }); | ||
166 | - } else if ($('.all-gift-box>.freebie').length) { | ||
167 | - window.location.href = '/cart/index/new/gift?cartType=' + cartType; | 162 | + if (self.handle.cartData.matchGifts && self.handle.cartData.matchGifts.length) { |
163 | + self.toPromotionPage(self.handle.cartData.matchGifts, 'Gift'); | ||
168 | } | 164 | } |
169 | } | 165 | } |
170 | }; | 166 | }; |
@@ -11,9 +11,12 @@ var $ = require('yoho-jquery'), | @@ -11,9 +11,12 @@ var $ = require('yoho-jquery'), | ||
11 | var $recommendForYou = $('.recommend-for-you'); | 11 | var $recommendForYou = $('.recommend-for-you'); |
12 | 12 | ||
13 | $.get('/product/recommend-for-you/cart').then(function(html) { | 13 | $.get('/product/recommend-for-you/cart').then(function(html) { |
14 | - var PRDID =[]; | 14 | + var PRDID = []; |
15 | 15 | ||
16 | - $recommendForYou.html(html).show(); | 16 | + $recommendForYou.html(html); |
17 | + if ($recommendForYou.find('.good-info').length) { | ||
18 | + $recommendForYou.show(); | ||
19 | + } | ||
17 | lazyLoad($('img.lazy')); | 20 | lazyLoad($('img.lazy')); |
18 | 21 | ||
19 | //为您优选埋点 http://redmine.yoho.cn/issues/10116 | 22 | //为您优选埋点 http://redmine.yoho.cn/issues/10116 |
@@ -58,22 +58,24 @@ const formatPromotionOpt = (promo) => { | @@ -58,22 +58,24 @@ const formatPromotionOpt = (promo) => { | ||
58 | * @param int $count 计商品件数 | 58 | * @param int $count 计商品件数 |
59 | * @return array $arr 处理之后的加价购商品数据 | 59 | * @return array $arr 处理之后的加价购商品数据 |
60 | */ | 60 | */ |
61 | -const formatAdvanceGoods = (advanceGood, isGift) => { | ||
62 | - return { | ||
63 | - promotionId: advanceGood.promotion_id, | ||
64 | - promotionTitle: advanceGood.promotion_title, | ||
65 | - status: advanceGood.status, | ||
66 | - goods: _.get(advanceGood, 'goods_list').map(good => { | ||
67 | - return { | ||
68 | - id: good.product_skn, | ||
69 | - name: good.product_name, | ||
70 | - thumb: good.goods_images ? helpers.image(good.goods_images, 120, 160) : '', | ||
71 | - price: transPrice(good.last_price), | ||
72 | - marketPrice: isGift ? '0.00' : transPrice(good.market_price), | ||
73 | - count: good.storage_number | ||
74 | - }; | ||
75 | - }) | ||
76 | - }; | 61 | +const formatAdvanceGoods = (gifts, isGift) => { |
62 | + return _.map(gifts, gift => { | ||
63 | + return { | ||
64 | + promotionId: gift.promotion_id, | ||
65 | + promotionTitle: gift.promotion_title, | ||
66 | + isGift: isGift, | ||
67 | + goods: _.map(gift.goods_list, good => { | ||
68 | + return { | ||
69 | + id: good.product_skn, | ||
70 | + name: good.product_name, | ||
71 | + thumb: good.goods_images ? helpers.image(good.goods_images, 120, 160) : '', | ||
72 | + price: transPrice(good.last_price), | ||
73 | + marketPrice: isGift ? '0.00' : transPrice(good.market_price), | ||
74 | + count: good.storage_number | ||
75 | + }; | ||
76 | + }) | ||
77 | + }; | ||
78 | + }); | ||
77 | }; | 79 | }; |
78 | 80 | ||
79 | /** | 81 | /** |
@@ -153,15 +155,14 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => { | @@ -153,15 +155,14 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => { | ||
153 | result.link = helpers.urlFormat(`/product/show_${goodData.product_skn}.html`); | 155 | result.link = helpers.urlFormat(`/product/show_${goodData.product_skn}.html`); |
154 | return result; | 156 | return result; |
155 | }; | 157 | }; |
156 | -const procPriceGiftData = (data) => { | 158 | +const procPriceGiftData = (data, promotionType) => { |
157 | let result = {}; | 159 | let result = {}; |
160 | + let arrays = _.get(data, 'arrays', []); | ||
158 | 161 | ||
159 | - if (data.promotion_type === 'Gift') { | ||
160 | - // 赠品 | ||
161 | - result.freebie = formatAdvanceGoods(data, true); | ||
162 | - } else if (data.promotion_type === 'Needpaygift') { | ||
163 | - // 加价购 | ||
164 | - result.advanceBuy = formatAdvanceGoods(data); | 162 | + // 赠品和加价购 |
163 | + result.gifts = formatAdvanceGoods(arrays, promotionType === 'Gift'); | ||
164 | + if (result.gifts.length === 1) { | ||
165 | + result.promotionTitle = result.gifts[0].promotionTitle; | ||
165 | } | 166 | } |
166 | return result; | 167 | return result; |
167 | }; | 168 | }; |
@@ -235,27 +236,12 @@ const procGoodsDetail = (productData, num) => { | @@ -235,27 +236,12 @@ const procGoodsDetail = (productData, num) => { | ||
235 | return data; | 236 | return data; |
236 | }; | 237 | }; |
237 | 238 | ||
238 | -const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => { | 239 | +const procCartData = (data, isAdvanceCart) => { |
239 | if (isAdvanceCart === undefined) { | 240 | if (isAdvanceCart === undefined) { |
240 | isAdvanceCart = true; | 241 | isAdvanceCart = true; |
241 | } | 242 | } |
242 | let result = {}; | 243 | let result = {}; |
243 | 244 | ||
244 | - if (onlyGift) { | ||
245 | - // 全场赠品 | ||
246 | - result.freebie = data.g_gift_list.map(good => { | ||
247 | - return formatAdvanceGoods(good, true); | ||
248 | - }); | ||
249 | - return result; | ||
250 | - } | ||
251 | - if (onlyAdvanceBuy) { | ||
252 | - // 全场加价购 | ||
253 | - result.advanceBuy = data.g_price_gift_list.map(good => { | ||
254 | - return formatAdvanceGoods(good); | ||
255 | - }); | ||
256 | - return result; | ||
257 | - } | ||
258 | - | ||
259 | // 购买的可用商品列表 | 245 | // 购买的可用商品列表 |
260 | result.goods = _.get(data, 'goods_list', []).map(good => { | 246 | result.goods = _.get(data, 'goods_list', []).map(good => { |
261 | let gr = formatCartGoods(good, isAdvanceCart); | 247 | let gr = formatCartGoods(good, isAdvanceCart); |
@@ -309,14 +295,15 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => { | @@ -309,14 +295,15 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => { | ||
309 | 295 | ||
310 | // 赠品 | 296 | // 赠品 |
311 | result.freebie = data.g_gift_list.filter(freebie => freebie.status !== 30 && freebie.status !== 0); | 297 | result.freebie = data.g_gift_list.filter(freebie => freebie.status !== 30 && freebie.status !== 0); |
312 | - result.giftCount = result.freebie.length; | 298 | + result.selectFreebie = result.freebie.filter(freebie => freebie.status === 10); |
313 | result.giftHasStorage = _.some(result.freebie, freebie => freebie.status === 10); | 299 | result.giftHasStorage = _.some(result.freebie, freebie => freebie.status === 10); |
314 | 300 | ||
315 | // 加价购 | 301 | // 加价购 |
316 | result.advanceBuy = data.g_price_gift_list.filter(advanceBuy => advanceBuy.status !== 30 && advanceBuy.status !== 0); | 302 | result.advanceBuy = data.g_price_gift_list.filter(advanceBuy => advanceBuy.status !== 30 && advanceBuy.status !== 0); |
317 | - result.advanceBuyCount = result.advanceBuy.length; | 303 | + result.selectAdvanceBuy = result.advanceBuy.filter(advanceBuy => advanceBuy.status === 10); |
318 | result.advanceHasStorage = _.some(result.advanceBuy, advanceBuy => advanceBuy.status === 10); | 304 | result.advanceHasStorage = _.some(result.advanceBuy, advanceBuy => advanceBuy.status === 10); |
319 | } | 305 | } |
306 | + result.matchGifts = _.get(data, 'match_gift_ids', []); | ||
320 | 307 | ||
321 | // 已参加的活动 | 308 | // 已参加的活动 |
322 | if (data.promotion_info && data.promotion_info.length > 0) { | 309 | if (data.promotion_info && data.promotion_info.length > 0) { |
@@ -359,16 +346,12 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => { | @@ -359,16 +346,12 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => { | ||
359 | 346 | ||
360 | return result; | 347 | return result; |
361 | }; | 348 | }; |
362 | -const processData = (data, cartType, onlyGift, onlyAdvanceBuy) => { | 349 | +const processData = (data, cartType) => { |
363 | if (cartType === undefined) { | 350 | if (cartType === undefined) { |
364 | cartType = 'all'; | 351 | cartType = 'all'; |
365 | } | 352 | } |
366 | let cart = data.data; | 353 | let cart = data.data; |
367 | let result = {}; | 354 | let result = {}; |
368 | - | ||
369 | - if (onlyGift || onlyAdvanceBuy) { // 加价购或者赠品数据 | ||
370 | - return procCartData(cart.ordinary_cart_data, onlyGift, onlyAdvanceBuy); | ||
371 | - } | ||
372 | let ordinaryCount = _.get(cart, 'ordinary_cart_data.shopping_cart_data.goods_count', 0); | 355 | let ordinaryCount = _.get(cart, 'ordinary_cart_data.shopping_cart_data.goods_count', 0); |
373 | let advanceCount = _.get(cart, 'advance_cart_data.shopping_cart_data.goods_count', 0); | 356 | let advanceCount = _.get(cart, 'advance_cart_data.shopping_cart_data.goods_count', 0); |
374 | let ordinarySoldOut = _.get(cart, 'ordinary_cart_data.sold_out_goods_list', []); | 357 | let ordinarySoldOut = _.get(cart, 'ordinary_cart_data.sold_out_goods_list', []); |
@@ -383,12 +366,12 @@ const processData = (data, cartType, onlyGift, onlyAdvanceBuy) => { | @@ -383,12 +366,12 @@ const processData = (data, cartType, onlyGift, onlyAdvanceBuy) => { | ||
383 | /* 普通购物车 */ | 366 | /* 普通购物车 */ |
384 | result.commonGoodsCount = ordinaryCount; | 367 | result.commonGoodsCount = ordinaryCount; |
385 | result.ordinarySoldOut = ordinarySoldOut.length; | 368 | result.ordinarySoldOut = ordinarySoldOut.length; |
386 | - result.commonCart = procCartData(cart.ordinary_cart_data, onlyGift, onlyAdvanceBuy, false); | 369 | + result.commonCart = procCartData(cart.ordinary_cart_data, false); |
387 | 370 | ||
388 | /* 预售购物车 */ | 371 | /* 预售购物车 */ |
389 | result.presellGoodsCount = advanceCount; | 372 | result.presellGoodsCount = advanceCount; |
390 | result.advanceSoldOut = advanceSoldOut.length; | 373 | result.advanceSoldOut = advanceSoldOut.length; |
391 | - result.preSellCart = procCartData(cart.advance_cart_data, onlyGift, onlyAdvanceBuy); | 374 | + result.preSellCart = procCartData(cart.advance_cart_data); |
392 | return result; | 375 | return result; |
393 | }; | 376 | }; |
394 | 377 |
-
Please register or login to post a comment