|
|
|
@ -8,10 +8,12 @@ use Symfony\Component\HttpFoundation\Response; |
|
|
|
use App\Models\v3\CouponReceiveType as ReceiveTypeModel; |
|
|
|
use App\Models\v3\CouponSetting as SettingModel; |
|
|
|
use App\Models\v3\Coupon as CouponModel; |
|
|
|
use Dcat\Admin\Contracts\LazyRenderable; |
|
|
|
use Dcat\Admin\Traits\LazyWidget; |
|
|
|
|
|
|
|
class CouponPublishForm extends Form |
|
|
|
class CouponPublishForm extends Form implements LazyRenderable |
|
|
|
{ |
|
|
|
|
|
|
|
use LazyWidget; |
|
|
|
/** |
|
|
|
* Handle the form request. |
|
|
|
* |
|
|
|
@ -39,10 +41,7 @@ class CouponPublishForm extends Form |
|
|
|
return $this->error('活动时间已经接近,请重新设置!'); |
|
|
|
} |
|
|
|
|
|
|
|
$coupon->status = 1; |
|
|
|
if(!$coupon->save()){ |
|
|
|
return $this->error('发布失败!'); |
|
|
|
} |
|
|
|
if($coupon->status == 0){ |
|
|
|
// 删除领取方式
|
|
|
|
$delRes = ReceiveTypeModel::where('coupon_id',$id)->delete(); |
|
|
|
if($delRes === false){ |
|
|
|
@ -55,8 +54,13 @@ class CouponPublishForm extends Form |
|
|
|
// 获取一次可领取数量
|
|
|
|
$receiveNumber = SettingModel::getSettingInfo($receiveType,'value'); |
|
|
|
$receiveModel->one_receive_number = empty($receiveNumber) ? 1 : $receiveNumber->value; |
|
|
|
if(!$receiveModel->save()){ |
|
|
|
return $this->error('发布失败!'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if($receiveModel->save()){ |
|
|
|
$coupon->status = 1; |
|
|
|
if($coupon->save()){ |
|
|
|
return $this->success('发布成功','/coupon'); |
|
|
|
} |
|
|
|
break; |
|
|
|
@ -78,12 +82,20 @@ class CouponPublishForm extends Form |
|
|
|
*/ |
|
|
|
public function form() |
|
|
|
{ |
|
|
|
$id = $this->getKey(); |
|
|
|
$receiveTypeInfo = ReceiveTypeModel::getReceiveTypeInfo($id,'receive_type'); |
|
|
|
$id = $this->payload['id'] ?? 0; |
|
|
|
$title = $this->payload['title'] ?? ''; |
|
|
|
$status = $this->payload['status'] ?? -1; |
|
|
|
|
|
|
|
$this->hidden('id')->value($id); |
|
|
|
$this->display('title','标题')->value($title); |
|
|
|
$receiveTypeInfo = ReceiveTypeModel::getReceiveTypeOne([['coupon_id','=',$id]],'receive_type'); |
|
|
|
$list = SettingModel::getSettingArray(); |
|
|
|
$receiveType = empty($receiveTypeInfo->receive_type)? 0 :$receiveTypeInfo->receive_type; |
|
|
|
$this->hidden('id')->value($id); |
|
|
|
if($status == 0){ |
|
|
|
$this->select('receive_type','领取方式')->required()->options($list)->value($receiveType); |
|
|
|
}else{ |
|
|
|
$this->select('receive_type','领取方式')->options($list)->value($receiveType)->disable(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|