Merge branch 'feature/cart' of http://git.dev.yoho.cn/web/yohobuy into feature/cart
Showing
11 changed files
with
296 additions
and
59 deletions
@@ -1261,7 +1261,7 @@ | @@ -1261,7 +1261,7 @@ | ||
1261 | chosed: true, | 1261 | chosed: true, |
1262 | name: '黄色', | 1262 | name: '黄色', |
1263 | colorNum:10, | 1263 | colorNum:10, |
1264 | - shortUrl:'', | 1264 | + sizeNumStr:'10/20/30' //对应的商品尺码数目,用斜杠分割 |
1265 | 1265 | ||
1266 | }, | 1266 | }, |
1267 | ... | 1267 | ... |
@@ -1271,7 +1271,8 @@ | @@ -1271,7 +1271,8 @@ | ||
1271 | id: 2, | 1271 | id: 2, |
1272 | chosed: true, | 1272 | chosed: true, |
1273 | name: 'X', | 1273 | name: 'X', |
1274 | - sizeNum: 2 | 1274 | + sizeNum: 2, |
1275 | + colorNumStr:'10/20/30' //对应的商品颜色数目用斜杠分割 | ||
1275 | }, | 1276 | }, |
1276 | ... | 1277 | ... |
1277 | ], | 1278 | ], |
framework @ e9d066dd
@@ -48,6 +48,32 @@ class CartData | @@ -48,6 +48,32 @@ class CartData | ||
48 | } | 48 | } |
49 | 49 | ||
50 | /** | 50 | /** |
51 | + * 购物车商品选择与取消接口 | ||
52 | + * | ||
53 | + * @param int $uid 用户ID | ||
54 | + * @param string $sku 商品sku列表 | ||
55 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
56 | + * @return array 购物车接口返回的数据 | ||
57 | + */ | ||
58 | + public static function selectGoods($uid, $sku, $shoppingKey) | ||
59 | + { | ||
60 | + $param = Yohobuy::param(); | ||
61 | + $param['method'] = 'app.Shopping.selected'; | ||
62 | + $param['product_sku_list'] = $sku; | ||
63 | + | ||
64 | + if (!empty($uid)) { | ||
65 | + $param['uid'] = $uid; | ||
66 | + } | ||
67 | + if (!empty($shoppingKey)) { | ||
68 | + $param['shopping_key'] = $shoppingKey; | ||
69 | + } | ||
70 | + | ||
71 | + $param['client_secret'] = Sign::getSign($param); | ||
72 | + | ||
73 | + return Yohobuy::get(Yohobuy::API_URL, $param); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
51 | * 购物车数据 | 77 | * 购物车数据 |
52 | * | 78 | * |
53 | * @param int $uid 用户ID | 79 | * @param int $uid 用户ID |
@@ -556,6 +556,86 @@ class Helpers | @@ -556,6 +556,86 @@ class Helpers | ||
556 | } | 556 | } |
557 | 557 | ||
558 | /** | 558 | /** |
559 | + * 格式化购物车商品 | ||
560 | + * | ||
561 | + * @param array $cartGoods 购物车商品列表 | ||
562 | + * @param bool $haveLink 控制是否需要商品链接 | ||
563 | + */ | ||
564 | + public static function formatCartGoods($cartGoods, $haveLink = false) | ||
565 | + { | ||
566 | + $arr = array(); | ||
567 | + | ||
568 | + $oneGoods = array(); | ||
569 | + foreach ($cartGoods as $key => $value) { | ||
570 | + $oneGoods['id'] = $value['product_sku']; | ||
571 | + $oneGoods['skn'] = $value['product_skn']; | ||
572 | + $oneGoods['name'] = $value['product_name']; | ||
573 | + $oneGoods['thumb'] = !empty($value['goods_images']) ? Images::getImageUrl($value['goods_images'], 120, 120) : ''; | ||
574 | + $oneGoods['color'] = $value['color_name']; | ||
575 | + $oneGoods['size'] = $value['size_name']; | ||
576 | + $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
577 | + $oneGoods['price'] = $value['real_price']; | ||
578 | + $oneGoods['count'] = $value['buy_number']; | ||
579 | + $oneGoods['lowStocks'] = ($value['buy_number'] < $value['storage_number']); | ||
580 | + //gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品; | ||
581 | + if (!isset($value['goods_type'])) { | ||
582 | + $oneGoods['soldOut'] = true; | ||
583 | + } elseif ($value['goods_type'] == 'gift') { | ||
584 | + $oneGoods['gift'] = true; | ||
585 | + } elseif ($value['goods_type'] == 'price_gift') { | ||
586 | + $oneGoods['advanceBuy'] = true; | ||
587 | + } | ||
588 | + // 上市期 | ||
589 | + if (!empty($value['expect_arrival_time'])) { | ||
590 | + $oneGoods['appearDate'] = $value['expect_arrival_time']; | ||
591 | + } | ||
592 | + // 商品链接 | ||
593 | + if ($haveLink && isset($value['product_id'])) { | ||
594 | + $oneGoods['link'] = self::url('/product/pro_' . $value['product_id'] . '_' . $value['goods_id'] . '/' . $value['cn_alphabet'] . '.html'); | ||
595 | + } | ||
596 | + | ||
597 | + $arr[$key] = $oneGoods; | ||
598 | + } | ||
599 | + | ||
600 | + return $arr; | ||
601 | + } | ||
602 | + | ||
603 | + /** | ||
604 | + * 格式化加价购商品 | ||
605 | + * | ||
606 | + * @param array $advanceGoods 加价购商品列表 | ||
607 | + * @param bool $haveLink 控制是否需要商品链接 | ||
608 | + */ | ||
609 | + public static function formatAdvanceGoods($advanceGoods) | ||
610 | + { | ||
611 | + $arr = array(); | ||
612 | + | ||
613 | + | ||
614 | + $gift = array(); | ||
615 | + $oneGoods = array(); | ||
616 | + foreach ($advanceGoods as $value) { | ||
617 | + $gift = array(); | ||
618 | + $gift['promotionTitle'] = $value['promotion_title']; | ||
619 | + | ||
620 | + foreach ($value['goods_list'] as $single) { | ||
621 | + $oneGoods['id'] = $single['product_skn']; | ||
622 | + $oneGoods['name'] = $single['product_name']; | ||
623 | + $oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 120) : ''; | ||
624 | + $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
625 | + $oneGoods['price'] = $single['last_price']; | ||
626 | + $oneGoods['marketPrice'] = $single['market_price']; | ||
627 | + $oneGoods['count'] = $single['storage_number']; | ||
628 | + | ||
629 | + $gift['goods'][] = $oneGoods; | ||
630 | + } | ||
631 | + | ||
632 | + $arr[] = $gift; | ||
633 | + } | ||
634 | + | ||
635 | + return $arr; | ||
636 | + } | ||
637 | + | ||
638 | + /** | ||
559 | * 订单状态,按订单支付类型和订单状态 | 639 | * 订单状态,按订单支付类型和订单状态 |
560 | * @var array | 640 | * @var array |
561 | */ | 641 | */ |
@@ -58,21 +58,51 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | @@ -58,21 +58,51 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | ||
58 | }).on('touchstart', '#chose-btn-sure', function() { | 58 | }).on('touchstart', '#chose-btn-sure', function() { |
59 | 59 | ||
60 | //确定 | 60 | //确定 |
61 | -}).on('touchstart', '.block', function() { | 61 | +}).on('touchstart', '.block', function(e) { |
62 | 62 | ||
63 | //尺寸颜色点选 | 63 | //尺寸颜色点选 |
64 | - var $this = $(this); | ||
65 | - | ||
66 | - if ($this.hasClass('.chosed') || $this.hasClass('disable')) { | 64 | + var $this = $(this), |
65 | + $that = $(e.target).closest('.chose-items'), | ||
66 | + numArray, | ||
67 | + index; | ||
68 | + | ||
69 | + if ($this.hasClass('chosed')) { | ||
70 | + $this.parent().find('.block').removeClass('chosed'); | ||
71 | + $that.find('.num .left-num').html(''); | ||
72 | + } else if ($this.hasClass('disable')) { | ||
73 | + $this.css('background-color', '#000'); | ||
67 | return; | 74 | return; |
75 | + } else if (!$this.hasClass('chosed')) { | ||
76 | + $this.siblings('.chosed').removeClass('chosed'); | ||
77 | + $this.addClass('chosed'); | ||
78 | + index = $this.index(); | ||
79 | + | ||
80 | + | ||
81 | + //根据颜色切换图片 | ||
82 | + if ($this.closest('.block-list').hasClass('color-list')) { | ||
83 | + $('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide'); | ||
84 | + } | ||
85 | + | ||
86 | + //剩余的商品数 | ||
87 | + if ($that.find('.color-list ul>li').hasClass('chosed') && $that.find('.size-list ul>li').hasClass('chosed')) { | ||
88 | + numArray = $this.closest('.block-list').siblings(':first').find('.chosed').data('numstr').split('/'); | ||
89 | + $that.find('.num .left-num').html('剩余' + numArray[index] + '件'); | ||
90 | + } else { | ||
91 | + $that.find('.num .left-num').html(''); | ||
92 | + } | ||
93 | + | ||
94 | + //点击切换 | ||
68 | } | 95 | } |
69 | 96 | ||
70 | - $this.siblings('.chosed').removeClass('chosed'); | ||
71 | - $this.addClass('chosed'); | ||
72 | }).on('touchstart', '.btn-minus', function() { | 97 | }).on('touchstart', '.btn-minus', function() { |
73 | var num = +$num.val(); | 98 | var num = +$num.val(); |
74 | 99 | ||
75 | - if (num === 1) { | 100 | + //若颜色和尺码没有被同时选中,则不能点击 |
101 | + if ($('.block-list>ul>li.chosed').length < 2) { | ||
102 | + return; | ||
103 | + } | ||
104 | + | ||
105 | + if (num === 0) { | ||
76 | return; | 106 | return; |
77 | } | 107 | } |
78 | 108 | ||
@@ -80,6 +110,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | @@ -80,6 +110,11 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { | ||
80 | }).on('touchstart', '.btn-plus', function() { | 110 | }).on('touchstart', '.btn-plus', function() { |
81 | var num = +$num.val(); | 111 | var num = +$num.val(); |
82 | 112 | ||
113 | + //若颜色和尺码没有被同时选中,则不能点击 | ||
114 | + if ($('.block-list>ul>li.chosed').length < 2) { | ||
115 | + return; | ||
116 | + } | ||
117 | + | ||
83 | //TODO:库存数验证 | 118 | //TODO:库存数验证 |
84 | $num.val(num + 1); | 119 | $num.val(num + 1); |
85 | }); | 120 | }); |
@@ -79,6 +79,11 @@ | @@ -79,6 +79,11 @@ | ||
79 | left: 0; | 79 | left: 0; |
80 | top: 20rem / $pxConvertRem; | 80 | top: 20rem / $pxConvertRem; |
81 | } | 81 | } |
82 | + >span.left-num{ | ||
83 | + position: absolute; | ||
84 | + left: pxToRem(380px); | ||
85 | + top: 20rem / $pxConvertRem; | ||
86 | + } | ||
82 | } | 87 | } |
83 | 88 | ||
84 | .block { | 89 | .block { |
@@ -99,6 +104,11 @@ | @@ -99,6 +104,11 @@ | ||
99 | background-position: bottom right; | 104 | background-position: bottom right; |
100 | color: #e10; | 105 | color: #e10; |
101 | } | 106 | } |
107 | + | ||
108 | + &.disable { | ||
109 | + color: #e0e0e0; | ||
110 | + border-color: #e0e0e0; | ||
111 | + } | ||
102 | } | 112 | } |
103 | 113 | ||
104 | .num { | 114 | .num { |
1 | .shopping-cart-good { | 1 | .shopping-cart-good { |
2 | + $cartRed: #d0253b; | ||
2 | position: relative; | 3 | position: relative; |
3 | padding-left: 16rem / $pxConvertRem; | 4 | padding-left: 16rem / $pxConvertRem; |
4 | 5 | ||
@@ -16,26 +17,30 @@ | @@ -16,26 +17,30 @@ | ||
16 | 17 | ||
17 | .info { | 18 | .info { |
18 | float: left; | 19 | float: left; |
19 | - margin-left: 50rem / $pxConvertRem; | 20 | + margin-left: 30rem / $pxConvertRem; |
20 | padding: 16rem / $pxConvertRem 0; | 21 | padding: 16rem / $pxConvertRem 0; |
21 | - border-bottom: 1px solid #e0e0e0; | 22 | + padding-right: 20rem / $pxConvertRem; |
22 | } | 23 | } |
23 | 24 | ||
24 | .thumb { | 25 | .thumb { |
25 | float: left; | 26 | float: left; |
26 | - width: 120rem / $pxConvertRem; | ||
27 | - height: 160rem / $pxConvertRem; | 27 | + width: 180rem / $pxConvertRem; |
28 | + height: 200rem / $pxConvertRem; | ||
29 | + background-size: 100%; | ||
30 | + background-repeat: no-repeat; | ||
28 | } | 31 | } |
29 | - | 32 | + |
30 | .deps { | 33 | .deps { |
31 | - margin-left: 135rem / $pxConvertRem; | ||
32 | - padding-right: 20rem / $pxConvertRem; | 34 | + margin-left: 173rem / $pxConvertRem; |
35 | + padding-bottom: 60rem / $pxConvertRem; | ||
36 | + border-bottom: 1px solid #e0e0e0; | ||
33 | } | 37 | } |
34 | 38 | ||
35 | .name { | 39 | .name { |
36 | font-size: 28rem / $pxConvertRem; | 40 | font-size: 28rem / $pxConvertRem; |
41 | + color: #5a5a5a; | ||
37 | } | 42 | } |
38 | - | 43 | + |
39 | .row:nth-child(2) { | 44 | .row:nth-child(2) { |
40 | font-size: 22rem / $pxConvertRem; | 45 | font-size: 22rem / $pxConvertRem; |
41 | height: 45rem / $pxConvertRem; | 46 | height: 45rem / $pxConvertRem; |
@@ -55,12 +60,14 @@ | @@ -55,12 +60,14 @@ | ||
55 | } | 60 | } |
56 | 61 | ||
57 | .appear-date { | 62 | .appear-date { |
58 | - color: #e01; | 63 | + color: $cartRed; |
64 | + display: block; | ||
65 | + margin-top: 4rem / $pxConvertRem; | ||
59 | } | 66 | } |
60 | 67 | ||
61 | .price { | 68 | .price { |
62 | font-size: 24rem / $pxConvertRem; | 69 | font-size: 24rem / $pxConvertRem; |
63 | - color: #000; | 70 | + color: $cartRed; |
64 | } | 71 | } |
65 | 72 | ||
66 | .count { | 73 | .count { |
@@ -78,7 +85,11 @@ | @@ -78,7 +85,11 @@ | ||
78 | border: none; | 85 | border: none; |
79 | color: #fff; | 86 | color: #fff; |
80 | text-align: center; | 87 | text-align: center; |
81 | - margin-left: 16rem / $pxConvertRem; | 88 | + float: right; |
89 | + margin-top: 20rem / $pxConvertRem; | ||
90 | + margin-right: 16rem / $pxConvertRem; | ||
91 | + border-radius: 20rem / $pxConvertRem; | ||
92 | + padding: 4rem / $pxConvertRem; | ||
82 | } | 93 | } |
83 | 94 | ||
84 | .sold-out { | 95 | .sold-out { |
@@ -86,7 +97,7 @@ | @@ -86,7 +97,7 @@ | ||
86 | } | 97 | } |
87 | 98 | ||
88 | .low-stocks { | 99 | .low-stocks { |
89 | - background: #e01; | 100 | + background: #7f7f7f; |
90 | } | 101 | } |
91 | 102 | ||
92 | .icon-del, | 103 | .icon-del, |
@@ -140,4 +151,10 @@ | @@ -140,4 +151,10 @@ | ||
140 | } | 151 | } |
141 | } | 152 | } |
142 | } | 153 | } |
143 | -} | ||
154 | +} | ||
155 | + | ||
156 | +.shopping-cart-good:last-child { | ||
157 | + .deps { | ||
158 | + border: none; | ||
159 | + } | ||
160 | +} |
@@ -3,7 +3,13 @@ | @@ -3,7 +3,13 @@ | ||
3 | <div class="main"> | 3 | <div class="main"> |
4 | <div class="infos"> | 4 | <div class="infos"> |
5 | <div class="basic-info"> | 5 | <div class="basic-info"> |
6 | - <img class="thumb" src={{thumb}}> | 6 | + {{#thumbs}} |
7 | + {{#if @first}} | ||
8 | + <img class="thumb" src={{img}}> | ||
9 | + {{else}} | ||
10 | + <img class="thumb hide" src={{img}}> | ||
11 | + {{/if}} | ||
12 | + {{/thumbs}} | ||
7 | <div class="text-info"> | 13 | <div class="text-info"> |
8 | <p class="name">{{name}}</p> | 14 | <p class="name">{{name}}</p> |
9 | <p class="price"> | 15 | <p class="price"> |
@@ -15,21 +21,21 @@ | @@ -15,21 +21,21 @@ | ||
15 | </div> | 21 | </div> |
16 | </div> | 22 | </div> |
17 | <div class="chose-items"> | 23 | <div class="chose-items"> |
18 | - <div class="color-list"> | 24 | + <div class="color-list block-list"> |
19 | <span>颜色</span> | 25 | <span>颜色</span> |
20 | <ul class="clearfix" data-type="color"> | 26 | <ul class="clearfix" data-type="color"> |
21 | {{# colors}} | 27 | {{# colors}} |
22 | - <li class="block {{#if chosed}}chosed{{/if}}" data-id={{id}}> | 28 | + <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{sizeNumStr}}"> |
23 | {{name}} | 29 | {{name}} |
24 | </li> | 30 | </li> |
25 | {{/ colors}} | 31 | {{/ colors}} |
26 | </ul> | 32 | </ul> |
27 | </div> | 33 | </div> |
28 | - <div class="size-list"> | 34 | + <div class="size-list block-list"> |
29 | <span>尺码</span> | 35 | <span>尺码</span> |
30 | - <ul class="clearfix {{#if @first}}{{^}}hide{{/if}}" data-type="size" > | 36 | + <ul class="clearfix" data-type="size" > |
31 | {{# sizes}} | 37 | {{# sizes}} |
32 | - <li class="block {{#if chosed}}chosed{{/if}}" data-id={{id}}> | 38 | + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{colorNumStr}}"> |
33 | {{name}} | 39 | {{name}} |
34 | </li> | 40 | </li> |
35 | {{/ sizes}} | 41 | {{/ sizes}} |
@@ -44,8 +50,9 @@ | @@ -44,8 +50,9 @@ | ||
44 | <input id="good-num" class="good-num" type="text" value={{num}}> | 50 | <input id="good-num" class="good-num" type="text" value={{num}}> |
45 | <a class="btn btn-plus" href="javascript:void(0);"> | 51 | <a class="btn btn-plus" href="javascript:void(0);"> |
46 | <span class="iconfont"></span> | 52 | <span class="iconfont"></span> |
47 | - </a> | 53 | + </a> |
48 | </div> | 54 | </div> |
55 | + <span class="left-num"></span> | ||
49 | </div> | 56 | </div> |
50 | </div> | 57 | </div> |
51 | </div> | 58 | </div> |
@@ -17,11 +17,6 @@ | @@ -17,11 +17,6 @@ | ||
17 | </span> | 17 | </span> |
18 | {{/if}} | 18 | {{/if}} |
19 | 19 | ||
20 | - {{#if appearDate}} | ||
21 | - <span class="appear-date"> | ||
22 | - 上市期:{{appearDate}} | ||
23 | - </span> | ||
24 | - {{/if}} | ||
25 | </p> | 20 | </p> |
26 | <p class="row"> | 21 | <p class="row"> |
27 | <span class="price"> | 22 | <span class="price"> |
@@ -36,14 +31,23 @@ | @@ -36,14 +31,23 @@ | ||
36 | </span> | 31 | </span> |
37 | {{/if}} | 32 | {{/if}} |
38 | 33 | ||
34 | + | ||
35 | + <span class="iconfont icon-edit"></span> | ||
36 | + <span class="iconfont icon-del"></span> | ||
37 | + </p> | ||
38 | + <p class="row"> | ||
39 | {{#if lowStocks}} | 39 | {{#if lowStocks}} |
40 | <span class="low-stocks"> | 40 | <span class="low-stocks"> |
41 | 库存不足 | 41 | 库存不足 |
42 | </span> | 42 | </span> |
43 | {{/if}} | 43 | {{/if}} |
44 | - | ||
45 | - <span class="iconfont icon-edit"></span> | ||
46 | - <span class="iconfont icon-del"></span> | 44 | + </p> |
45 | + <p class="row"> | ||
46 | + {{#if appearDate}} | ||
47 | + <span class="appear-date"> | ||
48 | + 上市期:{{appearDate}} | ||
49 | + </span> | ||
50 | + {{/if}} | ||
47 | </p> | 51 | </p> |
48 | </div> | 52 | </div> |
49 | </div> | 53 | </div> |
@@ -58,4 +62,4 @@ | @@ -58,4 +62,4 @@ | ||
58 | 删除 | 62 | 删除 |
59 | </div> | 63 | </div> |
60 | </div> | 64 | </div> |
61 | -</div> | ||
65 | +</div> |
@@ -13,7 +13,6 @@ class ShoppingCartController extends AbstractAction | @@ -13,7 +13,6 @@ class ShoppingCartController extends AbstractAction | ||
13 | /* | 13 | /* |
14 | * 购物车首页 | 14 | * 购物车首页 |
15 | */ | 15 | */ |
16 | - | ||
17 | public function indexAction() | 16 | public function indexAction() |
18 | { | 17 | { |
19 | $this->setTitle('购物车'); | 18 | $this->setTitle('购物车'); |
@@ -30,6 +29,47 @@ class ShoppingCartController extends AbstractAction | @@ -30,6 +29,47 @@ class ShoppingCartController extends AbstractAction | ||
30 | // 渲染模板 | 29 | // 渲染模板 |
31 | $this->_view->display('index', $data); | 30 | $this->_view->display('index', $data); |
32 | } | 31 | } |
32 | + /* | ||
33 | + * 异步获取购物车数据 | ||
34 | + */ | ||
35 | + public function getCartDataAction() | ||
36 | + { | ||
37 | + $result = array(); | ||
38 | + | ||
39 | + if ($this->isAjax()) { | ||
40 | + $shoppingKey = Helpers::getShoppingKeyByCookie(); | ||
41 | + $uid = $this->getUid(true); | ||
42 | + | ||
43 | + $result = CartModel::getCartData($uid, $shoppingKey); | ||
44 | + } | ||
45 | + | ||
46 | + if (empty($result)) { | ||
47 | + echo ' '; | ||
48 | + } else { | ||
49 | + $this->echoJson($result); | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * 购物车商品选择与取消 | ||
55 | + */ | ||
56 | + public function selectAction() | ||
57 | + { | ||
58 | + $result = array(); | ||
59 | + | ||
60 | + if ($this->isAjax()) { | ||
61 | + $productId = $this->post('id', 0); | ||
62 | + $uid = $this->getUid(true); | ||
63 | + $shoppingKey = $this->getSession('shoppingKey'); | ||
64 | + $result = CartModel::selectGoods($uid, $productId, $shoppingKey); | ||
65 | + } | ||
66 | + | ||
67 | + if (empty($result)) { | ||
68 | + echo ' '; | ||
69 | + } else { | ||
70 | + $this->echoJson($result); | ||
71 | + } | ||
72 | + } | ||
33 | 73 | ||
34 | /** | 74 | /** |
35 | * 移出购物车 | 75 | * 移出购物车 |
@@ -63,13 +63,13 @@ class CartModel | @@ -63,13 +63,13 @@ class CartModel | ||
63 | 63 | ||
64 | /* 普通购物车 */ | 64 | /* 普通购物车 */ |
65 | if(isset($cart['ordinary_cart_data'])) { | 65 | if(isset($cart['ordinary_cart_data'])) { |
66 | - $result['commonGoodsCount'] = count($cart['ordinary_cart_data']['goods_list']); | 66 | + $result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count']; |
67 | $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); | 67 | $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']); |
68 | } | 68 | } |
69 | 69 | ||
70 | /* 预售购物车 */ | 70 | /* 预售购物车 */ |
71 | if(isset($cart['advance_cart_data'])) { | 71 | if(isset($cart['advance_cart_data'])) { |
72 | - $result['presellGoodsCount'] = count($cart['advance_cart_data']['goods_list']); | 72 | + $result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count']; |
73 | $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); | 73 | $result['preSellCart'] = self::procCartData($cart['advance_cart_data']); |
74 | } | 74 | } |
75 | 75 | ||
@@ -79,6 +79,30 @@ class CartModel | @@ -79,6 +79,30 @@ class CartModel | ||
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | + * 购物车商品选择与取消接口返回的数据处理 | ||
83 | + * | ||
84 | + * @param int $uid 用户ID | ||
85 | + * @param string $sku 商品sku列表 | ||
86 | + * @param string $shoppingKey 未登录用户唯一识别码 | ||
87 | + * @return array 处理之后的数据的数据 | ||
88 | + */ | ||
89 | + public static function selectGoods($uid, $sku, $shoppingKey) | ||
90 | + { | ||
91 | + $result = array('code' => 400, 'message' => '出错啦~'); | ||
92 | + | ||
93 | + // 处理sku | ||
94 | + $sku_list = json_encode(array($sku => 1)); | ||
95 | + | ||
96 | + $select = CartData::selectGoods($uid, $sku_list, $shoppingKey); | ||
97 | + if ($select && isset($select['code'])) { | ||
98 | + $result['code'] = $select['code']; | ||
99 | + $result['message'] = $select['message']; | ||
100 | + } | ||
101 | + | ||
102 | + return $result; | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
82 | * 移出购物车 | 106 | * 移出购物车 |
83 | * | 107 | * |
84 | * @param int $uid 用户ID | 108 | * @param int $uid 用户ID |
@@ -567,26 +591,19 @@ class CartModel | @@ -567,26 +591,19 @@ class CartModel | ||
567 | $result = array(); | 591 | $result = array(); |
568 | 592 | ||
569 | $oneGoods = array(); | 593 | $oneGoods = array(); |
570 | - // 购买的商品列表 | ||
571 | - foreach ($data['goods_list'] as $value) { | ||
572 | - $oneGoods['id'] = $value['product_sku']; | ||
573 | - $oneGoods['skn'] = $value['product_skn']; | ||
574 | - $oneGoods['name'] = $value['product_name']; | ||
575 | - $oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120); | ||
576 | - $oneGoods['color'] = $value['color_name']; | ||
577 | - $oneGoods['size'] = $value['size_name']; | ||
578 | - $oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据 | ||
579 | - $oneGoods['price'] = $value['real_price']; | ||
580 | - $oneGoods['count'] = $value['buy_number']; | ||
581 | - $oneGoods['lowStocks'] = true; | ||
582 | - | ||
583 | - $result['goods'][] = $oneGoods; | ||
584 | - } | 594 | + // 购买的可用商品列表 |
595 | + $validGoods = Helpers::formatCartGoods($data['goods_list']); | ||
596 | + !empty($validGoods) && $result['goods'] = $validGoods; | ||
597 | + | ||
598 | + // 失效商品列表 | ||
599 | + $notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']); | ||
600 | + !empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods; | ||
601 | + | ||
585 | // 赠品 | 602 | // 赠品 |
586 | - count($data['gift_list']) && $result['freebieOrAdvanceBuy'] = true; | 603 | + (count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true; |
587 | $result['freebie'] = $data['gift_list']; | 604 | $result['freebie'] = $data['gift_list']; |
588 | // 加价购 | 605 | // 加价购 |
589 | - $result['advanceBuy'] = $data['price_gift']; | 606 | + $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift']); |
590 | // 结算数据 | 607 | // 结算数据 |
591 | $result['price'] = $data['shopping_cart_data']['order_amount']; | 608 | $result['price'] = $data['shopping_cart_data']['order_amount']; |
592 | $result['activityPrice'] = $data['shopping_cart_data']['discount_amount']; | 609 | $result['activityPrice'] = $data['shopping_cart_data']['discount_amount']; |
-
Please register or login to post a comment