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

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