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

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