ShowTimeController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\show_time;
  4. use App\code;
  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 ShowTimeController
  15. * @package App\Admin\Controllers
  16. */
  17. class ShowTimeController 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(show_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('star_date', '开始日期');
  76. $grid->column('end_date', '结束日期');
  77. $grid->column('star_time', '开始时间');
  78. $grid->column('end_time', '结束时间');
  79. $grid->column('create_id', '创建者')->display(function ($value){
  80. $name = Administrator::where('id',$value)->pluck('name')->first();
  81. return $name;
  82. });
  83. $grid->column('update_id', '更新者')->display(function ($value){
  84. $name = Administrator::where('id',$value)->pluck('name')->first();
  85. return $name;
  86. });;
  87. $grid->created_at('创建时间');
  88. $grid->updated_at('修改时间');
  89. $grid->disableExport();
  90. });
  91. }
  92. /**
  93. * Make a form builder.
  94. *
  95. * @return Form
  96. */
  97. protected function form()
  98. {
  99. return Admin::form(show_time::class, function (Form $form) {
  100. $form->display('id', '序号');
  101. $form->text('number','编号')->rules('required|max:10');
  102. $form->text('name','名称')->rules('required|max:10');
  103. $form->select('type','类别')->options(function (){
  104. $name = code::where('type_id',12)->pluck('code_dsp_name_cn','id');
  105. return $name;
  106. });
  107. $form->dateRange('star_date', 'end_date', '日期范围选择');
  108. $form->timeRange('star_time', 'end_time', '时间范围选择');
  109. $form->display('update_id', '更新者')->with(function ($value){
  110. if($value){
  111. }else{
  112. $value=Admin::user()->id;
  113. }
  114. $name = Administrator::where('id',$value)->pluck('name')->first();
  115. return $name;
  116. });
  117. $form->display('create_id', '创建者')->with(function ($value){
  118. if($value){
  119. }else{
  120. $value=Admin::user()->id;
  121. }
  122. $name = Administrator::where('id',$value)->pluck('name')->first();
  123. return $name;
  124. });
  125. $form->hidden('create_id')->default(Admin::user()->id);
  126. //保存前回调
  127. $form->saving(function (Form $form) {
  128. $form->update_id =Admin::user()->id;
  129. });
  130. $form->display('created_at', '创建时间');
  131. $form->display('updated_at', '更新时间');
  132. });
  133. }
  134. }