OrderVaccinesController.php 8.7 KB

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