...
|
...
|
@@ -23,7 +23,7 @@ class CartModel |
|
|
* @param int $productSku 商品SKU
|
|
|
* @param int $buyNumber 购买数量
|
|
|
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
|
|
|
* @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑
|
|
|
* @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
|
|
|
* @param null|int $promotionId 促销id,默认null(加价购有关)
|
|
|
* @param null|int $uid 用户UID,可以不传
|
|
|
* @return array 加入购物车接口返回的数据
|
...
|
...
|
@@ -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);
|
|
|
}
|
|
|
|
|
|
}
|
...
|
...
|
@@ -406,7 +408,7 @@ class CartModel |
|
|
$oneGoods['name'] = $single['product_name'];
|
|
|
$oneGoods['color'] = $single['color_name'];
|
|
|
$oneGoods['size'] = $single['size_name'];
|
|
|
$oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00
|
|
|
$oneGoods['price'] = Helpers::transPrice($single['sales_price']);
|
|
|
$oneGoods['count'] = $single['buy_number'];
|
|
|
|
|
|
$result['goods'][] = $oneGoods;
|
...
|
...
|
@@ -428,18 +430,20 @@ class CartModel |
|
|
}
|
|
|
|
|
|
// 有货币
|
|
|
$result['yohoCoin'] = isset($orderCompute['use_yoho_coin']) ? isset($orderCompute['use_yoho_coin']) : $payReturn['yoho_coin'];
|
|
|
$result['yohoCoin'] = (isset($orderCompute['use_yoho_coin']) && !empty($orderCompute['use_yoho_coin'])) ? $orderCompute['use_yoho_coin'] : $payReturn['yoho_coin'];
|
|
|
|
|
|
// 订单数据
|
|
|
if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
|
|
|
$sumPrice = isset($orderCompute['order_amount']) ? $orderCompute['order_amount'] : $payReturn['shopping_cart_data']['order_amount'];
|
|
|
$salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['discount_amount'];
|
|
|
$freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list'][1]['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][1]['promotion_amount'];
|
|
|
$couponPrice = isset($orderCompute['coupon_amount']) ? $orderCompute['coupon_amount'] : false;
|
|
|
$salePrice = isset($orderCompute['discount_amount']) ? $orderCompute['discount_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][3]['promotion_amount'];
|
|
|
$price = isset($orderCompute['last_order_amount']) ? $orderCompute['last_order_amount'] : $payReturn['shopping_cart_data']['last_order_amount'];
|
|
|
$freight = isset($orderCompute['promotion_formula_list']['promotion_amount']) ? $orderCompute['promotion_formula_list']['promotion_amount'] : $payReturn['shopping_cart_data']['promotion_formula_list'][1]['promotion_amount'];
|
|
|
$result['sumPrice'] = Helpers::transPrice($sumPrice);
|
|
|
$result['salePrice'] = Helpers::transPrice($salePrice);
|
|
|
$result['price'] = Helpers::transPrice($price);
|
|
|
$result['freight'] = strtr($freight, array('¥'=>'','¥'=>'')) . '.00';
|
|
|
$result['freight'] = $freight;
|
|
|
$result['couponPrice'] = $couponPrice;
|
|
|
}
|
|
|
|
|
|
// 发票有关数据
|
...
|
...
|
@@ -468,7 +472,7 @@ class CartModel |
|
|
// 优惠券数据
|
|
|
$coupons = array();
|
|
|
!empty($orderCompute['coupon_amount']) && $coupons['value'] = $orderInfo['couponValue'];
|
|
|
$coupons += self::getCouponList($uid, 0, 1, true);
|
|
|
$coupons += self::getCouponList($uid, true);
|
|
|
$result['coupon'] = $coupons;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -535,7 +539,7 @@ class CartModel |
|
|
if (isset($coupons['data'])) {
|
|
|
|
|
|
if ($onlyTotal) {
|
|
|
$result['count'] = $coupons['data']['total'];
|
|
|
$result['count'] = count($coupons['data']['couponList']);
|
|
|
} else {
|
|
|
$couponArr = array();
|
|
|
isset($coupons['data']['couponList']) && $couponArr = $coupons['data']['couponList'];
|
...
|
...
|
@@ -599,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();
|
|
|
|
|
|
$oneGoods = 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['advanceBuy'] = Helpers::formatAdvanceGoods($data['price_gift']);
|
|
|
// 结算数据
|
|
|
$result['price'] = $data['shopping_cart_data']['order_amount'];
|
|
|
$result['activityPrice'] = $data['shopping_cart_data']['discount_amount'];
|
|
|
$result['count'] = $data['shopping_cart_data']['goods_count'];
|
|
|
$result['sumPrice'] = $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;
|
|
|
}
|
...
|
...
|
|