DoctorManagementController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace App\Admin\Controllers\UserManagement\DocterManagement;
  3. use App\Admin\Actions\backstage\Docters\AddLabel;
  4. use App\Admin\Actions\backstage\Docters\DefaultOrganazation;
  5. use App\Admin\Actions\backstage\Docters\DelLabel;
  6. use App\Admin\Actions\backstage\Docters\LabelManagement;
  7. use App\Admin\Actions\backstage\Docters\ServiceManagement;
  8. use App\Admin\Actions\backstage\Docters\SignUp;
  9. use App\Admin\Actions\backstage\Docters\Team;
  10. use App\Models\Docter;
  11. use App\Models\DocterLabel;
  12. use App\Models\DocterOrganization;
  13. use App\Models\Organization;
  14. use App\Models\User;
  15. use Encore\Admin\Controllers\AdminController;
  16. use Encore\Admin\Form;
  17. use Encore\Admin\Grid;
  18. use Encore\Admin\Show;
  19. class DoctorManagementController extends AdminController
  20. {
  21. /**
  22. * Title for current resource.
  23. *
  24. * @var string
  25. */
  26. protected $title = '医生列表';
  27. /**
  28. * Make a grid builder.
  29. *
  30. * @return Grid
  31. */
  32. protected function grid()
  33. {
  34. $grid = new Grid(new Docter());
  35. $grid->disableCreateButton();
  36. $grid->filter(function ($filter){
  37. $filter->disableIdFilter();
  38. $filter->like('name','昵称');
  39. // $filter->like('organization','机构名称');
  40. $filter->where(function ($query) {
  41. $query->whereHas('organization',function ($query){
  42. $query->where('name','like',"%{$this->input}%");
  43. });
  44. },'机构名');
  45. $filter->equal('status','工作状态')->select([
  46. 0 => '禁用',
  47. 1 => '启用',
  48. ]);
  49. });
  50. $grid->actions(function ($actions) {
  51. // 去掉编辑
  52. $actions->disableEdit();
  53. // 去掉查看
  54. $actions->disableView();
  55. //签约管理
  56. $actions->add(new SignUp());
  57. //团队管理
  58. $actions->add(new Team());
  59. //标签管理
  60. $actions->add(new LabelManagement());
  61. //服务管理
  62. $actions->add(new ServiceManagement());
  63. //修改默认医院
  64. $actions->add(new DefaultOrganazation());
  65. });
  66. $grid->model()->orderBy('id','desc');
  67. $grid->column('id', __('Id'))->sortable();
  68. $grid->column('name', __('姓名'));
  69. $grid->column('avatar', __('头像'))->lightbox(['width' =>'', 'height' => 30]);
  70. $grid->column('phone', __('电话'));
  71. $grid->column('score', __('评分'));
  72. $grid->column('service_persons', __('服务人数'));
  73. $grid->column('is_then', __('认证状态'))->using([0=>'未认证',1=>'已认证']);
  74. $states = [
  75. 'on' => ['value' => 1, 'text' => '启用', 'color' => 'primary'],
  76. 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
  77. ];
  78. // $grid->column('organization', __('所属机构'))->pluck('name')->label('info');
  79. $grid->column('org', __('所属机构'))->display(function (){
  80. // dd($organization);
  81. // dd($this->id);
  82. $org_id = DocterOrganization::where('docter_id',$this->id)->where('state',1)->pluck('organization_id')->toArray();
  83. $name = Organization::whereIn('id',$org_id)->pluck('name')->toArray();
  84. if (empty($name))
  85. {
  86. return '无';
  87. }
  88. else
  89. {
  90. return $name;
  91. }
  92. })->label('info');
  93. $grid->column('serviceapply', __('开通服务'))->where('status',2)->pluck('service_type')->toArray()->display(function ($type){
  94. $type = array_unique($type);
  95. $type_arr = [];
  96. foreach ($type as $value)
  97. {
  98. if ($value == 1)
  99. {
  100. array_push($type_arr,'图文');
  101. }
  102. if ($value == 2)
  103. {
  104. array_push($type_arr,'电话');
  105. }
  106. if ($value == 3)
  107. {
  108. array_push($type_arr,'门诊');
  109. }
  110. }
  111. if($type_arr==null)
  112. {
  113. return '无';
  114. }
  115. return $type_arr;
  116. })->label('info');
  117. $grid->column('label', __('标签'))->display(function ($label){
  118. // dd($label);
  119. if($label==null)
  120. {
  121. return '无';
  122. }
  123. if($label == '无'){
  124. return '无';
  125. }
  126. $label_value = DocterLabel::whereIn('id',$label)->where('status',1)->pluck('label_name')->toArray();
  127. return $label_value;
  128. })->label('info');
  129. $grid->column('status', __('工作状态'))->switch($states);
  130. return $grid;
  131. }
  132. /**
  133. * Make a show builder.
  134. *
  135. * @param mixed $id
  136. * @return Show
  137. */
  138. protected function detail($id)
  139. {
  140. $show = new Show(Docter::findOrFail($id));
  141. return $show;
  142. }
  143. /**
  144. * Make a form builder.
  145. *
  146. * @return Form
  147. */
  148. protected function form()
  149. {
  150. $form = new Form(new Docter());
  151. $form->switch('status', __('状态'));
  152. return $form;
  153. }
  154. }