diff --git a/app/Admin/Forms/SkuGift.php b/app/Admin/Forms/SkuGift.php index f2e634b9..6ec413b9 100644 --- a/app/Admin/Forms/SkuGift.php +++ b/app/Admin/Forms/SkuGift.php @@ -42,12 +42,17 @@ class SkuGift extends Form implements LazyRenderable $delGiftIds[] = $gift['id']; } else { if (is_null($gift['id'])) { + $gift['remaining'] = $gift['limit'];//剩余数量; $giftSku[] = new ProductGift($gift); } else { $_gift = ProductGift::find($gift['id']); $_gift->gift_sku_id = $gift['gift_sku_id']; $_gift->num = $gift['num']; $_gift->limit = $gift['limit']; + $_gift->remaining = $gift['limit'] > 0 ? ($gift['limit'] - $_gift->sent) : $gift['limit']; + if ($_gift->remaining < 0) { + return $this->response()->error('无法设置限制数量小于已发数量'); + } $giftSku[] = $_gift; } } @@ -55,7 +60,7 @@ class SkuGift extends Form implements LazyRenderable $skuId = $input['sku_id']; $sku = ProductSku::findOrFail($skuId); if ($sku->verify_state == 1 || !is_null($sku->release_at)) {//如果是审核中,或者上架中,则无法修改。 - return $this->response()->error('当前商品目前无法修改赠品')->refresh(); + return $this->response()->error('当前商品目前无法修改赠品'); } try { DB::beginTransaction(); diff --git a/app/Models/ProductGift.php b/app/Models/ProductGift.php index dc445125..12b41656 100644 --- a/app/Models/ProductGift.php +++ b/app/Models/ProductGift.php @@ -12,6 +12,7 @@ class ProductGift extends Model protected $fillable = [ 'sku_id', 'gift_sku_id', + 'limit', 'num', 'sent', 'remaining',