OrderController.php 7.3 KB

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