|
@@ -43,9 +43,11 @@ class CartModel |
|
@@ -43,9 +43,11 @@ class CartModel |
43
|
/**
|
43
|
/**
|
44
|
* @param integer $uid 用户ID
|
44
|
* @param integer $uid 用户ID
|
45
|
* @param string $shoppingKey 未登录用户唯一识别码
|
45
|
* @param string $shoppingKey 未登录用户唯一识别码
|
|
|
46
|
+ * @param bool $onlyGift 只获取赠品的商品数据
|
|
|
47
|
+ * @param bool $onlyAdvanceBuy 只获取加价购的商品数据
|
46
|
* @return array|mixed 处理之后的购物车数据
|
48
|
* @return array|mixed 处理之后的购物车数据
|
47
|
*/
|
49
|
*/
|
48
|
- public static function getCartData($uid, $shoppingKey)
|
50
|
+ public static function getCartData($uid, $shoppingKey, $onlyGift = false, $onlyAdvanceBuy = false)
|
49
|
{
|
51
|
{
|
50
|
$result = array('cartNav' => true);
|
52
|
$result = array('cartNav' => true);
|
51
|
|
53
|
|
|
@@ -64,13 +66,13 @@ class CartModel |
|
@@ -64,13 +66,13 @@ class CartModel |
64
|
/* 普通购物车 */
|
66
|
/* 普通购物车 */
|
65
|
if(isset($cart['ordinary_cart_data'])) {
|
67
|
if(isset($cart['ordinary_cart_data'])) {
|
66
|
$result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count'];
|
68
|
$result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count'];
|
67
|
- $result['commonCart'] = self::procCartData($cart['ordinary_cart_data']);
|
69
|
+ $result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
68
|
}
|
70
|
}
|
69
|
|
71
|
|
70
|
/* 预售购物车 */
|
72
|
/* 预售购物车 */
|
71
|
if(isset($cart['advance_cart_data'])) {
|
73
|
if(isset($cart['advance_cart_data'])) {
|
72
|
$result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count'];
|
74
|
$result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count'];
|
73
|
- $result['preSellCart'] = self::procCartData($cart['advance_cart_data']);
|
75
|
+ $result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
74
|
}
|
76
|
}
|
75
|
|
77
|
|
76
|
}
|
78
|
}
|
|
@@ -601,12 +603,27 @@ class CartModel |
|
@@ -601,12 +603,27 @@ class CartModel |
601
|
* 处理不同类型的购物车数据
|
603
|
* 处理不同类型的购物车数据
|
602
|
*
|
604
|
*
|
603
|
* @param array $data 不同类型购物车数据
|
605
|
* @param array $data 不同类型购物车数据
|
|
|
606
|
+ * @param bool $onlyGift 只获取赠品的商品数据
|
|
|
607
|
+ * @param bool $onlyAdvanceBuy 只获取加价购的商品数据
|
604
|
* @return array $result 处理之后的不同类型购物车数据
|
608
|
* @return array $result 处理之后的不同类型购物车数据
|
605
|
*/
|
609
|
*/
|
606
|
- private static function procCartData($data)
|
610
|
+ private static function procCartData($data, $onlyGift = false, $onlyAdvanceBuy = false)
|
607
|
{
|
611
|
{
|
608
|
$result = array();
|
612
|
$result = array();
|
609
|
|
613
|
|
|
|
614
|
+ if (!$onlyAdvanceBuy) {
|
|
|
615
|
+ // 赠品
|
|
|
616
|
+ $result['giftCount'] = 0;
|
|
|
617
|
+ $result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
|
|
|
618
|
+ }
|
|
|
619
|
+
|
|
|
620
|
+ if (!$onlyGift) {
|
|
|
621
|
+ // 加价购
|
|
|
622
|
+ $result['advanceBuyCount'] = 0;
|
|
|
623
|
+ $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
|
|
|
624
|
+ }
|
|
|
625
|
+
|
|
|
626
|
+ if (!$onlyGift && !$onlyAdvanceBuy) {
|
610
|
// 购买的可用商品列表
|
627
|
// 购买的可用商品列表
|
611
|
$validGoods = Helpers::formatCartGoods($data['goods_list']);
|
628
|
$validGoods = Helpers::formatCartGoods($data['goods_list']);
|
612
|
!empty($validGoods) && $result['goods'] = $validGoods;
|
629
|
!empty($validGoods) && $result['goods'] = $validGoods;
|
|
@@ -615,17 +632,15 @@ class CartModel |
|
@@ -615,17 +632,15 @@ class CartModel |
615
|
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
|
632
|
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
|
616
|
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
|
633
|
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
|
617
|
|
634
|
|
618
|
- // 赠品
|
635
|
+ // 赠品和加价购商品
|
619
|
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
|
636
|
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
|
620
|
- $result['freebie'] = $data['gift_list'];
|
|
|
621
|
- // 加价购
|
|
|
622
|
- $result['advanceBuyCount'] = 0;
|
|
|
623
|
- $result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
|
637
|
+
|
624
|
// 结算数据
|
638
|
// 结算数据
|
625
|
$result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
639
|
$result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
626
|
$result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
|
640
|
$result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
|
627
|
$result['count'] = $data['shopping_cart_data']['goods_count'];
|
641
|
$result['count'] = $data['shopping_cart_data']['goods_count'];
|
628
|
$result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
642
|
$result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
|
|
643
|
+ }
|
629
|
|
644
|
|
630
|
return $result;
|
645
|
return $result;
|
631
|
}
|
646
|
}
|