From c76d59ad79dd9588b8d4dab190b1d92057789779 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Wed, 30 Oct 2024 17:21:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=AC=E5=9C=B0=E7=94=9F?= =?UTF-8?q?=E6=B4=BB=E8=B4=AD=E7=89=A9=E8=BD=A6=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreGoodsCartLogic.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/app/api/logic/LocalStoreGoodsCartLogic.php b/app/api/logic/LocalStoreGoodsCartLogic.php index 0f3ccbe7..1606edfc 100644 --- a/app/api/logic/LocalStoreGoodsCartLogic.php +++ b/app/api/logic/LocalStoreGoodsCartLogic.php @@ -102,31 +102,21 @@ class LocalStoreGoodsCartLogic extends Logic if ($cart['item_id'] == 0) { // 单规格商品 $item = LocalStoreGoods::where('id', $cart['lsg_id'])->field('price')->find(); - if ($post['type'] == 'plus' && $cart['goods_num'] + $post['goods_num'] > 999) { + if ($post['goods_num'] > 999) { throw new \Exception('商品数量超出限制'); } } else { // 多规格商品 $item = LocalStoreGoodsItem::where('id', $cart['item_id'])->field('price, stock')->find(); - if ($post['type'] == 'plus' && $cart['goods_num'] + $post['goods_num'] > $item['stock']) { + if ($post['goods_num'] > $item['stock']) { throw new \Exception('商品数量超出限制'); } } - 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, '.', ''); + $price = number_format($post['goods_num'] * $item['price'], 2, '.', ''); LocalStoreGoodsCart::where('id', $post['cart_id'])->update([ - 'goods_num' => $goods_num + 'goods_num' => $post['goods_num'] ]); } else {