From 10e6a21b35d053f0e7eab93224e94d4f3d61ed48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A=E5=A4=A9?= <442384644@qq.com> Date: Fri, 23 Dec 2022 15:49:48 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=A8=8B=E5=BA=8F=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E3=80=91=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=BF=AE=E6=94=B9=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E6=A3=80=E6=9F=A5=E9=99=90=E8=B4=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/services/order/StoreCartServices.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/crmeb/app/services/order/StoreCartServices.php b/crmeb/app/services/order/StoreCartServices.php index 4f139c623..e14c80eca 100644 --- a/crmeb/app/services/order/StoreCartServices.php +++ b/crmeb/app/services/order/StoreCartServices.php @@ -324,9 +324,27 @@ class StoreCartServices extends BaseServices if (!$id || !$number || !$uid) return false; $where = ['uid' => $uid, 'id' => $id]; $carInfo = $this->dao->getOne($where, 'product_id,combination_id,seckill_id,bargain_id,product_attr_unique,cart_num'); - /** @var StoreProductServices $StoreProduct */ - $StoreProduct = app()->make(StoreProductServices::class); - $stock = $StoreProduct->getProductStock($carInfo->product_id, $carInfo->product_attr_unique); + + //购物车修改数量检查限购 + /** @var StoreProductServices $productServices */ + $productServices = app()->make(StoreProductServices::class); + $limitInfo = $productServices->get($carInfo->product_id, ['is_limit', 'limit_type', 'limit_num']); + if ($limitInfo['is_limit']) { + if ($limitInfo['limit_type'] == 1 && $number > $limitInfo['limit_num']) { + throw new ApiException(410239, ['limit' => $limitInfo['limit_num']]); + } else if ($limitInfo['limit_type'] == 2) { + /** @var StoreOrderCartInfoServices $orderCartServices */ + $orderCartServices = app()->make(StoreOrderCartInfoServices::class); + $orderPayNum = $orderCartServices->sum(['uid' => $uid, 'product_id' => $carInfo->product_id], 'cart_num'); + $orderRefundNum = $orderCartServices->sum(['uid' => $uid, 'product_id' => $carInfo->product_id], 'refund_num'); + $orderNum = $orderPayNum - $orderRefundNum; + if (($number + $orderNum) > $limitInfo['limit_num']) { + throw new ApiException(410240, ['limit' => $limitInfo['limit_num'], 'pay_num' => $orderNum]); + } + } + } + + $stock = $productServices->getProductStock($carInfo->product_id, $carInfo->product_attr_unique); if (!$stock) throw new ApiException(410237); if ($stock < $number) throw new ApiException(410297, ['num' => $number]); if ($carInfo->cart_num == $number) return true;