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

150 lines
5.5 KiB

  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Repositories\v3\ServicePersonnel;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\v3\ServicePersonnel as ServicePersonnelModel;
  9. use App\Models\v3\Market as MarketModel;
  10. use App\Models\v3\User as UserModel;
  11. use App\Admin\Common\WeChatQrCode;
  12. class ServicePersonnelController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. return Grid::make(new ServicePersonnel(), function (Grid $grid) {
  22. //市场
  23. $marketList = MarketModel::getMarketArray();
  24. $grid->column('id')->sortable();
  25. $grid->column('head_url')->image('',50);
  26. $grid->column('name');
  27. $grid->column('tel');
  28. $grid->column('market_id')->display(function($marketId) use ($marketList){
  29. return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
  30. });
  31. $grid->column('type_text');
  32. $grid->column('qr_url')->image('',50);
  33. $grid->column('status')->using(ServicePersonnelModel::$_STATUS)->label(config('label.status_label'));
  34. $grid->model()->orderby('id','desc');
  35. $grid->filter(function (Grid\Filter $filter) use($marketList){
  36. $filter->equal('id');
  37. $filter->like('name');
  38. $filter->equal('type')->select(ServicePersonnelModel::$_TYPE);
  39. $filter->equal('market_id')->select($marketList);
  40. });
  41. // 每页10条
  42. $grid->paginate(10);
  43. // $grid->disableDeleteButton();
  44. });
  45. }
  46. /**
  47. * Make a show builder.
  48. *
  49. * @param mixed $id
  50. *
  51. * @return Show
  52. */
  53. protected function detail($id)
  54. {
  55. return Show::make($id, new ServicePersonnel(), function (Show $show) {
  56. $show->row(function (Show\Row $show) {
  57. $show->width(6)->id;
  58. $show->width(6)->field('name');
  59. $show->width(6)->field('tel');
  60. $show->width(6)->field('user_id')->as(function($userId){
  61. $item = UserModel::getUserInfo($userId,'nick_name');
  62. return empty($item) ? '' : '【'.$userId.'】:' . $item['nick_name'];
  63. });
  64. $show->width(6)->field('head_url')->image();
  65. $show->width(6)->field('qr_url')->image();
  66. });
  67. $show->row(function (Show\Row $show) {
  68. $show->width(6)->field('market_id')->as(function($marketId){
  69. $item = MarketModel::getMarketInfo($marketId,'name');
  70. return empty($item) ? '' : $item['name'];
  71. });
  72. $show->width(6)->field('type_text');
  73. $show->width(6)->field('status_text');
  74. $show->width(6)->field('created_at')->as(function($createdAt){
  75. return date('Y-m-d H:i:s',$createdAt);
  76. });
  77. $show->width(6)->field('updated_at')->as(function($updatedAt){
  78. return date('Y-m-d H:i:s',$updatedAt);
  79. });
  80. });
  81. });
  82. }
  83. /**
  84. * Make a form builder.
  85. *
  86. * @return Form
  87. */
  88. protected function form()
  89. {
  90. return Form::make(new ServicePersonnel(), function (Form $form) {
  91. $userId = $form->model()->user_id;
  92. //市场
  93. $marketList = MarketModel::getMarketArray();
  94. // 用户
  95. $userList = UserModel::getUserArray();
  96. // 已绑定的用户
  97. $userHas = ServicePersonnelModel::pluck('user_id')->toArray();
  98. foreach($userList as $ku => $uv){
  99. if($ku != 0 && in_array($ku,$userHas) && !in_array($userId,$userHas)){
  100. unset($userList[$ku]);
  101. }
  102. }
  103. $form->column(6,function(Form $form){
  104. $form->hidden('id');
  105. $form->text('name')->required();
  106. $form->text('tel')->required();
  107. $form->image('head_url')->autoUpload();
  108. });
  109. $form->column(6,function(Form $form) use($marketList,$userList){
  110. $form->select('type')->options(ServicePersonnelModel::$_TYPE)->required();
  111. $form->select('market_id')->options($marketList)->required();
  112. $form->select('user_id')->options($userList)->required();
  113. $statusList = ServicePersonnelModel::$_STATUS;
  114. unset($statusList[0],$statusList[2]);
  115. $form->radio('status')->options($statusList)->default(1);
  116. });
  117. $form->saved(function(Form $form){
  118. $id = $form->getKey();
  119. if($form->isCreating() && !empty($id)){
  120. $model = ServicePersonnelModel::find($id);
  121. $qrCode = new WeChatQrCode();
  122. // 生成专员二维码
  123. $qrCodeImg = $qrCode->getServicePersonnel($id);
  124. if($qrCodeImg['status']){
  125. $model->qr_url = $qrCodeImg['path'];
  126. $model->save();
  127. }
  128. }
  129. });
  130. $form->disableResetButton();
  131. $form->disableViewCheck();
  132. $form->disableEditingCheck();
  133. $form->disableCreatingCheck();
  134. });
  135. }
  136. }