...
|
...
|
@@ -43,11 +43,12 @@ class CartModel |
|
|
/**
|
|
|
* @param integer $uid 用户ID
|
|
|
* @param string $shoppingKey 未登录用户唯一识别码
|
|
|
* @param string $cartType 购物车类型
|
|
|
* @param bool $onlyGift 只获取赠品的商品数据
|
|
|
* @param bool $onlyAdvanceBuy 只获取加价购的商品数据
|
|
|
* @return array|mixed 处理之后的购物车数据
|
|
|
*/
|
|
|
public static function getCartData($uid, $shoppingKey, $onlyGift = false, $onlyAdvanceBuy = false)
|
|
|
public static function getCartData($uid, $shoppingKey, $cartType = 'all', $onlyGift = false, $onlyAdvanceBuy = false)
|
|
|
{
|
|
|
$result = array('cartNav' => true);
|
|
|
|
...
|
...
|
@@ -60,22 +61,33 @@ class CartModel |
|
|
$cartData = CartData::cartData($uid, $shoppingKey);
|
|
|
|
|
|
// 处理普通购物车和预售购物车的数据
|
|
|
if (isset($cartData['data']) && !empty($cartData['data'])) {
|
|
|
do {
|
|
|
if (!isset($cartData['data']) || empty($cartData['data'])) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
$cart = $cartData['data'];
|
|
|
|
|
|
/* 普通购物车 */
|
|
|
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'], $onlyGift, $onlyAdvanceBuy);
|
|
|
if ($cartType !== 'all') { // 加价购或者赠品数据
|
|
|
$result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* 预售购物车 */
|
|
|
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'], $onlyGift, $onlyAdvanceBuy);
|
|
|
$ordinaryCount = intval($cart['ordinary_cart_data']['shopping_cart_data']['goods_count']);
|
|
|
$advanceCount = intval($cart['advance_cart_data']['shopping_cart_data']['goods_count']);
|
|
|
// 普通购物车和预售购物车都为空
|
|
|
if ($ordinaryCount === 0 && $advanceCount === 0) {
|
|
|
$result['isEmptyCart'] = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
/* 普通购物车 */
|
|
|
$result['commonGoodsCount'] = $ordinaryCount;
|
|
|
$result['commonCart'] = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
|
|
/* 预售购物车 */
|
|
|
$result['presellGoodsCount'] = $advanceCount;
|
|
|
$result['preSellCart'] = self::procCartData($cart['advance_cart_data'], $onlyGift, $onlyAdvanceBuy);
|
|
|
}while(0);
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -611,36 +623,52 @@ class CartModel |
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
if (!$onlyAdvanceBuy) {
|
|
|
// 赠品
|
|
|
$result['giftCount'] = 0;
|
|
|
$result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
|
|
|
do {
|
|
|
// 数据为空时返回空的标志
|
|
|
if (empty($data)) {
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (!$onlyGift) {
|
|
|
if ($onlyAdvanceBuy) {
|
|
|
// 赠品
|
|
|
$result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list']);
|
|
|
break;
|
|
|
}
|
|
|
if ($onlyGift) {
|
|
|
// 加价购
|
|
|
$result['advanceBuyCount'] = 0;
|
|
|
$result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift'], $result['advanceBuyCount']);
|
|
|
$result['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift']);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
if (!$onlyGift && !$onlyAdvanceBuy) {
|
|
|
// 购买的可用商品列表
|
|
|
$validGoods = Helpers::formatCartGoods($data['goods_list']);
|
|
|
!empty($validGoods) && $result['goods'] = $validGoods;
|
|
|
if (!empty($validGoods)) {
|
|
|
$result['goods'] = $validGoods;
|
|
|
}
|
|
|
|
|
|
// 失效商品列表
|
|
|
$notValidGoods = Helpers::formatCartGoods($data['sold_out_goods_list']);
|
|
|
!empty($notValidGoods) && $result['$notValidGoods'] = $notValidGoods;
|
|
|
if (!empty($notValidGoods)) {
|
|
|
$result['$notValidGoods'] = $notValidGoods;
|
|
|
}
|
|
|
|
|
|
// 赠品和加价购商品
|
|
|
(count($data['gift_list']) || count($data['price_gift'])) && $result['freebieOrAdvanceBuy'] = true;
|
|
|
if (count($data['gift_list']) || count($data['price_gift'])) {
|
|
|
$result['freebieOrAdvanceBuy'] = true;
|
|
|
// 赠品
|
|
|
$result['giftCount'] = 0;
|
|
|
$result['freebie'] = Helpers::formatAdvanceGoods($data['gift_list'], $result['giftCount']);
|
|
|
// 加价购
|
|
|
$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']);
|
|
|
}
|
|
|
}while(0);
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
|