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

201 lines
6.5 KiB

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