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

210 lines
6.9 KiB

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