Browse Source

库存不足时 允许减操作

master
Lemon 5 years ago
parent
commit
3602e0a4b7
  1. 15
      app/Service/v3/Implementations/ShopCartUpdateService.php

15
app/Service/v3/Implementations/ShopCartUpdateService.php

@ -69,7 +69,20 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface
if($goodsCheck !== true)
{
throw new ErrorCodeException($goodsCheck);
if($goodsCheck === ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR){
$shopcartNum = ShoppingCart::query()
->where([
'user_id' => $userId,
'goods_id' => $goodsId,
'activity_type' => $activityType
])
->value('num');
if($num > $shopcartNum){
throw new ErrorCodeException($goodsCheck);
}
}else{
throw new ErrorCodeException($goodsCheck);
}
}
$shoppingCart = ShoppingCart::query()->lockForUpdate()->updateOrCreate(

Loading…
Cancel
Save