|
@@ -33,6 +33,9 @@ class cartControl extends mobileControl
|
|
|
|
|
|
//购物车列表 [得到最新商品属性及促销信息]
|
|
//购物车列表 [得到最新商品属性及促销信息]
|
|
$cart_list = $logic_buy_1->getGoodsCartList($cart_list);
|
|
$cart_list = $logic_buy_1->getGoodsCartList($cart_list);
|
|
|
|
+ $ret = array_chunk($cart_list,$this->page_size());
|
|
|
|
+ $pages = count($ret);
|
|
|
|
+ $cart_list = $ret[$this->page_no() - 1];
|
|
|
|
|
|
//购物车商品以店铺ID分组显示,并计算商品小计,店铺小计与总价由JS计算得出
|
|
//购物车商品以店铺ID分组显示,并计算商品小计,店铺小计与总价由JS计算得出
|
|
$store_cart_list = array();
|
|
$store_cart_list = array();
|
|
@@ -51,18 +54,82 @@ class cartControl extends mobileControl
|
|
|
|
|
|
if(in_array($_SESSION['client_type'],array('android', 'ios','ajax'))) {
|
|
if(in_array($_SESSION['client_type'],array('android', 'ios','ajax'))) {
|
|
$data = $this->format_cart($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list);
|
|
$data = $this->format_cart($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list);
|
|
- self::outsuccess($data);
|
|
|
|
|
|
+ self::outsuccess(array('carts' => $data,'mobile_page' => $pages));
|
|
} else {
|
|
} else {
|
|
$data = $this->format_cart($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list);
|
|
$data = $this->format_cart($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list);
|
|
- self::outsuccess($data);
|
|
|
|
- //self::outsuccess($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list);
|
|
|
|
|
|
+ self::outsuccess(array('carts' => $data,'mobile_page' => $pages));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function remove_goods(&$goods_info)
|
|
|
|
+ {
|
|
|
|
+ static $ex_goodsfield = array("buyer_id","store_id","store_name","gc_id","transport_id","goods_vat","goods_storage","goods_storage_alarm",
|
|
|
|
+ "is_fcode","promotions_id",);
|
|
|
|
+ static $ex_xsfield = array("xianshi_goods_id","xianshi_id","goods_id","store_id","goods_name","goods_price","goods_image","goods_url",
|
|
|
|
+ "image_url","xianshi_recommend");
|
|
|
|
+ static $ex_gbuyfield = array("groupbuy_id","goods_id","goods_commonid","goods_name","store_id","store_name","goods_price","recommended","views",
|
|
|
|
+ "class_id","s_class_id","is_vr","vr_city_id","vr_area_id","vr_mall_id","vr_class_id","vr_s_class_id","groupbuy_url","goods_url","start_time_text",
|
|
|
|
+ "end_time_text","groupbuy_state_text","reviewable","cancelable","state_flag","button_text","count_down_text","count_down");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(is_array($goods_info))
|
|
|
|
+ {
|
|
|
|
+ $store_id = $goods_info['store_id'];
|
|
|
|
+ foreach($ex_goodsfield as $key)
|
|
|
|
+ {
|
|
|
|
+ if(array_key_exists($key,$goods_info)) {
|
|
|
|
+ unset($goods_info[$key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(array_key_exists('xianshi_info',$goods_info))
|
|
|
|
+ {
|
|
|
|
+ $xs_info = &$goods_info['xianshi_info'];
|
|
|
|
+ if(is_array($xs_info))
|
|
|
|
+ {
|
|
|
|
+ foreach($ex_xsfield as $key)
|
|
|
|
+ {
|
|
|
|
+ if(array_key_exists($key,$xs_info)) {
|
|
|
|
+ unset($xs_info[$key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(array_key_exists('groupbuy_info',$goods_info))
|
|
|
|
+ {
|
|
|
|
+ $gbuy_info = &$goods_info['groupbuy_info'];
|
|
|
|
+ if(is_array($gbuy_info))
|
|
|
|
+ {
|
|
|
|
+ foreach($ex_gbuyfield as $key)
|
|
|
|
+ {
|
|
|
|
+ if(array_key_exists($key,$gbuy_info)) {
|
|
|
|
+ unset($gbuy_info[$key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(array_key_exists("state",$gbuy_info))
|
|
|
|
+ {
|
|
|
|
+ $state = intval($gbuy_info["state"]);
|
|
|
|
+ if($state == 20) {
|
|
|
|
+ $gbuy_info["state"] = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(array_key_exists("groupbuy_image",$gbuy_info)) {
|
|
|
|
+ $gbuy_info['groupbuy_image'] = cthumb($gbuy_info['groupbuy_image'], $store_id);
|
|
|
|
+ }
|
|
|
|
+ if(array_key_exists("groupbuy_image1",$gbuy_info)) {
|
|
|
|
+ $gbuy_info['groupbuy_image1'] = cthumb($gbuy_info['groupbuy_image1'], $store_id);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private function format_cart($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list)
|
|
private function format_cart($store_cart_list,$store_list,$mansong_rule_list,$free_freight_list)
|
|
{
|
|
{
|
|
$ret = array();
|
|
$ret = array();
|
|
- foreach($store_cart_list as $key => $val) {
|
|
|
|
|
|
+ foreach($store_cart_list as $key => $val)
|
|
|
|
+ {
|
|
$store_goods = array();
|
|
$store_goods = array();
|
|
$store_goods['store_info'] = $store_list[$key];
|
|
$store_goods['store_info'] = $store_list[$key];
|
|
$store_goods['free_freight'] = $free_freight_list[$key];
|
|
$store_goods['free_freight'] = $free_freight_list[$key];
|
|
@@ -70,6 +137,7 @@ class cartControl extends mobileControl
|
|
|
|
|
|
$store_goods['goods_info'] = array();
|
|
$store_goods['goods_info'] = array();
|
|
foreach($val as $index => $goods) {
|
|
foreach($val as $index => $goods) {
|
|
|
|
+ $this->remove_goods($goods);
|
|
array_push($store_goods['goods_info'],$goods);
|
|
array_push($store_goods['goods_info'],$goods);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -254,11 +322,6 @@ class cartControl extends mobileControl
|
|
|
|
|
|
public function cart_editOp()
|
|
public function cart_editOp()
|
|
{
|
|
{
|
|
- $token = trim($_GET['key']);
|
|
|
|
- if (false == $this->checkToken($token)) {
|
|
|
|
- return joutput_error($this->err_code);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
$cart_list = explode(',', urldecode($_POST['cart_list']));
|
|
$cart_list = explode(',', urldecode($_POST['cart_list']));
|
|
$new_cart_list = array();
|
|
$new_cart_list = array();
|
|
if (is_array($cart_list)) {
|
|
if (is_array($cart_list)) {
|
|
@@ -308,6 +371,116 @@ class cartControl extends mobileControl
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 购物车更新商品数量
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ public function editOp()
|
|
|
|
+ {
|
|
|
|
+ $cart_list = explode(',', urldecode($_POST['cart_list']));
|
|
|
|
+ if (!is_array($cart_list)) {
|
|
|
|
+ return self::outerr(errcode::ErrCart, '修改购物车列表参数格式错误');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $new_cart_list = array();
|
|
|
|
+ foreach ($cart_list as $value)
|
|
|
|
+ {
|
|
|
|
+ if (preg_match_all('/^(\d{1,10})\|(\d{1,6})$/', $value, $match)) {
|
|
|
|
+ if (intval($match[2][0]) > 0) {
|
|
|
|
+ $new_cart_list[$match[1][0]] = $match[2][0];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach($new_cart_list as $cart_id => $quantity)
|
|
|
|
+ {
|
|
|
|
+ if($quantity == 0) {
|
|
|
|
+ $this->do_edit(intval(abs($cart_id)),intval(abs($quantity)));
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function do_edit($cart_id,$quantity)
|
|
|
|
+ {
|
|
|
|
+ $model_cart = Model('cart');
|
|
|
|
+ $model_goods= Model('goods');
|
|
|
|
+ $logic_buy_1 = logic('buy_1');
|
|
|
|
+
|
|
|
|
+ //存放返回信息
|
|
|
|
+ $return = array();
|
|
|
|
+ $cart_info = $model_cart->getCartInfo(array('cart_id'=>$cart_id,'buyer_id'=>$_SESSION['member_id']));
|
|
|
|
+ if ($cart_info['bl_id'] == '0')
|
|
|
|
+ {
|
|
|
|
+ //普通商品
|
|
|
|
+ $goods_id = intval($cart_info['goods_id']);
|
|
|
|
+ $goods_info = $logic_buy_1->getGoodsOnlineInfo($goods_id,$quantity);
|
|
|
|
+ if(empty($goods_info))
|
|
|
|
+ {
|
|
|
|
+ if($_SESSION['is_login'] == 1) {
|
|
|
|
+ QueueClient::push('delCart', array('buyer_id'=>$_SESSION['member_id'],'cart_ids'=>array($cart_id)));
|
|
|
|
+ }
|
|
|
|
+ return array('cart_id' => $cart_id, 'quantity' => $quantity, 'err_info' => '商品已被下架');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //抢购
|
|
|
|
+ $logic_buy_1->getGroupbuyInfo($goods_info);
|
|
|
|
+ //限时折扣
|
|
|
|
+ $logic_buy_1->getXianshiInfo($goods_info,$quantity);
|
|
|
|
+ $quantity = $goods_info['goods_num'];
|
|
|
|
+
|
|
|
|
+ if(intval($goods_info['goods_storage']) < $quantity) {
|
|
|
|
+ $model_cart->editCart(array('goods_num'=>$goods_info['goods_storage']),array('cart_id'=>$cart_id,'buyer_id'=>$_SESSION['member_id']));
|
|
|
|
+ return array('cart_id' => $cart_id, 'quantity' => $goods_info['goods_storage'], 'err_info' => '库存不足,已将您购物车更新为库存数量.');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //优惠套装商品
|
|
|
|
+ $model_bl = Model('p_bundling');
|
|
|
|
+ $bl_goods_list = $model_bl->getBundlingGoodsList(array('bl_id'=>$cart_info['bl_id']));
|
|
|
|
+ $goods_id_array = array();
|
|
|
|
+ foreach ($bl_goods_list as $goods) {
|
|
|
|
+ $goods_id_array[] = $goods['goods_id'];
|
|
|
|
+ }
|
|
|
|
+ $goods_list = $model_goods->getGoodsOnlineListAndPromotionByIdArray($goods_id_array);
|
|
|
|
+
|
|
|
|
+ //如果其中有商品下架,删除
|
|
|
|
+ if (count($goods_list) != count($goods_id_array)) {
|
|
|
|
+ QueueClient::push('delCart', array('buyer_id'=>$_SESSION['member_id'],'cart_ids'=>array($cart_id)));
|
|
|
|
+ return array('cart_id' => $cart_id, 'quantity' => 0, 'err_info' => '该优惠套装已经无效,建议您购买单个商品.');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //如果有商品库存不足,更新购买数量到目前最大库存
|
|
|
|
+ foreach ($goods_list as $goods_info)
|
|
|
|
+ {
|
|
|
|
+ if ($quantity > $goods_info['goods_storage']) {
|
|
|
|
+ $model_cart->editCart(array('goods_num'=>$goods_info['goods_storage']),array('cart_id'=>$cart_id,'buyer_id'=>$_SESSION['member_id']));
|
|
|
|
+ return array('cart_id' => $cart_id, 'quantity' => $goods_info['goods_storage'], 'err_info' => '该优惠套装部分商品库存不足,建议您降低购买数量或购买库存足够的单个商品.');
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $goods_info['goods_price'] = $cart_info['goods_price'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $data = array();
|
|
|
|
+ $data['goods_num'] = $quantity;
|
|
|
|
+ $data['goods_price'] = $goods_info['goods_price'];
|
|
|
|
+
|
|
|
|
+ if($_SESSION['is_login'] == 1) {
|
|
|
|
+ $update = $model_cart->editCart($data,array('cart_id'=>$cart_id,'buyer_id'=>$_SESSION['member_id']));
|
|
|
|
+ } else {
|
|
|
|
+ $update = $model_cart->editCart($data,array('cart_id'=>$cart_id));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($update) {
|
|
|
|
+ return true;
|
|
|
|
+ } else {
|
|
|
|
+ return array('cart_id' => $cart_id, 'quantity' => 0, 'err_info' => '更新购物车失败.');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 购物车删除
|
|
* 购物车删除
|
|
*/
|
|
*/
|
|
public function cart_delOp()
|
|
public function cart_delOp()
|
|
@@ -318,9 +491,7 @@ class cartControl extends mobileControl
|
|
}
|
|
}
|
|
|
|
|
|
$cart_id = intval($_POST['cart_id']);
|
|
$cart_id = intval($_POST['cart_id']);
|
|
-
|
|
|
|
$model_cart = Model('cart');
|
|
$model_cart = Model('cart');
|
|
-
|
|
|
|
if ($cart_id > 0) {
|
|
if ($cart_id > 0) {
|
|
$condition = array();
|
|
$condition = array();
|
|
$condition['buyer_id'] = $this->member_info['member_id'];
|
|
$condition['buyer_id'] = $this->member_info['member_id'];
|