From 0e0dc81b6020c83639c4170cb20fa535437cdaa5 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Sat, 2 Nov 2024 09:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9C=E9=BE=99=E6=B1=87=E8=B6=85=E5=B8=82?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E7=94=9F=E6=B4=BB=E4=BB=B7=E6=A0=BC=E6=89=93?= =?UTF-8?q?=E6=8A=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreGoodsCartLogic.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/api/logic/LocalStoreGoodsCartLogic.php b/app/api/logic/LocalStoreGoodsCartLogic.php index 163d1f02..e8013970 100644 --- a/app/api/logic/LocalStoreGoodsCartLogic.php +++ b/app/api/logic/LocalStoreGoodsCartLogic.php @@ -7,12 +7,16 @@ use app\common\model\localstore\LocalStoreGoods; use app\common\model\localstore\LocalStoreGoodsCart; use app\common\model\localstore\LocalStoreGoodsItem; use think\Exception; +use think\facade\Config; use think\facade\Db; class LocalStoreGoodsCartLogic extends Logic { + private static $normal_goods_stock = 999; + public static function addCart($post, $user_id) { + // TODO 东龙汇超市商品需要计算8折价格 Db::startTrans(); try { // 验证商品 @@ -26,7 +30,7 @@ class LocalStoreGoodsCartLogic extends Logic $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) { + if ($post['item_id'] == 0 && $post['goods_num'] > self::$normal_goods_stock) { throw new \Exception('商品库存不足'); } @@ -87,7 +91,7 @@ class LocalStoreGoodsCartLogic extends Logic if ($post['cart_id']) { $cart = LocalStoreGoodsCart::getSelfCart($user_id, $post['cart_id']); if (!empty($cart)) { - if ($cart['item_id'] == 0 && $post['goods_num'] > 999) { + if ($cart['item_id'] == 0 && $post['goods_num'] > self::$normal_goods_stock) { // 单规格商品 throw new \Exception('商品数量超出限制'); } else if ($cart['item_id'] > 0) { @@ -177,9 +181,16 @@ class LocalStoreGoodsCartLogic extends Logic $goods_num += $v['goods_num']; } + if ($lstore_id == Config::get('localstore.dlh_lstore_id')) { + foreach ($cart as $k => &$v) { + $cart[$k]['original_price'] = $v['price']; + $v['price'] = number_format($v['price'] * LocalStoreGoodsLogic::$sale, 2, '.', ''); + } + } + return [ 'cart' => $cart, - 'total_amount' => $total_amount, // 购物车商品总价 + 'total_amount' => number_format($total_amount, 2, '.', ''), // 购物车商品总价 'goods_num' => $goods_num // 购物车商品总数 ]; }