库存限制

This commit is contained in:
liu 2024-06-11 14:35:56 +08:00
parent dba5ca3330
commit 3d55b3f505

View File

@ -7,6 +7,7 @@ use app\api\validate\CartValidate;
use app\api\controller\BaseApiController;
use app\api\lists\order\CartList;
use app\common\model\order\Cart;
use app\common\model\store_branch_product\StoreBranchProduct;
use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\NotParse()]
@ -29,6 +30,14 @@ class CartController extends BaseApiController
if ($count > 100) {
return $this->fail('购物车商品不能大于100个请先结算');
}
//数量下单判断
$stock = StoreBranchProduct::where(
['product_id'=>$params['product_id'],
'store_id'=>$params['store_id']
])->value('stock')??0;
if ($params['cart_num'] >$stock) {
return $this->fail('库存数量不足');
}
if ($result) {
$res = CartLogic::edit($params);
} else {