OrderVaccinesController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Community\Actions\Vaccine\AddVaccine;
  4. use App\Community\Actions\Vaccine\FasteOrder;
  5. use App\Community\Actions\Vaccine\Finished;
  6. use App\Community\Actions\Vaccine\OrderCance;
  7. use App\Community\Actions\Vaccine\Reserved;
  8. use App\Models\Docter;
  9. use App\Models\Order;
  10. use App\Models\OrderPatient;
  11. use App\Models\OrderVaccine;
  12. use Encore\Admin\Controllers\AdminController;
  13. use Encore\Admin\Facades\Admin;
  14. use Encore\Admin\Form;
  15. use Encore\Admin\Grid;
  16. use Encore\Admin\Show;
  17. use Illuminate\Support\Facades\Date;
  18. use Illuminate\Support\Facades\DB;
  19. class OrderVaccinesController 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 Order());
  35. $res = request()->all();
  36. $grid->disableExport(false);
  37. $grid->export(function ($export) {
  38. $export->filename('疫苗订单'.Date('Y-m-d',time()));
  39. $export->column('order_status', function ($value, $original) {
  40. $order_status_arr = Order::getStatus();
  41. return $order_status_arr[intval($original)];
  42. } );
  43. });
  44. // $grid->model()->orderByDesc('orders.id');
  45. // if(!empty($res['orderPatient']['appoint_start_time']['start']) || !empty($res['orderPatient']['appoint_start_time']['start']) ){
  46. //
  47. // $grid->model()->leftJoin('order_patients','order_patients.order_id','=','orders.id')->orderByDesc('order_patients.appoint_start_time');
  48. //
  49. // $grid->model()->whereHas('orderPatient',function($query){
  50. // $query->orderBy( OrderPatient::select('appoint_start_time')
  51. // ->whereColumn('order_id', 'orders.id')
  52. // ->orderBy('appoint_start_time', 'asc'));
  53. // });
  54. // } else {
  55. // $grid->model()->whereHas('orderPatient',function($query){
  56. // return $query->orderBy('appoint_start_time','desc')->groupBy('appoint_start_time');
  57. // });
  58. // }
  59. DB::enableQueryLog();
  60. // select bm_orders.*,bm_order_patients.appoint_end_time,bm_order_patients.appoint_start_time,bm_order_patients.name from `bm_orders`
  61. //left join `bm_order_patients` on `bm_order_patients`.`order_id` = `bm_orders`.`id` ORDER BY bm_order_patients.appoint_start_time asc;
  62. //
  63. // $grid->model()->leftJoin('order_patients','order_patients.order_id','=','orders.id')
  64. // ->orderByDesc('order_patients.appoint_start_time');
  65. // $grid->model()->orderByDesc('orders.idaa');
  66. $user = Admin::user();
  67. $is_admin = Admin::user()->inRoles(['administrator','devloper']);
  68. $is_docter = $user->docter_id;
  69. $where = ['product_type'=>4];
  70. if(!$is_admin){
  71. $org_id = $user->org_id;
  72. $where = ['product_type'=>4,'organization_id'=>$org_id];
  73. // if($is_docter) {
  74. // $where['docter_id'] = Docter::where(['id'=>$user->docter_id])->value('id');
  75. // }
  76. }
  77. $grid->model()->where($where);
  78. $grid->column('id', __('Id'));
  79. $grid->column('user.nickname', __('预约用户'));
  80. // $grid->column('yuyue', __('预约时间'))->display(function ($w){
  81. // if(empty($this->orderPatient) || empty($this->orderPatient->appoint_start_time)) return '';
  82. // return date('Y-m-d H:i',($this->orderPatient->appoint_start_time)) .'致' . date('H:i',($this->orderPatient->appoint_end_time));
  83. // });
  84. $grid->column('orderPatient.appoint_start_time', __('预约时间'))->display(function ($w){
  85. if(empty($this->orderPatient) || empty($this->orderPatient->appoint_start_time)) return '';
  86. return date('Y-m-d H:i',$w).'~'.date('H:i',$this->orderPatient->appoint_end_time);
  87. });
  88. $grid->column('end_time', __('接种时间'))->display(function ($w){
  89. if(empty($w)) return '';
  90. return date('Y-m-d',$w);
  91. });
  92. $grid->column('orderPatient.name', __('接种患者'));
  93. $grid->column('orderPatient.sex', __('患者性别'))->display(function ($w){
  94. return $w==1?'男':'女';
  95. });
  96. $grid->column('orderPatient.birthday', __('患者年龄'))->display(function ($w){
  97. return birthday_to_age($w);
  98. });
  99. $grid->column('vac_name', __('接种疫苗'))->display(function ($w){
  100. $vaccine_name = OrderVaccine::where('order_id',$this->id)->pluck('vaccine_name')->toArray();
  101. if(empty($vaccine_name) ) return '';
  102. return implode(',',$vaccine_name);
  103. });
  104. // $grid->column('docter.name', __('排班医生'));
  105. $status_arr = Order::getStatus();
  106. $grid->column('order_status', __('订单状态'))->display(function ($w) use ($status_arr) {
  107. $info = $status_arr[intval($w)];
  108. if($w == 1 || $w == 2){
  109. return '<span class="label label-warning">'.$info.'</span>';
  110. } else if( $w == 4 ){
  111. return '<span class="label label-success">'.$info.'</span>';
  112. } else if($w == 7 || $w == 3 ){
  113. return '<span class="label label-info">'.$info.'</span>';
  114. } else if($w == 6){
  115. return '<span class="label label-danger">'.$info.'</span>';
  116. } else {
  117. return '<span class="label label-default">'.$info.'</span>';
  118. }
  119. });
  120. // $grid->column('payment_status', __('支付状态'))->using(Order::getPayStatus())->label([1=>'warring',2=>'success',3=>'info',4=>'danger']);
  121. $grid->filter(function ($filter) {
  122. $filter->column(1/2, function ($filter) {
  123. // $filter->equal('docter.id','排班医生')->select('/cdms/api/getDocter');
  124. $filter->equal('order_status','订单状态')->select(Order::$_order_status);
  125. $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
  126. });
  127. });
  128. $grid->tools(function ($tools) {
  129. $tools->append(new FasteOrder());
  130. });
  131. $grid->actions(function ($actions) {
  132. // if( $actions->row->order_status<= 2){
  133. // $actions->add(new Reserved());
  134. // }
  135. if(!empty($actions->row->order_status) && ($actions->row->order_status<= 3 || $actions->row->order_status == 7 ) ){
  136. $actions->add(new Finished());
  137. $actions->add(new OrderCance());
  138. $actions->add(new AddVaccine());
  139. }
  140. $actions->disableEdit();
  141. // $actions->disableView();
  142. $actions->disableDelete();
  143. });
  144. return $grid;
  145. }
  146. /**
  147. * Make a show builder.
  148. *
  149. * @param mixed $id
  150. * @return Show
  151. */
  152. protected function detail($id)
  153. {
  154. $show = new Show(Order::findOrFail($id));
  155. $show->field('id', __('Id'));
  156. $show->field('orderPatient.name', __('患者姓名'));
  157. $show->field('orderPatient.sex', __('患者性别'))->as(function ($w){
  158. return $w==1?'男':'女';
  159. });
  160. $show->field('orderPatient.birthday', __('生日'))->as(function ($w){
  161. return birthday_to_age($w);
  162. });
  163. $show->field('orderVaccine.id', __('疫苗'))->as(function ($w){
  164. $vaccine_name = OrderVaccine::where('order_id',$this->id)->pluck('vaccine_name')->toArray();
  165. if(empty($vaccine_name) ) return '';
  166. return implode(',',$vaccine_name);
  167. });
  168. $show->field('payment_status', __('支付状态'))->using([1=>'待付款',2=>'已付款',3=>'退款中',4=>'已退款'])->label('info');
  169. $show->field('order_status', __('订单状态'))->using(Order::getStatus())->label('info');
  170. $show->field('created_at', __('创建时间'));
  171. $show->field('updated_at', __('更新时间'));
  172. return $show;
  173. }
  174. /**
  175. * Make a form builder.
  176. *
  177. * @return Form
  178. */
  179. protected function form()
  180. {
  181. $form = new Form(new OrderVaccine());
  182. $form->number('order_id', __('Order id'));
  183. $form->number('order_patient_id', __('Order patient id'));
  184. $form->number('vaccine_id', __('Vaccine id'));
  185. $form->switch('vaccine_type', __('Vaccine type'));
  186. $form->number('vaccine_price', __('Vaccine price'));
  187. $form->text('vaccine_name', __('Vaccine name'));
  188. $form->text('vaccine_remark', __('Vaccine remark'));
  189. $form->text('vaccine_supplier', __('Vaccine supplier'));
  190. return $form;
  191. }
  192. }