本地生活购物车添加库存校验
This commit is contained in:
parent
bdb4a46049
commit
94241c374c
@ -392,6 +392,18 @@ class LocalStoreGoodsLogic extends Logic
|
||||
}
|
||||
|
||||
$cart = LocalStoreGoodsCart::where(['user_id' => $user_id, 'lstore_id' => $post['lstore_id'], 'lsg_id' => $post['lsg_id'], 'item_id' => $post['item_id'], 'is_delete' => 0])->find();
|
||||
// 验证商品库存
|
||||
$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) {
|
||||
throw new \Exception('商品库存不足');
|
||||
}
|
||||
|
||||
if ($post['item_id'] > 0 && ($post['goods_num'] + $cart['goods_num']) > $item['stock']) {
|
||||
throw new \Exception('商品库存不足');
|
||||
}
|
||||
|
||||
if ($cart) {
|
||||
// 如果存在于购物车,就增加数量
|
||||
LocalStoreGoodsCart::where(['user_id' => $user_id, 'lstore_id' => $post['lstore_id'], 'lsg_id' => $post['lsg_id'], 'item_id' => $post['item_id'], 'is_delete' => 0])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user