增加本地商品数量减少限制
This commit is contained in:
parent
8154460c5b
commit
e1525498d4
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user