From 1f6dcf7af7e7c42106fa5b5f5272dc6af3f9024b Mon Sep 17 00:00:00 2001 From: liangyuyan <1103300295@qq.com> Date: Mon, 19 Oct 2020 17:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8--=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E4=BF=AE=E6=94=B9=E6=B4=BB=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Grid/v3/CouponTime.php | 52 ++++++++ app/Admin/Controllers/v3/CouponController.php | 5 +- app/Admin/Forms/v3/CouponTimeForm.php | 113 ++++++++++++++++++ app/Models/v3/Coupon.php | 4 +- 4 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 app/Admin/Actions/Grid/v3/CouponTime.php create mode 100644 app/Admin/Forms/v3/CouponTimeForm.php diff --git a/app/Admin/Actions/Grid/v3/CouponTime.php b/app/Admin/Actions/Grid/v3/CouponTime.php new file mode 100644 index 0000000..638f91e --- /dev/null +++ b/app/Admin/Actions/Grid/v3/CouponTime.php @@ -0,0 +1,52 @@ +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 [ + + ]; + } +} diff --git a/app/Admin/Controllers/v3/CouponController.php b/app/Admin/Controllers/v3/CouponController.php index 87a3c62..380da47 100644 --- a/app/Admin/Controllers/v3/CouponController.php +++ b/app/Admin/Controllers/v3/CouponController.php @@ -4,6 +4,7 @@ namespace App\Admin\Controllers\v3; use App\Admin\Actions\Grid\v3\CouponForbidden; use App\Admin\Actions\Grid\v3\CouponPublish; +use App\Admin\Actions\Grid\v3\CouponTime; use App\Admin\Repositories\v3\Coupon; use Dcat\Admin\Form; use Dcat\Admin\Grid; @@ -59,6 +60,7 @@ class CouponController extends AdminController $grid->actions(function (Grid\Displayers\Actions $actions) use($grid){ if(in_array($this->status,[0,3])){ $actions->append(new CouponPublish()); + $actions->append(new CouponTime()); if($this->status == 3){ $actions->disableEdit(); } @@ -67,6 +69,7 @@ class CouponController extends AdminController $actions->disableEdit(); if($this->status == 1){ $actions->append(new CouponForbidden()); + $actions->append(new CouponTime()); } } }); @@ -137,7 +140,7 @@ class CouponController extends AdminController return $text; }); // $show->category_ids->as(function($storeTypeId){ - // $text = '全部店铺类型'; + // $text = '全部类型'; // if($storeTypeId > 0){ // $storeType = storeTypeModel::select('type_name')->find($storeTypeId)->toArray(); // $text = $storeType ? $storeType['type_name'] : $text ; diff --git a/app/Admin/Forms/v3/CouponTimeForm.php b/app/Admin/Forms/v3/CouponTimeForm.php new file mode 100644 index 0000000..0a93432 --- /dev/null +++ b/app/Admin/Forms/v3/CouponTimeForm.php @@ -0,0 +1,113 @@ +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 []; + } + +} diff --git a/app/Models/v3/Coupon.php b/app/Models/v3/Coupon.php index dcf5966..db5e89c 100644 --- a/app/Models/v3/Coupon.php +++ b/app/Models/v3/Coupon.php @@ -95,12 +95,12 @@ class Coupon extends Model public function getEndTimeTextAttribute() { - $value = $this->usable_start_time; + $value = $this->end_time; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUsableStartTimeTextAttribute() { - $value = $this->start_time; + $value = $this->usable_start_time; return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUsableEndTimeTextAttribute()