7 changed files with 387 additions and 25 deletions
-
134app/Admin/Controllers/CouponController.php
-
18app/Admin/Repositories/Coupon.php
-
2app/Admin/routes.php
-
97app/Models/Coupon.php
-
55config/coupon.php
-
64dcat_admin_ide_helper.php
-
42resources/lang/zh-CN/coupon.php
@ -0,0 +1,134 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers; |
|||
|
|||
use App\Admin\Repositories\Coupon; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Controllers\AdminController; |
|||
use App\Models\Coupon as couponModel; |
|||
|
|||
class CouponController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make($c = new Coupon(), function (Grid $grid) { |
|||
$grid->id->sortable(); |
|||
$grid->title; |
|||
$grid->start_time->display(function($time){ |
|||
return date('Y-m-d H:i:s',$time); |
|||
}); |
|||
$grid->end_time->display(function($time){ |
|||
return date('Y-m-d H:i:s',$time); |
|||
}); |
|||
|
|||
$grid->full_amount; |
|||
$grid->discounts; |
|||
$grid->discount_type; |
|||
|
|||
$grid->inventory; |
|||
$grid->inventory_use; |
|||
$grid->type; |
|||
$grid->active_type; |
|||
|
|||
$grid->status |
|||
->using( |
|||
config('coupon.status') |
|||
) |
|||
->label( |
|||
config('coupon.status_label') |
|||
); |
|||
|
|||
// $grid->usable_start_time->display(function($time){
|
|||
// return date('Y-m-d H:i:s',$time);
|
|||
// });
|
|||
// $grid->usable_end_time->display(function($time){
|
|||
// return date('Y-m-d H:i:s',$time);
|
|||
// });
|
|||
|
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->like('name'); |
|||
|
|||
}); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a show builder. |
|||
* |
|||
* @param mixed $id |
|||
* |
|||
* @return Show |
|||
*/ |
|||
protected function detail($id) |
|||
{ |
|||
return Show::make($id, new Coupon(), function (Show $show) { |
|||
$show->id; |
|||
$show->title; |
|||
$show->introduce; |
|||
$show->start_time; |
|||
$show->end_time; |
|||
$show->full_amount; |
|||
$show->discounts; |
|||
$show->is_new_user; |
|||
$show->inventory; |
|||
$show->inventory_use; |
|||
$show->type; |
|||
$show->market_id; |
|||
$show->storetype_id; |
|||
$show->category; |
|||
$show->active_type; |
|||
$show->status; |
|||
$show->remark; |
|||
$show->weigh; |
|||
$show->usable_number; |
|||
$show->usable_start_time; |
|||
$show->usable_end_time; |
|||
$show->discount_type; |
|||
$show->created_at; |
|||
$show->updated_at; |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Make a form builder. |
|||
* |
|||
* @return Form |
|||
*/ |
|||
protected function form() |
|||
{ |
|||
return Form::make(new Coupon(), function (Form $form) { |
|||
$form->display('id'); |
|||
$form->text('title'); |
|||
$form->text('introduce'); |
|||
$form->text('start_time'); |
|||
$form->text('end_time'); |
|||
$form->text('full_amount'); |
|||
$form->text('discounts'); |
|||
$form->text('is_new_user'); |
|||
$form->text('inventory'); |
|||
$form->text('inventory_use'); |
|||
$form->text('type'); |
|||
$form->text('market_id'); |
|||
$form->text('storetype_id'); |
|||
$form->text('category'); |
|||
$form->text('active_type'); |
|||
$form->text('status'); |
|||
$form->text('remark'); |
|||
$form->text('weigh'); |
|||
$form->text('usable_number'); |
|||
$form->text('usable_start_time'); |
|||
$form->text('usable_end_time'); |
|||
$form->text('discount_type'); |
|||
|
|||
$form->display('created_at'); |
|||
$form->display('updated_at'); |
|||
}); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Repositories; |
|||
|
|||
use App\Models\Coupon as Model; |
|||
use Dcat\Admin\Grid\Model as GridModel; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class Coupon extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
|
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Dcat\Admin\Traits\HasDateTimeFormatter; |
|||
use Illuminate\Database\Eloquent\SoftDeletes; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class Coupon extends Model |
|||
{ |
|||
use HasDateTimeFormatter; |
|||
use SoftDeletes; |
|||
|
|||
protected $table = 'ims_system_coupon_user'; |
|||
|
|||
public function getStatusTextAttribute($value) |
|||
{ |
|||
return isset(config('coupon.status')[$value])?config('coupon.status')[$value]:''; |
|||
} |
|||
public function getTypeTextAttribute($value) |
|||
{ |
|||
return isset(config('coupon.type')[$value])?config('coupon.type')[$value]:''; |
|||
} |
|||
public function getCategoryTextAttribute($value) |
|||
{ |
|||
return isset(config('coupon.category')[$value])?config('coupon.category')[$value]:''; |
|||
} |
|||
public function getIsNewUserTextAttribute($value) |
|||
{ |
|||
return isset(config('coupon.is_new_user')[$value])?config('coupon.is_new_user')[$value]:''; |
|||
} |
|||
public function getDiscountTypeTextAttribute($value) |
|||
{ |
|||
return isset(config('coupon.discount_type')[$value])?config('coupon.discount_type')[$value]:''; |
|||
} |
|||
public function getActiveTypeTextAttribute($value) |
|||
{ |
|||
return isset(config('coupon.active_type')[$value])?config('coupon.active_type')[$value]:''; |
|||
} |
|||
public function getStartTimeTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : ''; |
|||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; |
|||
} |
|||
|
|||
public function getEndTimeTextAttribute($value) |
|||
{ |
|||
$value = $value ? $value : ''; |
|||
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; |
|||
} |
|||
|
|||
// 转换
|
|||
public function getTypeAttribute($value) |
|||
{ |
|||
return isset(config('coupon.type')[$value])?config('coupon.type')[$value]:''; |
|||
} |
|||
public function getDiscountTypeAttribute($value) |
|||
{ |
|||
return isset(config('coupon.discount_type')[$value])?config('coupon.discount_type')[$value]:''; |
|||
} |
|||
public function getActiveTypeAttribute($value) |
|||
{ |
|||
return isset(config('coupon.active_type')[$value])?config('coupon.active_type')[$value]:''; |
|||
} |
|||
// public function getStartTimeAttribute($value)
|
|||
// {
|
|||
// $value = $value ? $value : '';
|
|||
// return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
|||
// }
|
|||
|
|||
// 设置
|
|||
protected function setStartTimeAttribute($value) |
|||
{ |
|||
return $value === '' ? null : strtotime($value); |
|||
} |
|||
|
|||
protected function setEndTimeAttribute($value) |
|||
{ |
|||
return $value === '' ? null : strtotime($value); |
|||
} |
|||
|
|||
protected function setUsableStarttimeAttribute($value) |
|||
{ |
|||
return $value === '' ? null : strtotime($value); |
|||
} |
|||
|
|||
protected function setUsableEndTimeAttribute($value) |
|||
{ |
|||
return $value === '' ? null : strtotime($value); |
|||
} |
|||
|
|||
protected function setAddtimeAttribute($value) |
|||
{ |
|||
return $value === '' ? null : strtotime($value); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
<?php |
|||
|
|||
return [ |
|||
//优惠卷(用户)状态
|
|||
'status'=>[ |
|||
-1=> '已删除', |
|||
0=>'草稿', |
|||
1=>'正常', |
|||
2=>'已用完', |
|||
3=>'禁用', |
|||
], |
|||
'status_label'=>[ |
|||
'default' => 'primary', |
|||
0 => 'info', |
|||
1 => 'success', |
|||
2 => 'warning', |
|||
3 => 'danger', |
|||
-1=> 'danger' |
|||
], |
|||
//优惠卷 - 类型 type
|
|||
'type'=>[ |
|||
1=>'全平台', |
|||
2=>'线上', |
|||
3=>'线下', |
|||
], |
|||
//优惠卷 - 分类 category
|
|||
'category'=>[ |
|||
1=>'订单' |
|||
], |
|||
//优惠卷 - 是否新用户
|
|||
'is_new_user'=>[ |
|||
1=>'是', |
|||
2=>'否', |
|||
], |
|||
//优惠卷 - 发布优惠卷时,间隔最少时间
|
|||
'interval_time_min'=>3600, |
|||
//优惠卷 - 设置
|
|||
'setting_category'=>[ |
|||
1=>[ |
|||
'name' => '领取类型', |
|||
'active' => true |
|||
], |
|||
], |
|||
//优惠卷 - 折扣类型
|
|||
'discount_type'=>[ |
|||
1=>'金额', |
|||
2=>'打折(%)', |
|||
], |
|||
//优惠卷 - 活动类型 active_type
|
|||
'active_type'=>[ |
|||
1=>'领取活动', |
|||
2=>'转发活动', |
|||
3=>'返券专用' |
|||
] |
|||
]; |
|||
@ -0,0 +1,42 @@ |
|||
<?php |
|||
return [ |
|||
'labels' => [ |
|||
'Coupon' => '优惠券管理', |
|||
'coupon' => '优惠券管理', |
|||
], |
|||
'fields' => [ |
|||
'title' => '标题', |
|||
'introduce' => '介绍', |
|||
'start_time' => '活动开始时间', |
|||
'end_time' => '活动结束时间', |
|||
'start_time_text' => '活动开始时间', |
|||
'end_time_text' => '活动结束时间', |
|||
'full_amount' => '满金额', |
|||
'discounts' => '优惠金额', |
|||
'is_new_user' => '是否新用户', |
|||
'is_new_user_text' => '是否新用户', |
|||
'inventory' => '发放数量', |
|||
'inventory_use' => '已领取数量', |
|||
'type' => '类型', |
|||
'type_text' => '类型', |
|||
'market_id' => '市场', |
|||
'storetype_id' => '店铺类型', |
|||
'category' => '分类', |
|||
'category_text' => '分类', |
|||
'active_type' => '优惠券活动类型', |
|||
'active_type_text' => '优惠券活动类型', |
|||
'status' => '状态', |
|||
'status_text' => '状态', |
|||
'remark' => '备注', |
|||
'weigh' => '排序', |
|||
'usable_number' => '用户一次可使用数量', |
|||
'usable_start_time' => '可用开始时间', |
|||
'usable_end_time' => '可用结束时间', |
|||
'discount_type' => '优惠类型', |
|||
'usable_start_time_text' => '可用开始时间', |
|||
'usable_end_time_text' => '可用结束时间', |
|||
'discount_type_text' => '优惠类型', |
|||
], |
|||
'options' => [ |
|||
], |
|||
]; |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue