VaccineUserController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Models\Order;
  4. use App\Models\Patient;
  5. use App\Models\PatientRemark;
  6. use Encore\Admin\Controllers\AdminController;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Show;
  11. class VaccineUserController extends AdminController
  12. {
  13. /**
  14. * Title for current resource.
  15. *
  16. * @var string
  17. */
  18. protected $title = '计免用户';
  19. /**
  20. * Make a grid builder.
  21. *
  22. * @return Grid
  23. */
  24. protected function grid()
  25. {
  26. $grid = new Grid(new Order());
  27. $grid->model()->orderByDesc('id');
  28. $is_amdin = Admin::user()->isRole('administrator');
  29. $user = Admin::user();
  30. if(!$is_amdin){
  31. $grid->model()->where(['organization_id'=>$user->org_id,'product_type'=>4]);
  32. }
  33. $grid->model()->GroupBy('patient_id');
  34. $grid->column('orderPatient.name', __('姓名'));
  35. $grid->column('orderUser.nickname', __('监护人'));
  36. $grid->column('orderPatient.phone', __('监护人手机号'))->display(function ($w){
  37. if(empty($w)) return Patient::where('id',$this->patient_id)->value('phone');
  38. return $w;
  39. });
  40. $grid->column('orderPatient.birthday', __('出生日期'));
  41. $grid->column('patient_id', __('备注'))->display(function ($w) use($user) {
  42. return PatientRemark::where(['org_id'=>intval($user->org_id),'patient_id'=>$w,'type'=>2])->value('remark');
  43. });
  44. $grid->filter(function ($flter){
  45. $flter->like('orderPatient.name','请输入用户姓名');
  46. $flter->like('orderUser.nickname','请输入监护人姓名');
  47. $flter->between('orderUser.birthday','生日')->datetime();
  48. });
  49. return $grid;
  50. }
  51. /**
  52. * Make a show builder.
  53. *
  54. * @param mixed $id
  55. * @return Show
  56. */
  57. protected function detail($id)
  58. {
  59. $show = new Show(Order::findOrFail($id));
  60. return $show;
  61. }
  62. /**
  63. * Make a form builder.
  64. *
  65. * @return Form
  66. */
  67. protected function form()
  68. {
  69. $form = new Form(new Order());
  70. $form->setAction('/cdms/api/paitent_remark');
  71. $form->hidden('patient_id');
  72. $org_id = Admin::user()->org_id;
  73. $form->hidden('org_id')->default(intval($org_id));
  74. $form->hidden('type')->default(2);
  75. $form->textarea('remark','备注')->default(function () use ($org_id,$form){
  76. return PatientRemark::where(['org_id'=>intval($org_id),'patient_id'=>$form->model()->patient_id,'type'=>2])->value('remark');
  77. });
  78. return $form;
  79. }
  80. }