链街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('market_id')->display(function($marketId) use($marketList){
  29. return isset($marketList[$marketId]) ? $marketList[$marketId] : '';
  30. });
  31. // $grid->column('user_id')->display(function($userId){
  32. // $item = UserModel::getUserInfo($userId,'real_name');
  33. // return empty($item) ? '' : $item->real_name;
  34. // });
  35. $grid->column('store_id')->display(function($storeId){
  36. $item = StoreModel::getStoreInfo($storeId,'name');
  37. return empty($item) ? '' : $item->name;
  38. });
  39. $grid->column('position')->display(function($position) use($positionList){
  40. $item = '';
  41. if(!empty($position) && is_array($position)){
  42. foreach($position as $key => $value){
  43. $item .= '【'.$positionList[$value].'】';
  44. }
  45. }
  46. return $item;
  47. });
  48. $grid->column('status')->width(3)->select(EmployeesModel::$_STATUS);
  49. $grid->filter(function (Grid\Filter $filter) use($marketList,$positionList){
  50. $filter->equal('id');
  51. $filter->equal('market_id')->select($marketList);
  52. $filter->equal('position')->select($positionList);
  53. });
  54. $grid->model()->orderBy('status','desc');
  55. $grid->model()->orderBy('id','desc');
  56. // 每页10条
  57. $grid->paginate(10);
  58. });
  59. }
  60. /**
  61. * Make a show builder.
  62. *
  63. * @param mixed $id
  64. *
  65. * @return Show
  66. */
  67. protected function detail($id)
  68. {
  69. return Show::make($id, new LanzuEmployees(), function (Show $show) {
  70. $show->field('id');
  71. $show->field('name');
  72. $show->field('user_id');
  73. $show->field('store_id')->as(function($storeId){
  74. $item = StoreModel::getStoreInfo($storeId,'name');
  75. return empty($item) ? '' : $item->name;
  76. });
  77. $show->field('market_id')->as(function($marketId){
  78. $item = MarketModel::getMarketInfo($marketId,'name');
  79. return empty($item) ? '' : $item->name;
  80. });
  81. $show->field('position')->as(function($position){
  82. $positionList = config('role.position');
  83. $item = '';
  84. if(!empty($position) && is_array($position)){
  85. foreach($position as $key => $value){
  86. $item .= ' 【'.$positionList[$value].'】';
  87. }
  88. }
  89. return $item;
  90. });
  91. $show->field('status_text');
  92. $show->field('note');
  93. $show->field('created_at');
  94. $show->field('updated_at');
  95. });
  96. }
  97. /**
  98. * Make a form builder.
  99. *
  100. * @return Form
  101. */
  102. protected function form()
  103. {
  104. return Form::make(new LanzuEmployees(), function (Form $form) {
  105. $userId = $form->model()->user_id;
  106. //市场
  107. $marketList = MarketModel::getMarketArray();
  108. //店铺
  109. $storeList = StoreModel::getStoreArray([['market_id','=',1]]);
  110. // 用户
  111. // $userList = UserModel::getUserArray();
  112. // 已绑定的用户
  113. // $userHas = EmployeesModel::pluck('user_id')->toArray();
  114. // foreach($userList as $ku => $uv){
  115. // if($ku != 0 && in_array($ku,$userHas) && !in_array($userId,$userHas)){
  116. // unset($userList[$ku]);
  117. // }
  118. // }
  119. $form->hidden('id');
  120. $form->number('user_id')->required()->min(0);
  121. // $form->select('user_id')->required()->options($userList);
  122. $form->text('name','真实姓名')->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. }