Authored by Lynnic

Merge branch 'feature/cart' of git.dev.yoho.cn:web/yohobuy into feature/cart

framework @ e9d066dd
1 -Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2 1 +Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
@@ -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 */
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 +}
@@ -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">&#xe61e;</span>
  36 + <span class="iconfont icon-del">&#xe621;</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">&#xe61e;</span>  
46 - <span class="iconfont icon-del">&#xe621;</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,31 +591,25 @@ class CartModel @@ -567,31 +591,25 @@ 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'];
593 $result['count'] = $data['shopping_cart_data']['goods_count']; 610 $result['count'] = $data['shopping_cart_data']['goods_count'];
594 $result['sumPrice'] = $data['shopping_cart_data']['order_amount']; 611 $result['sumPrice'] = $data['shopping_cart_data']['order_amount'];
  612 + print_r($result);
595 613
596 return $result; 614 return $result;
597 } 615 }