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

154 lines
5.6 KiB

  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Repositories\v3\LanzuEmployees;
  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\LanzuEmployees as EmployeesModel;
  9. use App\Models\v3\User as UserModel;
  10. use App\Models\v3\Store as StoreModel;
  11. use App\Models\v3\ServicePersonnel as ServicePersonnelModel;
  12. use App\Models\v3\Market as MarketModel;
  13. class LanzuEmployeesController extends AdminController
  14. {
  15. /**
  16. * Make a grid builder.
  17. *
  18. * @return Grid
  19. */
  20. protected function grid()
  21. {
  22. return Grid::make(new LanzuEmployees(), function (Grid $grid) {
  23. //市场
  24. $marketList = MarketModel::getMarketArray();
  25. $positionList = config('role.position');
  26. $grid->column('id')->sortable();
  27. $grid->column('name');
  28. $grid->column('tel');
  29. $grid->column('user_id');
  30. $grid->column('market_id')->display(function($marketId) use($marketList){
  31. return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
  32. });
  33. $grid->column('store_id')->display(function($storeId){
  34. $item = StoreModel::getStoreInfo($storeId,'name');
  35. return empty($item) ? '' : $item->name;
  36. });
  37. $grid->column('position')->display(function($position) use($positionList){
  38. $item = '';
  39. if(!empty($position) && is_array($position)){
  40. foreach($position as $key => $value){
  41. $item .= '【'.$positionList[$value].'】';
  42. }
  43. }
  44. return $item;
  45. });
  46. $grid->column('status')->width(3)->select(EmployeesModel::$_STATUS);
  47. $grid->filter(function (Grid\Filter $filter) use($marketList,$positionList){
  48. $filter->equal('id');
  49. $filter->equal('market_id')->select($marketList);
  50. $filter->like('position')->select($positionList);
  51. });
  52. $grid->model()->orderBy('status','desc');
  53. $grid->model()->orderBy('id','desc');
  54. // 每页10条
  55. $grid->paginate(10);
  56. });
  57. }
  58. /**
  59. * Make a show builder.
  60. *
  61. * @param mixed $id
  62. *
  63. * @return Show
  64. */
  65. protected function detail($id)
  66. {
  67. return Show::make($id, new LanzuEmployees(), function (Show $show) {
  68. $show->field('id');
  69. $show->field('name');
  70. $show->field('tel');
  71. $show->field('user_id');
  72. $show->field('store_id')->as(function($storeId){
  73. $item = StoreModel::getStoreInfo($storeId,'name');
  74. return empty($item) ? '' : $item->name;
  75. });
  76. $show->field('market_id')->as(function($marketId){
  77. $item = MarketModel::getMarketInfo($marketId,'name');
  78. return empty($item) ? '' : $item->name;
  79. });
  80. $show->field('position')->as(function($position){
  81. $positionList = config('role.position');
  82. $item = '';
  83. if(!empty($position) && is_array($position)){
  84. foreach($position as $key => $value){
  85. $item .= ' 【'.$positionList[$value].'】';
  86. }
  87. }
  88. return $item;
  89. });
  90. $show->field('status_text');
  91. $show->field('note');
  92. $show->field('created_at');
  93. $show->field('updated_at');
  94. });
  95. }
  96. /**
  97. * Make a form builder.
  98. *
  99. * @return Form
  100. */
  101. protected function form()
  102. {
  103. return Form::make(new LanzuEmployees(), function (Form $form) {
  104. $userId = $form->model()->user_id;
  105. //市场
  106. $marketList = MarketModel::getMarketArray();
  107. //店铺
  108. $storeList = StoreModel::getStoreArray([['market_id','=',1]]);
  109. // 用户
  110. // $userList = UserModel::getUserArray();
  111. // 已绑定的用户
  112. // $userHas = EmployeesModel::pluck('user_id')->toArray();
  113. // foreach($userList as $ku => $uv){
  114. // if($ku != 0 && in_array($ku,$userHas) && !in_array($userId,$userHas)){
  115. // unset($userList[$ku]);
  116. // }
  117. // }
  118. $form->hidden('id');
  119. $form->number('user_id')->required()->min(0);
  120. // $form->select('user_id')->required()->options($userList);
  121. $form->text('name','真实姓名')->width(2)->required();
  122. $form->mobile('tel')->width(4)->required();
  123. $form->select('market_id')->required()->options($marketList);
  124. $form->multipleSelect('position')->required()->options(config('role.position'));
  125. $form->select('store_id')->options($storeList);
  126. $form->text('note')->maxLength(200);
  127. $form->hidden('status')->default(1);
  128. $form->saving(function(Form $form){
  129. $id = $form->getKey();
  130. $userId = $form->input('user_id');
  131. $store = EmployeesModel::select('id')->where([
  132. ['user_id','=',$userId],
  133. ['id','<>',$id?$id:0],
  134. ])->first();
  135. if(!empty($store)){
  136. return $form->error('用户已经为懒族员工');
  137. }
  138. });
  139. $form->disableResetButton();
  140. $form->disableViewCheck();
  141. $form->disableEditingCheck();
  142. $form->disableCreatingCheck();
  143. });
  144. }
  145. }