From 1bf2f7e3085fc9b4d742843bfc04a9ecf1c87ef8 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Fri, 1 Nov 2024 10:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9C=AC=E5=9C=B0=E7=94=9F?= =?UTF-8?q?=E6=B4=BB=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=80=BB=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreGoodsCartLogic.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/api/logic/LocalStoreGoodsCartLogic.php b/app/api/logic/LocalStoreGoodsCartLogic.php index 9fa2dad2..13d4a20c 100644 --- a/app/api/logic/LocalStoreGoodsCartLogic.php +++ b/app/api/logic/LocalStoreGoodsCartLogic.php @@ -99,13 +99,10 @@ class LocalStoreGoodsCartLogic extends Logic if ($post['cart_id']) { $cart = LocalStoreGoodsCart::getSelfCart($user_id, $post['cart_id']); if (!empty($cart)) { - if ($cart['item_id'] == 0) { + if ($cart['item_id'] == 0 && $post['goods_num'] > 999) { // 单规格商品 - $item = LocalStoreGoods::where('id', $cart['lsg_id'])->field('price')->find(); - if ($post['goods_num'] > 999) { - throw new \Exception('商品数量超出限制'); - } - } else { + throw new \Exception('商品数量超出限制'); + } else if ($cart['item_id'] > 0) { // 多规格商品 $item = LocalStoreGoodsItem::where('id', $cart['item_id'])->field('price, stock')->find(); if ($post['goods_num'] > $item['stock']) { @@ -117,21 +114,20 @@ class LocalStoreGoodsCartLogic extends Logic 'goods_num' => $post['goods_num'] ]); - $cart = LocalStoreGoodsCart::alias('c') + $result = LocalStoreGoodsCart::alias('c') ->join('local_store_goods g', 'c.lsg_id = g.id') - ->where(['c.user_id' => $user_id, 'c.lstore_id' => $post['lstore_id'], 'c.is_delete' => 0, 'g.state' => 1, 'g.audit_status' => 1, 'g.delete_time' => 0]) + ->where(['c.user_id' => $user_id, 'c.lstore_id' => $cart['lstore_id'], 'c.is_delete' => 0, 'g.state' => 1, 'g.audit_status' => 1, 'g.delete_time' => 0]) ->field('c.id, c.item_id, c.goods_num, g.id as lsg_id, g.title, g.price') ->append(['pic', 'item']) ->select() ->toArray(); $price = 0; - foreach ($cart as &$v) { + foreach ($result as &$v) { $price += ($v['goods_num'] * $v['price']); } - $price = number_format($price, 2, '.', ''); - + $price = number_format($price, 2, '.', ''); } else { throw new \Exception('商品信息不存在'); }