From 90f055abd8681d1c7fc75d4e09872ed5513aa670 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Tue, 23 Jan 2024 18:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81=E9=99=90?= =?UTF-8?q?=E8=B4=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOrderCreateRepository.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index d97078f6..a8c99c2a 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -112,6 +112,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository throw new ValidateException('活动商品限购1个'); } } + $oldProductId = $cart->product->old_product_id ?? 0; + if (in_array($oldProductId, [1, 2, 3])) { + $oldProductStock = Db::name('store_product')->where('product_id', $oldProductId)->value('stock'); + if ($oldProductStock < $cart['cart_num']) { + throw new ValidateException('商品库存不足'); + } + } if ($cart['product_type'] <= 97 && $cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) { throw new ValidateException('活动商品必须单独购买'); }