From fb89addef4ca9961ceb98bce16f05100c19f6b50 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Tue, 21 Dec 2021 11:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=A0=E5=93=81=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Forms/SkuGift.php | 7 ++++++- app/Models/ProductGift.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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',