链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.6 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\Coupon;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\Coupon as couponModel;
  9. use App\Models\CouponSetting as couponSettingModel;
  10. class CouponController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. return Grid::make(new Coupon(), function (Grid $grid) {
  20. $grid->id->sortable();
  21. $grid->title;
  22. $grid->start_time_text;
  23. $grid->end_time_text;
  24. $grid->full_amount;
  25. $grid->discounts;
  26. $grid->discount_type_text;
  27. $grid->inventory;
  28. $grid->inventory_use;
  29. $grid->active_type_text;
  30. $grid->status
  31. ->using(
  32. config('coupon.status')
  33. )
  34. ->label(
  35. config('coupon.status_label')
  36. );
  37. // $grid->usable_start_time->display(function($time){
  38. // return date('Y-m-d H:i:s',$time);
  39. // });
  40. // $grid->usable_end_time->display(function($time){
  41. // return date('Y-m-d H:i:s',$time);
  42. // });
  43. $grid->filter(function (Grid\Filter $filter) {
  44. $filter->like('name');
  45. });
  46. });
  47. }
  48. /**
  49. * Make a show builder.
  50. *
  51. * @param mixed $id
  52. *
  53. * @return Show
  54. */
  55. protected function detail($id)
  56. {
  57. return Show::make($id, new Coupon(), function (Show $show) {
  58. $show->id;
  59. $show->title;
  60. $show->introduce;
  61. $show->start_time;
  62. $show->end_time;
  63. $show->full_amount;
  64. $show->discounts;
  65. $show->is_new_user;
  66. $show->inventory;
  67. $show->inventory_use;
  68. $show->type;
  69. $show->market_id;
  70. $show->storetype_id;
  71. $show->category;
  72. $show->active_type;
  73. $show->status;
  74. $show->remark;
  75. $show->weigh;
  76. $show->usable_number;
  77. $show->usable_start_time;
  78. $show->usable_end_time;
  79. $show->discount_type;
  80. $show->created_at;
  81. $show->updated_at;
  82. });
  83. }
  84. /**
  85. * Make a form builder.
  86. *
  87. * @return Form
  88. */
  89. protected function form()
  90. {
  91. return Form::make(new Coupon(), function (Form $form) {
  92. $form->display('id');
  93. $form->text('title')->required()->maxLength(255,'最多只能输入500个字');
  94. $form->textarea('introduce')->required();
  95. $form->text('full_amount')->width(2)->required()->floatTwo();
  96. $form->text('discounts')->width(2)->required()->floatTwo();
  97. $form->radio('discount_type')->options(config('coupon.discount_type'))->default(1)->required();
  98. $form->text('inventory')->width(2)->required()->type('number')->attribute('min', 1)->default(1);
  99. $form->datetime('start_time')->width(3)->required();
  100. $form->datetime('end_time')->width(3)->required();
  101. $form->datetime('usable_start_time')->width(3)->required();
  102. $form->datetime('usable_end_time')->width(3)->required();
  103. $form->select('active_type')->width(3)->options(config('coupon.active_type'))->default(1);
  104. /* 领取方式 */
  105. $receive = couponSettingModel::select('id','value','name')->where('category')->get();
  106. $form->select('receive_type')->width(3)->options([])->default(2);
  107. $form->select('type')->width(3)->options(config('coupon.type'))->default(1)->disable();
  108. $form->select('category')->width(3)->options(config('coupon.category'))->default(1)->disable();
  109. /* 目前默认全平台的市场 2020-08-20*/
  110. $form->select('market_id')->width(3)->options(['所有市场'])->disable();
  111. /* 目前默认全平台的店铺分类 2020-08-20*/
  112. $form->select('storetype_id')->width(3)->options(['所有店铺类型'])->disable();
  113. $form->radio('is_new_user')->options(config('coupon.is_new_user'))->default(2)->disable();
  114. // $form->text('usable_number')->width(2)->default(1)->disable();
  115. $form->text('weigh')->width(2)->type('number')->attribute('min', 0)->default(0);
  116. $form->text('remark')->maxLength(500,'最多只能输入500个字');
  117. $form->display('created_at');
  118. $form->display('updated_at');
  119. });
  120. }
  121. }