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

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