diff --git a/app/Admin/Controllers/v3/CouponController.php b/app/Admin/Controllers/v3/CouponController.php index 029a03a..659795b 100644 --- a/app/Admin/Controllers/v3/CouponController.php +++ b/app/Admin/Controllers/v3/CouponController.php @@ -16,8 +16,6 @@ use App\Models\v3\Market as MarketModel; use App\Models\v3\Category as CategoryModel; use Dcat\Admin\Form\NestedForm; -use function GuzzleHttp\json_decode; - class CouponController extends AdminController { protected $receive_type = 0; @@ -28,9 +26,6 @@ class CouponController extends AdminController */ protected function grid() { - // $model = new CouponModel(); - // $list = $model->setAppends([])->select('id','title')->get(); - // dd($list->toArray()); return Grid::make(new Coupon(), function (Grid $grid) { $grid->id->sortable(); $grid->title; @@ -47,7 +42,7 @@ class CouponController extends AdminController $grid->active_type_text; $grid->status ->using( - CouponModel::$_STATUS + CouponModel::$status ) ->label( config('label.status_label') @@ -76,9 +71,9 @@ class CouponController extends AdminController }); $grid->disableBatchDelete(); - $grid->disableCreateButton(); + // $grid->disableCreateButton(); $grid->disableDeleteButton(); - $grid->disableEditButton(); + // $grid->disableEditButton(); }); } @@ -90,9 +85,10 @@ class CouponController extends AdminController * @return Show */ protected function detail($id) - { - return Show::make($id, new Coupon(), function (Show $show) use($id){ - // $show->id; + { + $builder = CouponModel::with('receiveType'); + return Show::make($id, $builder, function (Show $show) use($id){ + $show->id; $show->title; $show->introduce; $show->full_amount; @@ -107,10 +103,17 @@ class CouponController extends AdminController $show->usable_end_time_text; $show->active_type_text; - $show->receive_type_text; + $show->column('receive_type.receive_type','')->as(function($receiveTypeId) use($show){ + $text = ''; + if($receiveTypeId > 0){ + $receiveTypeName = SettingModel::getSettingInfo($receiveTypeId,'name'); + $text = $receiveTypeName ? $receiveTypeName : $text; + } + return $text; + }); $show->type_text; $show->category_text; - $show->market_id->as(function($marketId){ + $show->market_ids->as(function($marketId){ $text = '全部市场'; if($marketId > 0){ $market = marketModel::select('name')->find($marketId)->toArray(); @@ -118,14 +121,14 @@ class CouponController extends AdminController } return $text; }); - $show->storetype_id->as(function($storeTypeId){ - $text = '全部店铺类型'; - if($storeTypeId > 0){ - $storeType = storeTypeModel::select('type_name')->find($storeTypeId)->toArray(); - $text = $storeType ? $storeType['type_name'] : $text ; - } - return $text; - }); + // $show->category_ids->as(function($storeTypeId){ + // $text = '全部店铺类型'; + // if($storeTypeId > 0){ + // $storeType = storeTypeModel::select('type_name')->find($storeTypeId)->toArray(); + // $text = $storeType ? $storeType['type_name'] : $text ; + // } + // return $text; + // }); $show->is_new_user_text; $show->usable_number; @@ -152,25 +155,44 @@ class CouponController extends AdminController $form->textarea('introduce')->required(); $form->currency('full_amount')->required()->symbol('¥'); $form->currency('discounts')->required()->symbol('¥'); - $form->radio('discount_type')->options(CouponModel::$_DISCOUNTTYPE)->default(1); + $form->radio('discount_type')->options(CouponModel::$discountType)->default(1); $form->number('inventory')->required()->type('number')->attribute('min', 1)->default(1); $form->number('weigh')->type('number')->attribute('min', 0)->default(0); - $form->hidden('is_new_user')->options(CouponModel::$_ISNEWUSER)->default(2); + $form->hidden('is_new_user')->options(CouponModel::$isNewUser)->default(2); }); $form->column(6,function(Form $form) { - $form->select('active_type')->required()->options(CouponModel::$_ACTIVETYPE)->default(1); - - $form->datetimeRange('start_time','end_time','活动时间')->required(); - // ->rules('after:now',[ - // 'after' => '只能选择今天和之后的时间' - // ]); - $form->datetimeRange('usable_start_time','usable_end_time','可用时间')->required()->rules('after:start_time',[ - 'after' => '可用时间必须比活动开始时间晚' - ]); + $receiveTypes = SettingModel::getSettingArray(); + $form->select('active_type')->required()->options(CouponModel::$activeType)->default(1); + // $form->select('receive_type.receive_type','领取方式')->required()->options($receiveTypes)->default(2); + $form->datetime('start_time')->required() + ->customFormat(function ($start_time){ + return date('Y-m-d H:i:s',$start_time); + }) + ->rules('after:now',[ + 'after' => '只能选择今天和之后的时间' + ]); + $form->datetime('end_time')->required() + ->customFormat(function ($start_time){ + return date('Y-m-d H:i:s',$start_time); + }) + ->rules('after:start_time',[ + 'after' => '只能选择活动开始之后的时间' + ]); + $form->datetime('usable_start_time')->required() + ->customFormat(function ($start_time){ + return date('Y-m-d H:i:s',$start_time); + }); + $form->datetime('usable_end_time')->required() + ->customFormat(function ($start_time){ + return date('Y-m-d H:i:s',$start_time); + }) + ->rules('after:end_time',[ + 'after' => '只能选择活动结束之后的时间' + ]); // $form->select('type')->options(CouponModel::$_TYPE)->default(1)->disable(); - // $form->select('category')->options(CouponModel::$_CATEGORY)->default(1)->disable(); + /* 默认全平台的市场 */ $marketList = MarketModel::getMarketArray(); $form->multipleSelect('market_ids')->options($marketList)->help('不选默认所有市场可用'); @@ -180,7 +202,7 @@ class CouponController extends AdminController }); $form->column(12,function(Form $form){ - $form->tags('activity_available','可用活动')->options(CouponModel::$_ACTIVITY_AVAILABLE); + $form->tags('activity_available','可用活动')->options(CouponModel::$activityAvailable); $form->tags('tags','标签')->options(['新人专享','满39减10','满19减5']); $form->text('remark')->maxLength(500,'最多只能输入500个字')->default(''); }); diff --git a/app/Admin/Controllers/v3/CouponSettingController.php b/app/Admin/Controllers/v3/CouponSettingController.php index 912d37d..19eeb5e 100644 --- a/app/Admin/Controllers/v3/CouponSettingController.php +++ b/app/Admin/Controllers/v3/CouponSettingController.php @@ -70,7 +70,7 @@ class CouponSettingController extends AdminController { return Form::make(new CouponSetting(), function (Form $form) { $form->hidden('id'); - $form->select('category')->width(6)->options(SettingModel::$_CATEGORY); + $form->select('category')->width(6)->options(SettingModel::$category); $form->text('name')->width(6)->required()->maxLength(50); $form->number('value')->required()->rules('min:1')->default(1); diff --git a/app/Admin/Forms/v3/CouponPublishForm.php b/app/Admin/Forms/v3/CouponPublishForm.php index e069cfd..668d64b 100644 --- a/app/Admin/Forms/v3/CouponPublishForm.php +++ b/app/Admin/Forms/v3/CouponPublishForm.php @@ -33,7 +33,11 @@ class CouponPublishForm extends Form switch($coupon->status){ case 0: case 3: - // 判断活动时间 还未判断 + $time = time(); + // 判断活动时间 + if($coupon->end_time <= $time + SettingModel::$publishTime){ + return $this->error('活动时间已经接近,请重新设置!'); + } $coupon->status = 1; if(!$coupon->save()){ diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 5738177..f9b0866 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -88,6 +88,5 @@ Route::group([ // 订单统计 $router->resource('/order_report', 'v3\OrderReportController'); - // $router->any('/order_report', 'v3\OrderReportController@index'); }); diff --git a/app/Models/v3/Coupon.php b/app/Models/v3/Coupon.php index bd2d58a..785c961 100644 --- a/app/Models/v3/Coupon.php +++ b/app/Models/v3/Coupon.php @@ -19,13 +19,13 @@ class Coupon extends Model /* 查询记录数 limit */ protected $perPage = 10; - public static $_ACTIVITY_AVAILABLE = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品']; - public static $_CATEGORY = [1=>'订单']; - public static $_TYPE = [1=>'全平台',2=>'线上', 3=>'线下']; - public static $_ISNEWUSER = [1=>'是',2=>'否']; - public static $_DISCOUNTTYPE = [1=>'金额',2=>'打折(%)']; - public static $_ACTIVETYPE = [1=>'领取活动',2=>'转发活动',3=>'返券专用']; - public static $_STATUS = [ -1=> '已删除', 0=>'草稿', 1=>'正常',2=>'已领完',3=>'禁用']; + public static $activityAvailable = ['flash_sale'=>'秒杀','group_buy'=>'团购','new_product'=>'新品']; + public static $category = [1=>'订单']; + public static $type = [1=>'全平台',2=>'线上', 3=>'线下']; + public static $isNewUser = [1=>'是',2=>'否']; + public static $discountType = [1=>'金额',2=>'打折(%)']; + public static $activeType = [1=>'领取活动',2=>'转发活动',3=>'返券专用']; + public static $status = [ -1=> '已删除', 0=>'草稿', 1=>'正常',2=>'已领完',3=>'禁用']; /* 添加转换字段 */ protected $appends = [ @@ -54,32 +54,32 @@ class Coupon extends Model public function getStatusTextAttribute() { $value = $this->status; - return isset(self::$_STATUS[$value])?self::$_STATUS[$value]:''; + return isset(self::$status[$value])?self::$status[$value]:''; } public function getTypeTextAttribute() { $value = $this->type; - return isset(self::$_TYPE[$value])?self::$_TYPE[$value]:''; + return isset(self::$type[$value])?self::$type[$value]:''; } public function getCategoryTextAttribute() { $value = $this->category; - return isset(self::$_CATEGORY[$value])?self::$_CATEGORY[$value]:''; + return isset(self::$category[$value])?self::$category[$value]:''; } public function getIsNewUserTextAttribute() { $value = $this->is_new_user; - return isset(self::$_ISNEWUSER[$value])?self::$_ISNEWUSER[$value]:''; + return isset(self::$isNewUser[$value])?self::$isNewUser[$value]:''; } public function getDiscountTypeTextAttribute() { $value = $this->discount_type; - return isset(self::$_DISCOUNTTYPE[$value])?self::$_DISCOUNTTYPE[$value]:''; + return isset(self::$discountType[$value])?self::$discountType[$value]:''; } public function getActiveTypeTextAttribute() { $value = $this->active_type; - return isset(self::$_ACTIVETYPE[$value])?self::$_ACTIVETYPE[$value]:''; + return isset(self::$activeType[$value])?self::$activeType[$value]:''; } public function getActivityAvailableTextAttribute() { @@ -119,12 +119,13 @@ class Coupon extends Model return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } - public function getReceiveTypeTextAttribute() + public static function getReceiveTypeText($id) { - $id = $this->getKey(); - $receive = SettingModel::where('receive_type.system_coupon_user_id',$id) - ->join('ims_system_coupon_user_receivetype as receive_type','receive_type.receive_type','ims_system_coupon_setting.id','inner') - ->first('name'); + // $id = $this->getKey(); + // $receive = SettingModel::where('receive_type.coupon_id',$id) + // ->join('lanzu_coupon_receive_type as receive_type','receive_type.receive_type','lanzu_coupon_setting.id','inner') + // ->first('name'); + $receive = SettingModel::getSettingInfo($id,'name'); return $receive ? $receive['name'] : ''; } diff --git a/app/Models/v3/CouponSetting.php b/app/Models/v3/CouponSetting.php index 83528ab..44a43d8 100644 --- a/app/Models/v3/CouponSetting.php +++ b/app/Models/v3/CouponSetting.php @@ -11,8 +11,9 @@ class CouponSetting extends Model protected $table = 'lanzu_coupon_setting'; protected $dateFormat = 'U'; - public static $_CATEGORY = [1=>'领取方式']; - public static $_STATUS = ['禁用','正常']; + public static $publishTime = 3600;// 发布优惠券时,优惠券的结束时间至少比当前时间多一个小时 + public static $category = [1=>'领取方式']; + public static $status = ['禁用','正常']; protected $appends = [ 'category_text', @@ -22,12 +23,12 @@ class CouponSetting extends Model public function getCategoryTextAttribute($value) { $value = $value ? $value : $this->category; - return isset(self::$_CATEGORY[$value]) ? self::$_CATEGORY[$value] : ''; + return isset(self::$category[$value]) ? self::$category[$value] : ''; } public function getStatusTextAttribute($value) { $value = $value ? $value : $this->status; - return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : ''; + return isset(self::$status[$value]) ? self::$status[$value] : ''; } /**