HotSpotController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\hot_spot;
  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 HotSpotController
  15. * @package App\Admin\Controllers
  16. */
  17. class HotSpotController 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(hot_spot::class, function (Grid $grid) {
  68. $grid->id('序号')->sortable();
  69. $grid->open_status('开放状态')->switch([
  70. 'on' => ['value' => 1, 'text' => '开放', 'color' => 'success'],
  71. 'off' => ['value' => 0, 'text' => '未开放', 'color' => 'default'],
  72. ]);
  73. $grid->column('number', '编号');
  74. $grid->column('name', '名称');
  75. $grid->column('address', '位置');
  76. $grid->column('type', '类别')->display(function ($value){
  77. if($value==1){
  78. $name="<span class='label bg-yellow'>饭店自动</span>";
  79. }elseif($value==2){
  80. $name="<span class='label bg-yellow'>商铺自动</span>";
  81. }else{
  82. $name="<span class='label bg-yellow'>手动添加</span>";
  83. }
  84. return $name;
  85. });
  86. $grid->column('开放日期')->display(function () {
  87. return $this->star_date . '-' . $this->end_date;
  88. });
  89. $grid->column('开放时间')->display(function () {
  90. return $this->star_time . '-' . $this->end_time;
  91. });
  92. $grid->created_at('创建时间');
  93. $grid->updated_at('修改时间');
  94. });
  95. }
  96. /**
  97. * Make a form builder.
  98. *
  99. * @return Form
  100. */
  101. protected function form()
  102. {
  103. return Admin::form(hot_spot::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->text('address','位置')->rules('required|max:30');
  108. $form->dateRange('star_date', 'end_date', '选择日期范围');
  109. $form->timeRange('star_time', 'end_time', '选择营业时间');
  110. $form->textarea('hot_info','商家简介')->rules('required|max:120');
  111. $form->switch('open_status','开放状态')->states([
  112. 'on' => ['value' => 1, 'text' => '开放', 'color' => 'success'],
  113. 'off' => ['value' => 0, 'text' => '未开放', 'color' => 'default'],
  114. ])->default(1);
  115. $form->multipleFile('pics','宣传照片')->removable();
  116. $form->display('update_id', '更新者')->with(function ($value){
  117. if($value){
  118. }else{
  119. $value=Admin::user()->id;
  120. }
  121. $name = Administrator::where('id',$value)->pluck('name')->first();
  122. return $name;
  123. });
  124. $form->display('create_id', '创建者')->with(function ($value){
  125. if($value){
  126. }else{
  127. $value=Admin::user()->id;
  128. }
  129. $name = Administrator::where('id',$value)->pluck('name')->first();
  130. return $name;
  131. });
  132. $form->hidden('create_id')->default(Admin::user()->id);
  133. //保存前回调
  134. $form->saving(function (Form $form) {
  135. $form->update_id =Admin::user()->id;
  136. });
  137. $form->display('created_at', '创建时间');
  138. $form->display('updated_at', '更新时间');
  139. });
  140. }
  141. }