链街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.

178 lines
5.4 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\ImsCjdcMarket;
  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\LanzuMpInfo;
  9. class ImsCjdcMarketController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new ImsCjdcMarket(), function (Grid $grid) {
  19. $grid->id->sortable();
  20. $grid->logo->image('', 50, 50);
  21. $grid->name;
  22. $grid->column('mp_id', '服务商')->display(function ($mid) {
  23. if ($mid == 0) return '懒族自营';
  24. $mp = LanzuMpInfo::find($mid);
  25. if (!$mp) {
  26. return '<span style="color: #ff0000">数据错误</span>';
  27. }
  28. return $mp->name;
  29. });
  30. $grid->column('status', '状态')->filter(
  31. Grid\Column\Filter\In::make([
  32. 0 => '禁用',
  33. 1 => '正常',
  34. ])
  35. )->display(function ($status) {
  36. if ($status == 0) {
  37. return '禁用';
  38. } else {
  39. return '正常';
  40. }
  41. });
  42. $grid->address;
  43. $grid->column('addtime', '创建时间');
  44. $grid->filter(function (Grid\Filter $filter) {
  45. $filter->equal('id');
  46. });
  47. $grid->disableFilterButton();
  48. $grid->quickSearch(['name'])->placeholder('输入市场名称');
  49. $grid->actions(function (Grid\Displayers\Actions $actions) {
  50. if (!\Admin::user()->isAdministrator() && $actions->row->mp_id == 0) {
  51. $actions->disableDelete();
  52. $actions->disableEdit();
  53. }
  54. });
  55. });
  56. }
  57. /**
  58. * Make a show builder.
  59. *
  60. * @param mixed $id
  61. *
  62. * @return Show
  63. */
  64. protected function detail($id)
  65. {
  66. return Show::make($id, new ImsCjdcMarket(), function (Show $show) {
  67. if (!\Admin::user()->isAdministrator() && $show->model()->mp_id == 0) {
  68. $show->panel()
  69. ->tools(function ($tools) {
  70. $tools->disableEdit();
  71. $tools->disableList();
  72. $tools->disableDelete();
  73. // 显示快捷编辑按钮
  74. $tools->showQuickEdit();
  75. });
  76. }
  77. $show->name;
  78. $show->logo->image();
  79. $show->introduce;
  80. $show->imgs->image();
  81. $show->addtime('创建时间');
  82. $show->sort;
  83. $show->status()->using([0=>'禁用',1=>'正常']);
  84. $show->coordinates;
  85. $show->remark;
  86. $show->address;
  87. $show->poundage;
  88. $show->dn_poundage;
  89. $show->dm_poundage;
  90. $show->yd_poundage;
  91. $show->loudspeaker_imei;
  92. $show->dishes_menu_intro;
  93. $show->create_time->as(function ($time){
  94. if ($time){
  95. return date('Y-m-d H:i',$time);
  96. }else{
  97. return '-';
  98. }
  99. });
  100. $show->created_at->as(function ($time){
  101. if ($time){
  102. return date('Y-m-d H:i',$time);
  103. }else{
  104. return '-';
  105. }
  106. });
  107. $show->updated_at->as(function ($time){
  108. if ($time){
  109. return date('Y-m-d H:i',$time);
  110. }else{
  111. return '-';
  112. }
  113. });
  114. });
  115. }
  116. /**
  117. * Make a form builder.
  118. *
  119. * @return Form
  120. */
  121. protected function form()
  122. {
  123. return Form::make(new ImsCjdcMarket(), function (Form $form) {
  124. $form->display('id');
  125. $form->text('name')->required();
  126. $form->select('mp_id', '服务商')->options('/api/getMpInfo')->required();
  127. $form->text('address')->required();
  128. $form->text('coordinates')
  129. ->required()
  130. ->placeholder('输入 经纬度,如: 108.281552,22.83731')
  131. ->help("通过网址 <a href='https://lbs.amap.com/console/show/picker' target='_blank'>https://lbs.amap.com/console/show/picker</a> 获取经纬度");
  132. $form->text('poundage');
  133. $form->text('dn_poundage');
  134. $form->text('dm_poundage');
  135. $form->text('yd_poundage');
  136. $form->text('loudspeaker_imei')->value(0);
  137. $form->number('sort', '排序');
  138. $form->switch('status', '状态');
  139. $form->image('logo');
  140. $form->multipleImage('imgs', '市场图片');
  141. $form->textarea('introduce');
  142. $form->textarea('remark');
  143. $form->textarea('dishes_menu_intro')->value('菜谱简介');
  144. });
  145. }
  146. /**
  147. * 服务商信息
  148. * @return \Illuminate\Http\JsonResponse
  149. */
  150. protected function getMpInfo()
  151. {
  152. $mps = LanzuMpInfo::all();
  153. $ret = [];
  154. foreach ($mps as $key => $value) {
  155. $item = [];
  156. $item['id'] = $value->id;
  157. $item['text'] = $value->name;
  158. $ret[] = $item;
  159. }
  160. return response()->json($ret);
  161. }
  162. }