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

203 lines
6.7 KiB

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