|
@@ -9,21 +9,52 @@ defined('InShopNC') or exit('Access Invalid!');
|
|
|
|
|
|
require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
|
|
|
|
|
|
-class cartControl extends mobileControl
|
|
|
+class cart_item
|
|
|
{
|
|
|
- public function __construct()
|
|
|
+ private $cart_id;
|
|
|
+ private $bl_id;
|
|
|
+ private $goods_id;
|
|
|
+ private $goods_num;
|
|
|
+
|
|
|
+ public function __construct($cart_id,$bl_id,$goods_id,$goods_num)
|
|
|
{
|
|
|
- parent::__construct();
|
|
|
+ $this->cart_id = intval($cart_id);
|
|
|
+ $this->bl_id = intval($bl_id);
|
|
|
+ $this->goods_id = intval($goods_id);
|
|
|
+ $this->goods_num = intval($goods_num);
|
|
|
}
|
|
|
|
|
|
+ public function is_bl() {
|
|
|
+ return $this->bl_id > 0;
|
|
|
+ }
|
|
|
+ public function format() {
|
|
|
+ $cart_item['cart_id'] = $this->cart_id;
|
|
|
+ $cart_item['goods_id'] = $this->goods_id;
|
|
|
+ $cart_item['bl_id'] = $this->bl_id;
|
|
|
+ $cart_item['goods_num'] = $this->goods_num;
|
|
|
+ return $cart_item;
|
|
|
+ }
|
|
|
+ public function goods_ids()
|
|
|
+ {
|
|
|
+ if($this->is_bl()) {
|
|
|
+ return activity_helper::bundling_goods($this->bl_id);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return array($this->goods_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class cartControl extends mobileControl
|
|
|
+{
|
|
|
+ public function __construct() {
|
|
|
+ parent::__construct();
|
|
|
+ }
|
|
|
public function listOp()
|
|
|
{
|
|
|
$model_cart = Model('cart');
|
|
|
$minest_cartid = intval($_GET['minest_cartid']);
|
|
|
|
|
|
- $has_more = false;
|
|
|
- $pages = 1;
|
|
|
-
|
|
|
if($_SESSION['is_login'] == 1)
|
|
|
{
|
|
|
$page_size = $this->page_size();
|
|
@@ -40,13 +71,16 @@ class cartControl extends mobileControl
|
|
|
$pages = $this->pages($total);
|
|
|
$has_more = $total > $page_size;
|
|
|
}
|
|
|
-
|
|
|
$cart_list = $model_cart->listCart('db',$condition,$page_size);
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
$cart_list = $model_cart->listCart('Session');
|
|
|
+ $total = count($cart_list);
|
|
|
+ $has_more = false;
|
|
|
+ $pages = 1;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
$goods_ids = array();
|
|
|
$cart_infos = array();
|
|
|
foreach ($cart_list as $item) {
|
|
@@ -63,12 +97,13 @@ class cartControl extends mobileControl
|
|
|
$summaries = $helper->cart_summary($goods_ids,$related_goods);
|
|
|
$summary_list = $summaries['summary'];
|
|
|
if(!empty($related_goods)) {
|
|
|
- $related_summary = $helper->cart_summary($goods_ids,$x);
|
|
|
+ $related_summary = $helper->cart_summary($related_goods,$x);
|
|
|
$summary_list = array_merge($summary_list,$related_summary['summary']);
|
|
|
}
|
|
|
|
|
|
- $ret['cart_list'] = $cart_infos;
|
|
|
- $ret['summary'] = $summary_list;
|
|
|
+ $ret['cart_count'] = $total;
|
|
|
+ $ret['cart_list'] = $cart_infos;
|
|
|
+ $ret['summary'] = $summary_list;
|
|
|
$ret['groupbuy'] = $summaries['groupbuy'];
|
|
|
$ret['limitime'] = $summaries['limitime'];
|
|
|
$ret['bundling'] = $summaries['bundling'];
|
|
@@ -77,69 +112,6 @@ class cartControl extends mobileControl
|
|
|
return self::outsuccess($ret);
|
|
|
}
|
|
|
|
|
|
- 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","groupbuy_intro");
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 购物车列表
|
|
|
*/
|
|
@@ -200,49 +172,110 @@ class cartControl extends mobileControl
|
|
|
self::outsuccess(array('cart_list' => $cart_list, 'mobile_page' => mobile_page($page_count)));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 购物车添加
|
|
|
- */
|
|
|
public function addOp()
|
|
|
{
|
|
|
- $model_goods = Model('goods');
|
|
|
- $logic_buy_1 = Logic('buy_1');
|
|
|
+ $ret = $this->do_add($err,$ext_info);
|
|
|
+ if($ret === false) {
|
|
|
+ $msg = isset($err['msg']) ? $err['msg'] : '';
|
|
|
+ return self::outerr($err['code'],$msg);
|
|
|
+ } else {
|
|
|
+ return self::outsuccess($ret);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addexOp()
|
|
|
+ {
|
|
|
+ $ret = $this->do_add($err,$ext_info);
|
|
|
+ if($ret === false) {
|
|
|
+ $msg = isset($err['msg']) ? $err['msg'] : '';
|
|
|
+ return self::outerr($err['code'],$msg);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $bl_id = intval($ext_info['bl_id']);
|
|
|
+ $goods_id = intval($ext_info['goods_id']);
|
|
|
+ $cart_id = intval($ext_info['cart_id']);
|
|
|
+
|
|
|
+ $model_cart = Model('cart');
|
|
|
+ $save_type = $this->save_type();
|
|
|
+ $cart_num = $model_cart->getCartNum($save_type,array('buyer_id'=>$_SESSION['member_id']));
|
|
|
+ $goods_num = $model_cart->getCartItemNum($save_type,$cart_id);
|
|
|
+ $item = new cart_item($cart_id,$bl_id,$goods_id,$goods_num);
|
|
|
+
|
|
|
+ $result['cart_count'] = $cart_num;
|
|
|
+ $result['cart_list'][] = $item->format();
|
|
|
+
|
|
|
+
|
|
|
+ $gids = $item->goods_ids();
|
|
|
+ if(empty($gids)) {
|
|
|
+ $result['summary'] = array();
|
|
|
+ $result['groupbuy'] = array();
|
|
|
+ $result['limitime'] = array();
|
|
|
+ $result['bundling'] = array();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $helper = new goods_helper();
|
|
|
+ $summaries = $helper->cart_summary($gids,$related_goods);
|
|
|
+ $summary_list = $summaries['summary'];
|
|
|
+ if(!empty($related_goods)) {
|
|
|
+ $related_summary = $helper->cart_summary($related_goods,$x);
|
|
|
+ $summary_list = array_merge($summary_list,$related_summary['summary']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result['summary'] = $summary_list;
|
|
|
+ $result['groupbuy'] = $summaries['groupbuy'];
|
|
|
+ $result['limitime'] = $summaries['limitime'];
|
|
|
+ $result['bundling'] = $summaries['bundling'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::outsuccess($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ public function do_add(&$err,&$ext_info)
|
|
|
+ {
|
|
|
if (is_numeric($_GET['goods_id']) && is_numeric($_POST['quantity']))
|
|
|
{
|
|
|
$goods_id = intval($_POST['goods_id']);
|
|
|
$quantity = intval($_POST['quantity']);
|
|
|
|
|
|
if ($goods_id <= 0 || $quantity <= 0) {
|
|
|
- return self::outerr(errcode::ErrInputParam);
|
|
|
+ $err = array('code' => errcode::ErrInputParam);
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
+ $model_goods = Model('goods');
|
|
|
+ $logic_buy_1 = Logic('buy_1');
|
|
|
$goods_info = $model_goods->getGoodsOnlineInfoAndPromotionById($goods_id);
|
|
|
- //抢购
|
|
|
$logic_buy_1->getGroupbuyInfo($goods_info);
|
|
|
- //限时折扣
|
|
|
$logic_buy_1->getXianshiInfo($goods_info, $quantity);
|
|
|
|
|
|
$ret = $this->check_goods($goods_info, $quantity);
|
|
|
if(is_array($ret)) {
|
|
|
- return self::outerr($ret['code'],$ret['msg']);
|
|
|
+ $err = $ret;
|
|
|
+ return false;
|
|
|
}
|
|
|
+ $bl_id = 0;
|
|
|
}
|
|
|
elseif (is_numeric($_GET['bl_id']))
|
|
|
{
|
|
|
- //优惠套装加入购物车(单套)
|
|
|
if ($_SESSION['is_login'] != 1) {
|
|
|
- return self::outerr(errcode::ErrUnLogin);
|
|
|
+ $err = array('code' => errcode::ErrUnLogin);
|
|
|
+ return false;
|
|
|
}
|
|
|
$bl_id = intval($_GET['bl_id']);
|
|
|
- if ($bl_id <= 0) return ;
|
|
|
+ if ($bl_id <= 0) {
|
|
|
+ $err = array('code' => errcode::ErrInputParam);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
$model_bl = Model('p_bundling');
|
|
|
$bl_info = $model_bl->getBundlingInfo(array('bl_id'=>$bl_id));
|
|
|
if (empty($bl_info) || $bl_info['bl_state'] == '0') {
|
|
|
- return self::outerr(errcode::ErrBLUnExist);
|
|
|
+ $err = array('code' => errcode::ErrBLUnExist);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- //检查每个商品是否符合条件,并重新计算套装总价
|
|
|
$bl_goods_list = $model_bl->getBundlingGoodsList(array('bl_id'=>$bl_id));
|
|
|
$goods_id_array = array();
|
|
|
$bl_amount = 0;
|
|
@@ -250,10 +283,17 @@ class cartControl extends mobileControl
|
|
|
$goods_id_array[] = $goods['goods_id'];
|
|
|
$bl_amount += $goods['bl_goods_price'];
|
|
|
}
|
|
|
+
|
|
|
$model_goods = Model('goods');
|
|
|
$goods_list = $model_goods->getGoodsOnlineListAndPromotionByIdArray($goods_id_array);
|
|
|
- foreach ($goods_list as $goods) {
|
|
|
- $this->check_goods($goods,1);
|
|
|
+ foreach ($goods_list as $goods)
|
|
|
+ {
|
|
|
+ $err = $this->check_goods($goods,1);
|
|
|
+ if($err === true) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//优惠套装作为一条记录插入购物车,图片取套装内的第一个商品图
|
|
@@ -267,6 +307,12 @@ class cartControl extends mobileControl
|
|
|
$goods_info['store_name'] = $bl_info['store_name'];
|
|
|
$goods_info['bl_id'] = $bl_id;
|
|
|
$quantity = 1;
|
|
|
+ $goods_id = intval($goods_info['goods_id']);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $err = array('code' => errcode::ErrInputParam);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
//已登录状态,存入数据库,未登录时,存入Session
|
|
@@ -279,11 +325,14 @@ class cartControl extends mobileControl
|
|
|
|
|
|
$model_cart = Model('cart');
|
|
|
$insert = $model_cart->addCart($goods_info, $save_type , $quantity);
|
|
|
- if ($insert) { //todo 此处返回结果有变化
|
|
|
+
|
|
|
+ if ($insert) {
|
|
|
$data = array('result' => 1, 'num' => $model_cart->cart_goods_num, 'amount' => ncPriceFormat($model_cart->cart_all_price));
|
|
|
- return self::outsuccess($data);
|
|
|
+ $ext_info = array('bl_id' => $bl_id,'goods_id' => $goods_id,'cart_id' => $insert);
|
|
|
+ return $data;
|
|
|
} else {
|
|
|
- return self::outerr(errcode::ErrAddCart);
|
|
|
+ $err = array('code' => errcode::ErrAddCart);
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -383,50 +432,33 @@ class cartControl extends mobileControl
|
|
|
|
|
|
public function editOp()
|
|
|
{
|
|
|
- $cart_list = explode(',', urldecode($_POST['cart_list']));
|
|
|
- if (!is_array($cart_list)) {
|
|
|
- return self::outerr(errcode::ErrCart, '修改购物车列表参数格式错误');
|
|
|
+ $cart_id = intval($_POST['cart_id']);
|
|
|
+ $quantity = intval($_POST['quantity']);
|
|
|
+
|
|
|
+ if ($cart_id <= 0 || $quantity < 0) {
|
|
|
+ return self::outerr(errcode::ErrInputParam);
|
|
|
}
|
|
|
|
|
|
- $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];
|
|
|
- }
|
|
|
- }
|
|
|
+ if($quantity > 0) {
|
|
|
+ $ret = $this->do_edit(intval(abs($cart_id)),intval($quantity));
|
|
|
}
|
|
|
- if(empty($new_cart_list)) {
|
|
|
- return self::outerr(errcode::ErrCart, '修改购物车列表参数格式错误');
|
|
|
+ else {
|
|
|
+ $ret = $this->do_del($cart_id);
|
|
|
}
|
|
|
|
|
|
- $errors = array();
|
|
|
- foreach($new_cart_list as $cart_id => $quantity)
|
|
|
- {
|
|
|
- if($quantity == 0) {
|
|
|
- $quantity = 1;
|
|
|
- $ret = $this->do_edit(intval(abs($cart_id)),intval(abs($quantity)));
|
|
|
- }
|
|
|
- else {
|
|
|
- $ret = $this->do_del($cart_id);
|
|
|
- }
|
|
|
- //删除购物车在分页的情况下,删除会导致页面计算出问题.
|
|
|
-// if($quantity > 0) {
|
|
|
-// $ret = $this->do_edit(intval(abs($cart_id)),intval(abs($quantity)));
|
|
|
-// }
|
|
|
-// else {
|
|
|
-// $ret = $this->do_del($cart_id);
|
|
|
-// }
|
|
|
- if(is_array($ret)) {
|
|
|
- array_push($errors,$ret);
|
|
|
- }
|
|
|
- }
|
|
|
+ if ($ret === true) {
|
|
|
+ $save_type = $this->save_type();
|
|
|
+ $mod_cart = Model('cart');
|
|
|
+ $cart_num = $mod_cart->getCartNum($save_type,array('buyer_id'=>$_SESSION['member_id']));
|
|
|
+ $goods_num = $mod_cart->getCartItemNum($save_type,$cart_id);
|
|
|
+
|
|
|
+ $result['cart_count'] = $cart_num;
|
|
|
+ $result['cart_id'] = $cart_id;
|
|
|
+ $result['goods_num'] = $goods_num;
|
|
|
|
|
|
- if (count($errors) > 0) {
|
|
|
- self::outerr(array('result' => '0', 'quantity_error' => $errors));
|
|
|
+ self::outsuccess($result);
|
|
|
} else {
|
|
|
- self::outsuccess(array('result' => '1'));
|
|
|
+ self::outerr(errcode::ErrAddCart,$ret['err_info']);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -507,11 +539,9 @@ class cartControl extends mobileControl
|
|
|
{
|
|
|
$model_cart = Model('cart');
|
|
|
if ($_SESSION['member_id']) {
|
|
|
- //登录状态下删除数据库内容
|
|
|
$delete = $model_cart->delCart('db',array('cart_id'=>$cart_id,'buyer_id'=>$_SESSION['member_id']));
|
|
|
return $delete;
|
|
|
} else {
|
|
|
- //未登录时删除cookie的购物车信息
|
|
|
$delete = $model_cart->delCart('Session',array('goods_id'=>$cart_id));
|
|
|
return $delete;
|
|
|
}
|
|
@@ -594,4 +624,14 @@ class cartControl extends mobileControl
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ private function save_type()
|
|
|
+ {
|
|
|
+ if ($_SESSION['is_login'] == 1) {
|
|
|
+ $save_type = 'db';
|
|
|
+ } else {
|
|
|
+ $save_type = 'Session';
|
|
|
+ }
|
|
|
+ return $save_type;
|
|
|
+ }
|
|
|
}
|