链街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\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->column('status')->switch();
  55. $grid->created_at->display(function ($time){
  56. return date('Y-m-d H:i:s',$time);
  57. });
  58. $grid->filter(function (Grid\Filter $filter) {
  59. $filter->equal('id');
  60. });
  61. $grid->disableFilterButton();
  62. $grid->quickSearch(['name'])->placeholder('输入市场名称');
  63. $grid->actions(function (Grid\Displayers\Actions $actions) {
  64. if (!\Admin::user()->isAdministrator() && $actions->row->mp_id == 0) {
  65. $actions->disableDelete();
  66. $actions->disableEdit();
  67. }
  68. });
  69. });
  70. }
  71. /**
  72. * Make a show builder.
  73. *
  74. * @param mixed $id
  75. *
  76. * @return Show
  77. */
  78. protected function detail($id)
  79. {
  80. return Show::make($id, new Market(), function (Show $show) {
  81. if (!\Admin::user()->isAdministrator() && $show->model()->mp_id == 0) {
  82. $show->panel()
  83. ->tools(function ($tools) {
  84. $tools->disableEdit();
  85. $tools->disableList();
  86. $tools->disableDelete();
  87. // 显示快捷编辑按钮
  88. $tools->showQuickEdit();
  89. });
  90. }
  91. $show->name;
  92. $show->logo->image();
  93. $show->introduce;
  94. $show->imgs->image();
  95. $show->addtime('创建时间');
  96. $show->sort;
  97. $show->status()->using([0=>'禁用',1=>'正常']);
  98. $show->remark;
  99. $show->address;
  100. $show->created_at->as(function ($time){
  101. if ($time){
  102. return date('Y-m-d H:i',$time);
  103. }else{
  104. return '-';
  105. }
  106. });
  107. $show->updated_at->as(function ($time){
  108. if ($time){
  109. return date('Y-m-d H:i',$time);
  110. }else{
  111. return '-';
  112. }
  113. });
  114. });
  115. }
  116. /**
  117. * Make a form builder.
  118. *
  119. * @return Form
  120. */
  121. protected function form()
  122. {
  123. return Form::make(new Market(), function (Form $form) {
  124. $form->display('id');
  125. $form->text('name')->required();
  126. $form->select('mp_id', '服务商')->options('/api/getMpInfo');
  127. $form->mobile('tel','电话')->required();
  128. $form->select('province_id','省')
  129. ->options('/api/area')->required()
  130. ->load('city_id','/api/area');
  131. $form->select('city_id','市')->required()->load('region_id','/api/area');
  132. $form->select('region_id','区')->required();
  133. $form->text('address')->required();
  134. if ($form->isEditing()){
  135. $form->text('coordinates')
  136. ->value(implode(',',[$form->model()->lng,$form->model()->lat]))
  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. if (!($form->mp_id)){
  141. $form->mp_id = '0';
  142. }
  143. }else{
  144. $form->text('coordinates')
  145. ->required()
  146. ->placeholder('输入 经纬度,如: 108.281552,22.83731')
  147. ->help("通过网址 <a href='https://lbs.amap.com/console/show/picker' target='_blank'>https://lbs.amap.com/console/show/picker</a> 获取经纬度");
  148. }
  149. $form->number('sort', '排序');
  150. $form->switch('status', '状态');
  151. $form->image('logo')->required();
  152. $form->multipleImage('imgs', '市场图片');
  153. $form->textarea('remark')->required();
  154. $form->hidden('lng');
  155. $form->hidden('lat');
  156. $form->saving(function (Form $form){
  157. if($form->coordinates){
  158. $coordinates = explode(',',$form->coordinates);
  159. $form->lng = $coordinates[0];
  160. $form->lat = $coordinates[1];
  161. $form->deleteInput('coordinates');
  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. }