FasteOrder.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Community\Actions\Vaccine;
  3. use App\Models\Order;
  4. use App\Models\OrderPatient;
  5. use App\Models\OrderVaccine;
  6. use App\Models\OrganizationVaccine;
  7. use App\Models\Patient;
  8. use App\Models\TimePeriod;
  9. use App\Models\Vaccine;
  10. use Encore\Admin\Actions\Action;
  11. use Encore\Admin\Actions\RowAction;
  12. use Encore\Admin\Grid\Tools\AbstractTool;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Support\Facades\Request;
  15. use Encore\Admin\Facades\Admin;
  16. class FasteOrder extends Action
  17. {
  18. protected $selector = '.import-tenant';
  19. public function handle()
  20. {
  21. $data = request()->all();
  22. $org_id = Admin::user()->org_id;
  23. $timeInfo = TimePeriod::where(['id'=>$data['timer']])->first()->toArray();
  24. $patientInfo = Patient::where(['id'=>$data['user']])->first()->toArray();
  25. $vaccineInfo = Vaccine::where(['id'=>$data['vaccine']])->first()->toArray();
  26. $orgVaccine = OrganizationVaccine::where(['vaccine_id'=>$data['vaccine'],'org_id'=>$org_id])->first()->toArray();
  27. DB::beginTransaction();
  28. try {
  29. $orderInfo = [
  30. 'user_id'=>$patientInfo['user_id'],
  31. 'organization_id'=>$org_id,
  32. 'order_sn'=>$patientInfo['user_id'],
  33. 'product_type'=>4,
  34. 'order_status'=>3,
  35. 'payment_status'=>2,
  36. ];
  37. $order = Order::create($orderInfo);
  38. $order_sn = build_sn($order['id']);
  39. Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
  40. //保存订单患者信息
  41. $addPatient = Patient::select(['name', 'sex', 'avatar', 'birthday', 'relationship_type', 'info', 'card_type', 'card_number', 'card_img_url', 'card_back_img_url', 'email', 'phone as patient_phone', 'social_card_number', 'born_hospital', 'guardian_name', 'address'])->where('id', $data['user'])->first()->getOriginal();
  42. $addPatient['order_id'] = $order['id'];
  43. $addPatient['patient_id'] = $data['user'];
  44. $addPatient['organization_id'] = $org_id;
  45. $addPatient['time_period_id'] = $data['timer'];
  46. $addPatient['appoint_start_time'] = strtotime($data['date'].' '.$timeInfo['start_time_period'].':00');
  47. $addPatient['appoint_end_time'] = strtotime($data['date'].' '.$timeInfo['end_time_period'].':00');
  48. $patienter = OrderPatient::create($addPatient);
  49. // todo 需要完善疫苗订单
  50. // $vaccine = [
  51. // 'order_id'=>$order['id'],
  52. // 'order_patient_id'=>$patienter['id'],
  53. // 'vaccine_id'=>$orgVaccine['vaccine_id'],
  54. // 'vaccine_type'=>$orgVaccine['type'],
  55. // 'vaccine_price'=>$orgVaccine['price'],
  56. // 'vaccine_name'=>$vaccineInfo['name'],
  57. // 'vaccine_remark'=>$vaccineInfo['remark'],
  58. // 'vaccine_supplier'=>$orgVaccine['supplier'],
  59. // ];
  60. //
  61. // OrderVaccine::create($vaccine);
  62. DB::commit();
  63. } catch ( Exception $e){
  64. DB::rollBack();
  65. return $this->response()->error('添加订单失败');
  66. }
  67. return $this->response()->success('导入完成!')->refresh();
  68. }
  69. public function form()
  70. {
  71. Admin::script($this->script());
  72. Admin::js('select2.js');
  73. $patient = Patient::pluck('name','id');
  74. $org_id = Admin::user()->org_id;
  75. $ids = OrganizationVaccine::where(['org_id'=>$org_id])->pluck('vaccine_id');
  76. $vaccine = Vaccine::whereIn('id',$ids)->pluck('name','id');
  77. $this->select('user', '接种人')->options($patient)->rules('required',['required'=>'请选择接种患者']);
  78. $this->select('vaccine', '疫苗')->options($vaccine)->rules('required',['required'=>'请选择疫苗']);
  79. $this->date('date','时间')->rules('required',['required'=>'请选择时间']);
  80. $this->select('timer','时间段')->rules('required',['required'=>'请选择时间段']);
  81. }
  82. public function html()
  83. {
  84. return <<<HTML
  85. <a class="btn btn-sm btn-default import-tenant"><i class="fa fa-calendar-check-o"></i> 快速预约</a>
  86. HTML;
  87. }
  88. protected function script()
  89. {
  90. return <<<EOT
  91. $('#date').blur(function () {
  92. var url = '';
  93. var date = $('#date').val();
  94. console.log(date);
  95. $.get("/cdms/api/getDateVaccine",{date: this.value}, function (data) {
  96. var html = '';
  97. for(let key in data){
  98. console.log(key + '---' + data[key])
  99. html += '<option value="'+key+'">'+data[key]+'</option>';
  100. }
  101. $('select[name="timer"]').empty();
  102. $('select[name="timer"]').append(html);
  103. });
  104. });
  105. EOT;
  106. }
  107. }