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

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