From e1525498d459ccaaf4a70dc3532e700f96c69b32 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Wed, 30 Oct 2024 17:17:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=AC=E5=9C=B0=E5=95=86?= =?UTF-8?q?=E5=93=81=E6=95=B0=E9=87=8F=E5=87=8F=E5=B0=91=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreGoodsCartLogic.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/api/logic/LocalStoreGoodsCartLogic.php b/app/api/logic/LocalStoreGoodsCartLogic.php index 0b999e4c..0f3ccbe7 100644 --- a/app/api/logic/LocalStoreGoodsCartLogic.php +++ b/app/api/logic/LocalStoreGoodsCartLogic.php @@ -102,19 +102,28 @@ class LocalStoreGoodsCartLogic extends Logic if ($cart['item_id'] == 0) { // 单规格商品 $item = LocalStoreGoods::where('id', $cart['lsg_id'])->field('price')->find(); - if ($cart['goods_num'] + $post['goods_num'] > 999) { + if ($post['type'] == 'plus' && $cart['goods_num'] + $post['goods_num'] > 999) { throw new \Exception('商品数量超出限制'); } } else { // 多规格商品 $item = LocalStoreGoodsItem::where('id', $cart['item_id'])->field('price, stock')->find(); - if ($cart['goods_num'] + $post['goods_num'] > $item['stock']) { + if ($post['type'] == 'plus' && $cart['goods_num'] + $post['goods_num'] > $item['stock']) { throw new \Exception('商品数量超出限制'); } } - $price = number_format($post['goods_num'] * $item['price'], 2, '.', ''); - $goods_num = $cart['goods_num'] + $post['goods_num']; + if ($post['type'] == 'minus') { + $goods_num = $cart['goods_num'] - $post['goods_num']; + } else { + $goods_num = $cart['goods_num'] + $post['goods_num']; + } + + if ($goods_num <= 0) { + throw new \Exception('商品数量不能小于0'); + } + + $price = number_format($goods_num * $item['price'], 2, '.', ''); LocalStoreGoodsCart::where('id', $post['cart_id'])->update([ 'goods_num' => $goods_num