123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace App\Admin\Controllers\CouponManagement;
- use App\Admin\Actions\backstage\Coupon\CouponDetails;
- use App\Admin\Actions\backstage\Coupon\CouponDistribution;
- use App\Admin\Actions\backstage\Coupon\CouponDistributions;
- use App\Models\Coupon;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- class CouponManagementController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- protected $title = '优惠券管理';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Coupon());
- $grid->tools(function (Grid\Tools $tools) {
- $tools->append(new CouponDistributions());
- });
- $grid->actions(function ($actions) {
- $actions->disableView();
- $actions->add(new CouponDetails());
- });
- $grid->column('id', __('Id'));
- $grid->column('name', __('劵名称'));
- $grid->column('title', __('劵标题'));
- $grid->column('icon', __('券图标'))->image('',100,100);
- $grid->column('type', __('类型'))->using([1=>'满减券',2=>'折扣券']);
- $grid->column('usable_type', __('可用类型'))->using([1=>'全部产品通用',2=>'部分产品可用']);
- $grid->column('money', __('满减券的优惠钱数'))->display(function ($money){
- return $money/100;
- });
- $grid->column('discount', __('折扣'));
- $grid->column('position_type', __('发放平台'))->using([1=>'领券中心',2=>'后台发放']);
- $grid->column('num', __('数量'));
- $grid->column('effective_days', __('有效天数'));
- $grid->column('start_time', __('有效期开始时间'))->display(function ($time){
- if ($time ==0)
- return '';
- return date('Y-m-d H:i:s',$time);
- });
- $grid->column('end_time', __('有效期结束时间'))->display(function ($time){
- if ($time ==0)
- return '';
- return date('Y-m-d H:i:s',$time);
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Coupon::findOrFail($id));
- $show->field('id', __('Id'));
- $show->field('name', __('Name'));
- $show->field('title', __('Title'));
- $show->field('desc', __('Desc'));
- $show->field('rules', __('Rules'));
- $show->field('icon', __('Icon'));
- $show->field('type', __('Type'));
- $show->field('usable_type', __('Usable type'));
- $show->field('money', __('Money'));
- $show->field('discount', __('Discount'));
- $show->field('min_consume_amount', __('Min consume amount'));
- $show->field('max_reduce_amount', __('Max reduce amount'));
- $show->field('expire_type', __('Expire type'));
- $show->field('effective_days', __('Effective days'));
- $show->field('start_time', __('Start time'));
- $show->field('end_time', __('End time'));
- $show->field('created_at', __('Created at'));
- $show->field('updated_at', __('Updated at'));
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new Coupon());
- $form->text('name', __('优惠券名称'));
- $form->text('title', __('券标题'));
- $form->text('desc', __('使用说明'));
- $form->text('rules', __('使用规则'));
- $form->image('icon', __('券图标'))->help('图标大小48px * 48px');
- $form->select('type', '类型')
- ->options([
- 1 => '满减券',
- 2 => '折扣券',
- ])->when(1, function (Form $form) {
- $form->text('money', '满减券的优惠钱数');
- $form->text('min_consume_amount', '最低消费金额');
- })->when(2, function (Form $form) {
- $form->text('discount', '折扣');
- $form->text('max_reduce_amount', '折扣券的最大抵扣金额');
- });
- $form->select('position_type',__('发放平台'))->options([1=>'领券中心',2=>'后台发放']);
- $form->number('num', __('数量'));
- $form->select('usable_type',__('可用类型'))->options([1=>'全部产品通用',2=>'部分产品可用']);
- $form->select('expire_type', '过期类型')
- ->options([
- 1 => '领取N天过期',
- 2 => '设置固定过期时间',
- ])->when(1, function (Form $form) {
- $form->text('effective_days', __('有效天数'));
- })->when(2, function (Form $form) {
- $form->date('start_time', __('有效期开始时间'));
- $form->date('end_time', __('有效期结束时间'));
- $form->saving(function ($form){
- $form->start_time = strtotime($form->start_time);
- $form->end_time = strtotime($form->end_time);
- });
- });
- return $form;
- }
- }
|