ServiceTimeController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\code;
  4. use App\service_time;
  5. use Encore\Admin\Auth\Database\Administrator;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Facades\Admin;
  9. use Encore\Admin\Layout\Content;
  10. use App\Http\Controllers\Controller;
  11. use Encore\Admin\Controllers\ModelForm;
  12. /**
  13. * 运营时间管理
  14. * Class ServiceTimeController
  15. * @package App\Admin\Controllers
  16. */
  17. class ServiceTimeController extends Controller
  18. {
  19. use ModelForm;
  20. /**
  21. * Index interface.
  22. *
  23. * @return Content
  24. */
  25. public function index()
  26. {
  27. return Admin::content(function (Content $content) {
  28. $content->header('运营时间管理');
  29. $content->description('列表');
  30. $content->body($this->grid());
  31. });
  32. }
  33. /**
  34. * Edit interface.
  35. *
  36. * @param $id
  37. * @return Content
  38. */
  39. public function edit($id)
  40. {
  41. return Admin::content(function (Content $content) use ($id) {
  42. $content->header('运营时间管理');
  43. $content->description('编辑');
  44. $content->body($this->form()->edit($id));
  45. });
  46. }
  47. /**
  48. * Create interface.
  49. *
  50. * @return Content
  51. */
  52. public function create()
  53. {
  54. return Admin::content(function (Content $content) {
  55. $content->header('运营时间管理');
  56. $content->description('新增');
  57. $content->body($this->form());
  58. });
  59. }
  60. /**
  61. * Make a grid builder.
  62. *
  63. * @return Grid
  64. */
  65. protected function grid()
  66. {
  67. return Admin::grid(service_time::class, function (Grid $grid) {
  68. $grid->id('序号')->sortable();
  69. $grid->column('number', '编号');
  70. $grid->column('name', '名称');
  71. $grid->column('type', '类别')->display(function ($value){
  72. $name = code::where('id',$value)->pluck('code_dsp_name_cn')->first();
  73. return $name;
  74. });
  75. $grid->column('priority', '优先级')->display(function ($value){
  76. $name = code::where('id',$value)->pluck('code_dsp_name_cn')->first();
  77. return $name;
  78. });
  79. $grid->column('star_date', '开始日期');
  80. $grid->column('end_date', '结束日期');
  81. $grid->column('star_time', '开始时间');
  82. $grid->column('end_time', '结束时间');
  83. $grid->column('create_id', '创建者')->display(function ($value){
  84. $name = Administrator::where('id',$value)->pluck('name')->first();
  85. return $name;
  86. });
  87. $grid->column('update_id', '更新者')->display(function ($value){
  88. $name = Administrator::where('id',$value)->pluck('name')->first();
  89. return $name;
  90. });;
  91. $grid->created_at('创建时间');
  92. $grid->updated_at('修改时间');
  93. $grid->disableExport();
  94. });
  95. }
  96. /**
  97. * Make a form builder.
  98. *
  99. * @return Form
  100. */
  101. protected function form()
  102. {
  103. return Admin::form(service_time::class, function (Form $form) {
  104. $form->display('id', '序号');
  105. $form->text('number','编号')->rules('required|max:10');
  106. $form->text('name','名称')->rules('required|max:10');
  107. $form->select('type','类别')->options(function (){
  108. $name = code::where('type_id',14)->pluck('code_dsp_name_cn','id');
  109. return $name;
  110. });
  111. //优先级查询
  112. $form->select('priority','优先级')->options(function (){
  113. $name = code::where('type_id',13)->pluck('code_dsp_name_cn','id');
  114. return $name;
  115. });
  116. $form->dateRange('star_date', 'end_date', '日期范围选择');
  117. $form->timeRange('star_time', 'end_time', '时间范围选择');
  118. $form->display('update_id', '更新者')->with(function ($value){
  119. if($value){
  120. }else{
  121. $value=Admin::user()->id;
  122. }
  123. $name = Administrator::where('id',$value)->pluck('name')->first();
  124. return $name;
  125. });
  126. $form->display('create_id', '创建者')->with(function ($value){
  127. if($value){
  128. }else{
  129. $value=Admin::user()->id;
  130. }
  131. $name = Administrator::where('id',$value)->pluck('name')->first();
  132. return $name;
  133. });
  134. $form->hidden('create_id')->default(Admin::user()->id);
  135. //保存前回调
  136. $form->saving(function (Form $form) {
  137. $form->update_id =Admin::user()->id;
  138. });
  139. $form->display('created_at', '创建时间');
  140. $form->display('updated_at', '更新时间');
  141. });
  142. }
  143. }