From 94241c374cb615131478e6e97bd7f85dbef782b9 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Mon, 28 Oct 2024 17:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=94=9F=E6=B4=BB=E8=B4=AD?= =?UTF-8?q?=E7=89=A9=E8=BD=A6=E6=B7=BB=E5=8A=A0=E5=BA=93=E5=AD=98=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreGoodsLogic.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/api/logic/LocalStoreGoodsLogic.php b/app/api/logic/LocalStoreGoodsLogic.php index 8bd5b172..41b692f5 100644 --- a/app/api/logic/LocalStoreGoodsLogic.php +++ b/app/api/logic/LocalStoreGoodsLogic.php @@ -392,6 +392,18 @@ class LocalStoreGoodsLogic extends Logic } $cart = LocalStoreGoodsCart::where(['user_id' => $user_id, 'lstore_id' => $post['lstore_id'], 'lsg_id' => $post['lsg_id'], 'item_id' => $post['item_id'], 'is_delete' => 0])->find(); + // 验证商品库存 + $item = LocalStoreGoodsItem::where(['lstore_id' => $post['lstore_id'], 'goods_id' => $post['lsg_id']])->field('stock')->find(); + + // 普通商品 + if ($post['item_id'] == 0 && $post['goods_num'] > 999) { + throw new \Exception('商品库存不足'); + } + + if ($post['item_id'] > 0 && ($post['goods_num'] + $cart['goods_num']) > $item['stock']) { + throw new \Exception('商品库存不足'); + } + if ($cart) { // 如果存在于购物车,就增加数量 LocalStoreGoodsCart::where(['user_id' => $user_id, 'lstore_id' => $post['lstore_id'], 'lsg_id' => $post['lsg_id'], 'item_id' => $post['item_id'], 'is_delete' => 0])