4 changed files with 171 additions and 3 deletions
-
52app/Admin/Actions/Grid/v3/CouponTime.php
-
5app/Admin/Controllers/v3/CouponController.php
-
113app/Admin/Forms/v3/CouponTimeForm.php
-
4app/Models/v3/Coupon.php
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Actions\Grid\v3; |
||||
|
|
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Widgets\Modal; |
||||
|
use App\Admin\Forms\v3\CouponPublishForm; |
||||
|
use App\Admin\Forms\v3\CouponTimeForm; |
||||
|
|
||||
|
class CouponTime extends RowAction |
||||
|
{ |
||||
|
/** |
||||
|
* 修改优惠券活动时间 |
||||
|
* @return string |
||||
|
*/ |
||||
|
protected $title = ' 时间 '; |
||||
|
|
||||
|
public function render() |
||||
|
{ |
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
$modal = Modal::make() |
||||
|
->xl() |
||||
|
->title($this->title) |
||||
|
->body(CouponTimeForm::make()->setKey($id)->payload([ |
||||
|
'id'=>$this->row->id, |
||||
|
'status'=>$this->row->status, |
||||
|
'title'=>$this->row->title, |
||||
|
'start_time'=>$this->row->start_time, |
||||
|
'end_time'=>$this->row->end_time, |
||||
|
'usable_start_time'=>$this->row->usable_start_time, |
||||
|
'usable_end_time'=>$this->row->usable_end_time, |
||||
|
])) |
||||
|
->button($this->title); |
||||
|
|
||||
|
return $modal; |
||||
|
} |
||||
|
|
||||
|
// 确认弹窗信息
|
||||
|
public function confirm() |
||||
|
{ |
||||
|
return '您确定要修改时间吗?'; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
|
||||
|
return [ |
||||
|
|
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,113 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Forms\v3; |
||||
|
|
||||
|
use App\Models\v3\GoodsBanners; |
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
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 CouponTimeForm extends Form implements LazyRenderable |
||||
|
{ |
||||
|
use LazyWidget; |
||||
|
/** |
||||
|
* Handle the form request. |
||||
|
* |
||||
|
* @param array $input |
||||
|
* |
||||
|
* @return Response |
||||
|
*/ |
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
// 获取外部传递参数
|
||||
|
$id = $input['id']; |
||||
|
|
||||
|
$start_time = $input['start_time'] ?? ''; |
||||
|
$end_time = $input['end_time'] ?? ''; |
||||
|
$usable_start_time = $input['usable_start_time'] ?? ''; |
||||
|
$usable_end_time = $input['usable_end_time'] ?? ''; |
||||
|
|
||||
|
$coupon = CouponModel::find($id); |
||||
|
if(!$coupon){ |
||||
|
return $this->error('优惠券不存在或已删除!'); |
||||
|
} |
||||
|
|
||||
|
switch($coupon->status){ |
||||
|
case 0: |
||||
|
case 1: |
||||
|
case 3: |
||||
|
$coupon->start_time = $start_time; |
||||
|
$coupon->end_time = $end_time; |
||||
|
$coupon->usable_start_time = $usable_start_time; |
||||
|
$coupon->usable_end_time = $usable_end_time; |
||||
|
if($coupon->save()){ |
||||
|
return $this->success('修改成功','/coupon'); |
||||
|
} |
||||
|
break; |
||||
|
case 2: |
||||
|
return $this->error('优惠券已领完!'); |
||||
|
break; |
||||
|
case -1: |
||||
|
return $this->error('优惠券已删除!'); |
||||
|
break; |
||||
|
} |
||||
|
return $this->error('发布失败!'); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Build a form here. |
||||
|
*/ |
||||
|
public function form() |
||||
|
{ |
||||
|
$id = $this->payload['id'] ?? 0; |
||||
|
$title = $this->payload['title'] ?? ''; |
||||
|
$status = $this->payload['status'] ?? -1; |
||||
|
|
||||
|
$start_time = $this->payload['start_time'] ?? ''; |
||||
|
$end_time = $this->payload['end_time'] ?? ''; |
||||
|
$usable_start_time = $this->payload['usable_start_time'] ?? ''; |
||||
|
$usable_end_time = $this->payload['usable_end_time'] ?? ''; |
||||
|
|
||||
|
$this->hidden('id')->value($id); |
||||
|
$this->display('title','标题')->value($title); |
||||
|
|
||||
|
$this->datetime('start_time','活动开始时间')->required() |
||||
|
->customFormat(function () use($start_time){ |
||||
|
return date('Y-m-d H:i:s',$start_time); |
||||
|
}); |
||||
|
|
||||
|
$this->datetime('end_time','活动结束时间')->required() |
||||
|
->customFormat(function () use($end_time){ |
||||
|
return date('Y-m-d H:i:s',$end_time); |
||||
|
}) |
||||
|
->rules('after:start_time',[ |
||||
|
'after' => '只能选择活动开始之后的时间' |
||||
|
]); |
||||
|
$this->datetime('usable_start_time','可用开始时间')->required() |
||||
|
->customFormat(function () use($usable_start_time){ |
||||
|
return date('Y-m-d H:i:s',$usable_start_time); |
||||
|
}); |
||||
|
$this->datetime('usable_end_time','可用结束时间')->required() |
||||
|
->customFormat(function () use($usable_end_time){ |
||||
|
return date('Y-m-d H:i:s',$usable_end_time); |
||||
|
}) |
||||
|
->rules('after:end_time',[ |
||||
|
'after' => '只能选择活动结束之后的时间' |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* The data of the form. |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function default() |
||||
|
{ |
||||
|
return []; |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue