CouponManagementController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace App\Admin\Controllers\CouponManagement;
  3. use App\Admin\Actions\backstage\Coupon\CouponDetails;
  4. use App\Admin\Actions\backstage\Coupon\CouponDistribution;
  5. use App\Admin\Actions\backstage\Coupon\CouponDistributions;
  6. use App\Models\Coupon;
  7. use Encore\Admin\Controllers\AdminController;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Show;
  11. class CouponManagementController extends AdminController
  12. {
  13. /**
  14. * Title for current resource.
  15. *
  16. * @var string
  17. */
  18. protected $title = '优惠券管理';
  19. /**
  20. * Make a grid builder.
  21. *
  22. * @return Grid
  23. */
  24. protected function grid()
  25. {
  26. $grid = new Grid(new Coupon());
  27. $grid->tools(function (Grid\Tools $tools) {
  28. $tools->append(new CouponDistributions());
  29. });
  30. $grid->actions(function ($actions) {
  31. $actions->disableView();
  32. $actions->add(new CouponDetails());
  33. });
  34. $grid->column('id', __('Id'));
  35. $grid->column('name', __('劵名称'));
  36. $grid->column('title', __('劵标题'));
  37. $grid->column('icon', __('券图标'))->image('',100,100);
  38. $grid->column('type', __('类型'))->using([1=>'满减券',2=>'折扣券']);
  39. $grid->column('usable_type', __('可用类型'))->using([1=>'全部产品通用',2=>'部分产品可用']);
  40. $grid->column('money', __('满减券的优惠钱数'))->display(function ($money){
  41. return $money/100;
  42. });
  43. $grid->column('discount', __('折扣'));
  44. $grid->column('position_type', __('发放平台'))->using([1=>'领券中心',2=>'后台发放']);
  45. $grid->column('num', __('数量'));
  46. $grid->column('effective_days', __('有效天数'));
  47. $grid->column('start_time', __('有效期开始时间'))->display(function ($time){
  48. if ($time ==0)
  49. return '';
  50. return date('Y-m-d H:i:s',$time);
  51. });
  52. $grid->column('end_time', __('有效期结束时间'))->display(function ($time){
  53. if ($time ==0)
  54. return '';
  55. return date('Y-m-d H:i:s',$time);
  56. });
  57. return $grid;
  58. }
  59. /**
  60. * Make a show builder.
  61. *
  62. * @param mixed $id
  63. * @return Show
  64. */
  65. protected function detail($id)
  66. {
  67. $show = new Show(Coupon::findOrFail($id));
  68. $show->field('id', __('Id'));
  69. $show->field('name', __('Name'));
  70. $show->field('title', __('Title'));
  71. $show->field('desc', __('Desc'));
  72. $show->field('rules', __('Rules'));
  73. $show->field('icon', __('Icon'));
  74. $show->field('type', __('Type'));
  75. $show->field('usable_type', __('Usable type'));
  76. $show->field('money', __('Money'));
  77. $show->field('discount', __('Discount'));
  78. $show->field('min_consume_amount', __('Min consume amount'));
  79. $show->field('max_reduce_amount', __('Max reduce amount'));
  80. $show->field('expire_type', __('Expire type'));
  81. $show->field('effective_days', __('Effective days'));
  82. $show->field('start_time', __('Start time'));
  83. $show->field('end_time', __('End time'));
  84. $show->field('created_at', __('Created at'));
  85. $show->field('updated_at', __('Updated at'));
  86. return $show;
  87. }
  88. /**
  89. * Make a form builder.
  90. *
  91. * @return Form
  92. */
  93. protected function form()
  94. {
  95. $form = new Form(new Coupon());
  96. $form->text('name', __('优惠券名称'));
  97. $form->text('title', __('券标题'));
  98. $form->text('desc', __('使用说明'));
  99. $form->text('rules', __('使用规则'));
  100. $form->image('icon', __('券图标'))->help('图标大小48px * 48px');
  101. $form->select('type', '类型')
  102. ->options([
  103. 1 => '满减券',
  104. 2 => '折扣券',
  105. ])->when(1, function (Form $form) {
  106. $form->text('money', '满减券的优惠钱数');
  107. $form->text('min_consume_amount', '最低消费金额');
  108. })->when(2, function (Form $form) {
  109. $form->text('discount', '折扣');
  110. $form->text('max_reduce_amount', '折扣券的最大抵扣金额');
  111. });
  112. $form->select('position_type',__('发放平台'))->options([1=>'领券中心',2=>'后台发放']);
  113. $form->number('num', __('数量'));
  114. $form->select('usable_type',__('可用类型'))->options([1=>'全部产品通用',2=>'部分产品可用']);
  115. $form->select('expire_type', '过期类型')
  116. ->options([
  117. 1 => '领取N天过期',
  118. 2 => '设置固定过期时间',
  119. ])->when(1, function (Form $form) {
  120. $form->text('effective_days', __('有效天数'));
  121. })->when(2, function (Form $form) {
  122. $form->date('start_time', __('有效期开始时间'));
  123. $form->date('end_time', __('有效期结束时间'));
  124. $form->saving(function ($form){
  125. $form->start_time = strtotime($form->start_time);
  126. $form->end_time = strtotime($form->end_time);
  127. });
  128. });
  129. return $form;
  130. }
  131. }