OrderController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Community\Actions\Clinc\Finished;
  4. use App\Community\Actions\Clinc\OrderCancel;
  5. use App\Community\Actions\Clinc\Reserved;
  6. use App\Models\Docter;
  7. use App\Models\Order;
  8. use Encore\Admin\Controllers\AdminController;
  9. use Encore\Admin\Facades\Admin;
  10. use Encore\Admin\Form;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Show;
  13. class OrderController extends AdminController
  14. {
  15. /**
  16. * Title for current resource.
  17. *
  18. * @var string
  19. */
  20. protected $title = '门诊预约';
  21. /**
  22. * Make a grid builder.
  23. *
  24. * @return Grid
  25. */
  26. protected function grid()
  27. {
  28. $grid = new Grid(new Order());
  29. $user = Admin::user();
  30. $grid->disableExport(false);
  31. $grid->export(function ($export) {
  32. $export->filename('门诊订单'.Date('Y-m-d',time()));
  33. $export->column('order_status', function ($value, $original) {
  34. $order_status_arr = Order::getStatus();
  35. return $order_status_arr[intval($original)];
  36. } );
  37. });
  38. $is_admin = Admin::user()->inRoles(['administrator','devloper']);
  39. $grid->model()->orderByDesc('id');
  40. //检查是否是门诊医生
  41. $is_docter = $user->isRole('opc');
  42. $org_id = $user->org_id;
  43. $where = ['product_type'=>3];
  44. if(!$is_admin){
  45. if($is_docter) {
  46. $where['docter_id'] = Docter::where(['id'=>$user->docter_id])->value('id');
  47. }
  48. $where ['organization_id']=$org_id;
  49. }
  50. $grid->model()->where($where)->leftJoin('order_patients','order_patients.order_id','=','orders.id');
  51. if(!empty($res['orderPatient']['appoint_start_time']['start']) || !empty($res['orderPatient']['appoint_start_time']['start']) ){
  52. $grid->model()->orderBy('order_patients.appoint_start_time','asc');
  53. } else {
  54. $grid->model()->orderBy('order_patients.appoint_start_time','desc');
  55. }
  56. $grid->column('id', __('Id'));
  57. $grid->column('orderUser.nickname', __('预约用户'));
  58. $grid->column('orderPatient.appoint_start_time', __('预约时间'))->display(function ($w){
  59. $end ='';
  60. $start = '';
  61. if(!empty($this->orderPatient) && $this->orderPatient->appoint_end_time){
  62. $end = date('H:i',$this->orderPatient->appoint_end_time);
  63. }
  64. if(!empty($w)){
  65. $start = date('Y-m-d H:i',$w);
  66. }
  67. return $start.'~'.$end;
  68. });
  69. // $grid->column('orderPatient.appoint_end_time', __('预约结束时间'))->display(function ($w){
  70. // if(empty($w)) return '';
  71. // return date('Y-m-d H:i',$w);
  72. // });
  73. $grid->column('orderPatient.phone', __('电话号码'))->display(function ($p){
  74. if(empty($p)) return $this->user->phone;
  75. return $p;
  76. });
  77. $grid->column('orderPatient.name', __('预约患者'));
  78. $grid->column('orderPatient.sex', __('患者性别'))->display(function ($w){
  79. return $w==1?'男':'女';
  80. });
  81. $grid->column('orderPatient.birthday', __('患者年龄'))->display(function ($w){
  82. return birthday_to_age($w);
  83. });;
  84. $grid->column('docter.name', __('预约医生'));
  85. // $grid->column('order_status', __('订单状态'))->using([1=>'未支付',2=>'待接单',3=>'进行中',4=>'已完成',5=>'已取消']);
  86. // $grid->column('order_status','订单状态')->using(Order::getStatus())->label([1=>'info',2=>'warring',3=>'info',4=>'success',5=>'danger']);
  87. $status_arr = Order::getStatus();
  88. $grid->column('order_status', __('订单状态'))->display(function ($w) use ($status_arr) {
  89. $info = $status_arr[intval($w)];
  90. if($w == 1 || $w == 2){
  91. return '<span class="label label-warning">'.$info.'</span>';
  92. } else if( $w == 4 ){
  93. return '<span class="label label-success">'.$info.'</span>';
  94. } else if($w == 7 || $w == 3 ){
  95. return '<span class="label label-info">'.$info.'</span>';
  96. } else if($w == 6){
  97. return '<span class="label label-danger">'.$info.'</span>';
  98. } else {
  99. return '<span class="label label-default">'.$info.'</span>';
  100. }
  101. });
  102. // $grid->column('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款']);
  103. $grid->column('payment_status', __('支付状态'))->using(Order::getPayStatus())->label([1=>'warring',2=>'success',3=>'info',4=>'danger',5=>'warring']);
  104. //查询
  105. $grid->quickSearch(function ($model, $query) {
  106. $model->whereHas('patients',function ($model) use ($query) {
  107. $model->where('name', 'like', "{$query}%");
  108. });
  109. })->placeholder('请输入用户姓名');
  110. $grid->actions(function ($actions) {
  111. // if(!empty($actions->row->order_status) && $actions->row->order_status < 2){
  112. // $actions->add(new Reserved());
  113. // }
  114. if(!empty($actions->row->order_status) && ($actions->row->order_status<= 3 || $actions->row->order_status == 7) ){
  115. $actions->add(new OrderCancel());
  116. $actions->add(new Finished());
  117. }
  118. // $actions->disableView();
  119. $actions->disableEdit();
  120. $actions->disableDelete();
  121. });
  122. $grid->filter(function (Grid\Filter $filter) {
  123. $filter->disableIdFilter();
  124. $filter->column(1/2, function ($filter) {
  125. $filter->equal('docter_id','排班医生')->select('/cdms/api/getDocter');
  126. $filter->equal('order_status','订单状态')->select(Order::$_order_status);
  127. $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
  128. });
  129. });
  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(Order::findOrFail($id));
  141. $show->field('id', __('Id'));
  142. $show->field('orderUser.nickname', __('预约用户'));
  143. $show->field('orderPatient.sex', __('患者性别'))->as(function ($w){
  144. return $w==1?'男':'女';
  145. });
  146. $show->field('orderPatient.appoint_start_time', __('开始时间'));
  147. $show->field('orderPatient.appoint_end_time', __('结束时间'));
  148. $show->field('orderPatient.birthday', __('患者年龄'));
  149. $show->field('docter.name', __('预约医生'));
  150. $show->field('order_status', __('订单状态'))->using(Order::getStatus())->label('info');
  151. $show->field('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label('info');
  152. $show->panel()->tools(function ($tools) {
  153. $tools->disableEdit();
  154. $tools->disableDelete();
  155. });
  156. $show->field('created_at', __('创建时间'));
  157. $show->field('updated_at', __('更新时间'));
  158. return $show;
  159. }
  160. /**
  161. * Make a form builder.
  162. *
  163. * @return Form
  164. */
  165. protected function form()
  166. {
  167. $form = new Form(new Order());
  168. $form->display('orderUser.nickname', __('用户'));
  169. $form->display('docter_id', __('医生'));
  170. return $form;
  171. }
  172. }