东龙汇超市本地生活价格打折

This commit is contained in:
wangxiaowei 2024-11-02 09:21:09 +08:00
parent 7a77a1472e
commit 0e0dc81b60

@ -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 // 购物车商品总数
];
}