...
|
...
|
@@ -43,9 +43,11 @@ class CartModel |
|
|
/**
|
|
|
* @param integer $uid 用户ID
|
|
|
* @param string $shoppingKey 未登录用户唯一识别码
|
|
|
* @param bool $onlyGift 只获取赠品的商品数据
|
|
|
* @param bool $onlyAdvanceBuy 只获取加价购的商品数据
|
|
|
* @return array|mixed 处理之后的购物车数据
|
|
|
*/
|
|
|
public static function getCartData($uid, $shoppingKey)
|
|
|
public static function getCartData($uid, $shoppingKey, $onlyGift = false, $onlyAdvanceBuy = false)
|
|
|
{
|
|
|
$result = array('cartNav' => true);
|
|
|
|
...
|
...
|
@@ -64,13 +66,13 @@ class CartModel |
|
|
/* 普通购物车 */
|
|
|
if(isset($cart['ordinary_cart_data'])) {
|
|
|
$result['commonGoodsCount'] = $cart['ordinary_cart_data']['shopping_cart_data']['goods_count'];
|
|
|
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data']);
|
|
|
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
|
|
}
|
|
|
|
|
|
/* 预售购物车 */
|
|
|
if(isset($cart['advance_cart_data'])) {
|
|
|
$result['presellGoodsCount'] = $cart['advance_cart_data']['shopping_cart_data']['goods_count'];
|
|
|
$result['preSellCart'] = self::procCartData($cart['advance_cart_data']);
|
|
|
$result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -601,31 +603,44 @@ class CartModel |
|
|
* 处理不同类型的购物车数据
|
|
|
*
|
|
|
* @param array $data 不同类型购物车数据
|
|
|
* @param bool $onlyGift 只获取赠品的商品数据
|
|
|
* @param bool $onlyAdvanceBuy 只获取加价购的商品数据
|
|
|
* @return array $result 处理之后的不同类型购物车数据
|
|
|
*/
|
|
|
private static function procCartData($data)
|
|
|
private static function procCartData($data, $onlyGift = false, $onlyAdvanceBuy = false)
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
// 购买的可用商品列表
|
|
|
$validGoods = Helpers::formatCartGoods($data['goods_list']);
|
|
|
!empty($validGoods) && $result['goods'] = $validGoods;
|
|
|
|
|
|
// 失效商品列表
|
|
|
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
|
|
|
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
|
|
|
|
|
|
// 赠品
|
|
|
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
|
|
|
$result['freebie'] = $data['gift_list'];
|
|
|
// 加价购
|
|
|
$result['advanceBuyCount'] = 0;
|
|
|
$result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
|
|
|
// 结算数据
|
|
|
$result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
|
|
$result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
|
|
|
$result['count'] = $data['shopping_cart_data']['goods_count'];
|
|
|
$result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
|
|
if (!$onlyAdvanceBuy) {
|
|
|
// 赠品
|
|
|
$result['giftCount'] = 0;
|
|
|
$result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
|
|
|
}
|
|
|
|
|
|
if (!$onlyGift) {
|
|
|
// 加价购
|
|
|
$result['advanceBuyCount'] = 0;
|
|
|
$result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
|
|
|
}
|
|
|
|
|
|
if (!$onlyGift && !$onlyAdvanceBuy) {
|
|
|
// 购买的可用商品列表
|
|
|
$validGoods = Helpers::formatCartGoods($data['goods_list']);
|
|
|
!empty($validGoods) && $result['goods'] = $validGoods;
|
|
|
|
|
|
// 失效商品列表
|
|
|
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
|
|
|
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
|
|
|
|
|
|
// 赠品和加价购商品
|
|
|
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
|
|
|
|
|
|
// 结算数据
|
|
|
$result['price'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
|
|
$result['activityPrice'] = Helpers::transPrice($data['shopping_cart_data']['discount_amount']);
|
|
|
$result['count'] = $data['shopping_cart_data']['goods_count'];
|
|
|
$result['sumPrice'] = Helpers::transPrice($data['shopping_cart_data']['order_amount']);
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
|