diff --git a/app/api/controller/order/CartController.php b/app/api/controller/order/CartController.php index f68c600a..06ad4b0d 100644 --- a/app/api/controller/order/CartController.php +++ b/app/api/controller/order/CartController.php @@ -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 {