Authored by Rock Zhang

添加获取购物车数目接口

... ... @@ -41,6 +41,8 @@ class CartModel
}
/**
* 获取购物车信息
*
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @param string $cartType 购物车类型
... ... @@ -97,6 +99,31 @@ class CartModel
}
/**
* 获取购物车商品数目
*
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array|mixed 购物车商品数目
*/
public static function getCartCount($uid, $shoppingKey)
{
$result = array(
'code' => 200,
'data' => array(
'cart_goods_count' => 0
)
);
$carData = self::getCartData($uid, $shoppingKey);
if (isset($carData['commonGoodsCount'])) {
$result['data']['cart_goods_count'] = $carData['commonGoodsCount'] + $carData['presellGoodsCount'];
}
return $result;
}
/**
* 购物车商品选择与取消接口返回的数据处理
*
* @param int $uid 用户ID
... ... @@ -490,10 +517,18 @@ class CartModel
{
$result = array('code' => 400, 'message' => '出错啦~');
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
do {
if (empty($couponCode)) {
$result['code'] = 401;
$result['message'] = '优惠券代码为空';
break;
}
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
}while(0);
return $result;
}
... ...
... ... @@ -49,6 +49,7 @@ class IndexController extends AbstractAction
// 渲染模板
$this->_view->display('index', $data);
}
/*
* 异步获取购物车数据
*/
... ... @@ -71,6 +72,22 @@ class IndexController extends AbstractAction
}
/**
* 异步获取购物车商品数目
*/
public function countAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::getCartCount($uid, $shoppingKey);
}
$this->echoJson($result);
}
/**
* 购物车商品选择与取消
*/
public function selectAction()
... ... @@ -84,11 +101,7 @@ class IndexController extends AbstractAction
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -106,11 +119,7 @@ class IndexController extends AbstractAction
$result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -126,11 +135,7 @@ class IndexController extends AbstractAction
$result = CartModel::addToFav($uid, $productId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/*
... ... @@ -184,11 +189,7 @@ class IndexController extends AbstractAction
$result['num'] = $num;
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/*
... ... @@ -214,11 +215,7 @@ class IndexController extends AbstractAction
$result = CartModel::giftProductData($skn, $promotionId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -238,11 +235,7 @@ class IndexController extends AbstractAction
$result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -264,11 +257,7 @@ class IndexController extends AbstractAction
$result = CartModel::modifyCartProduct($uid, $params, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -318,11 +307,7 @@ class IndexController extends AbstractAction
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -333,16 +318,12 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$couponCode = $this->get('couponCode', '');
$couponCode = $this->post('couponCode', '');
$uid = $this->getUid(true);
$result = CartModel::searchCoupon($uid, $couponCode);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -357,11 +338,7 @@ class IndexController extends AbstractAction
$result = CartModel::getCouponList($uid);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ...