From af4af0d1ed4b62a0a8237dfc6a78936ba6bc657c Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 29 Jun 2024 15:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/order/CartController.php | 6 ++++- app/api/logic/order/CartLogic.php | 29 +++++++++++++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index 0f0346d9b..7496016df 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -48,7 +48,11 @@ class CartController extends BaseApiController return $this->fail('库存数量不足'); } if ($result) { - $res = CartLogic::edit($params); + if(isset($params['type']) && $params['type'] == 1){ + $res = CartLogic::add($params); + }else{ + $res = CartLogic::edit($params); + } } else { $res = CartLogic::add($params); } diff --git a/app/api/logic/order/CartLogic.php b/app/api/logic/order/CartLogic.php index 8afb470ba..9b2d32d14 100644 --- a/app/api/logic/order/CartLogic.php +++ b/app/api/logic/order/CartLogic.php @@ -33,16 +33,29 @@ class CartLogic extends BaseLogic } Db::startTrans(); try { - $cart = Cart::create([ + //check + $check = Cart::where([ 'uid' => $params['uid'], - 'type' => $params['type']??'', + 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], - 'store_id' => $params['store_id']??0, - 'staff_id' => $params['staff_id']??0, - 'product_attr_unique' => '', - 'cart_num' => $params['cart_num'], - 'is_new' => $params['is_new']??0, - ]); + 'is_pay'=>0 + ])->field('id')->find(); + if($check){ + Cart::where('id',$check['id'])->inc('cart_num',$params['cart_num']) + ->update(); + $cart['id'] = $check['id']; + }else{ + $cart = Cart::create([ + 'uid' => $params['uid'], + 'type' => $params['type']??'', + 'product_id' => $params['product_id'], + 'store_id' => $params['store_id']??0, + 'staff_id' => $params['staff_id']??0, + 'product_attr_unique' => '', + 'cart_num' => $params['cart_num'], + 'is_new' => $params['is_new']??0, + ]); + } StoreProductLog::create([ 'type'=>'cart', 'uid' => $params['uid'],