whj 4 rokov pred
rodič
commit
958638046f

+ 72 - 9
app/Community/Actions/Vaccine/FasteOrder.php

xqd xqd xqd xqd
@@ -2,12 +2,17 @@
 
 namespace App\Community\Actions\Vaccine;
 
+use App\Models\Order;
+use App\Models\OrderPatient;
+use App\Models\OrderVaccine;
 use App\Models\OrganizationVaccine;
 use App\Models\Patient;
+use App\Models\TimePeriod;
 use App\Models\Vaccine;
 use Encore\Admin\Actions\Action;
 use Encore\Admin\Actions\RowAction;
 use Encore\Admin\Grid\Tools\AbstractTool;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Request;
 use Encore\Admin\Facades\Admin;
 
@@ -15,9 +20,61 @@ class FasteOrder extends Action
 {
     protected $selector = '.import-tenant';
 
-    public function handle(Request $request)
+    public function handle()
     {
-        $request->file('file');
+        $data = request()->all();
+
+        $org_id = Admin::user()->org_id;
+        $timeInfo = TimePeriod::where(['id'=>$data['timer']])->first()->toArray();
+        $patientInfo = Patient::where(['id'=>$data['user']])->first()->toArray();
+        $vaccineInfo = Vaccine::where(['id'=>$data['vaccine']])->first()->toArray();
+        $orgVaccine = OrganizationVaccine::where(['vaccine_id'=>$data['vaccine'],'org_id'=>$org_id])->first()->toArray();
+        DB::beginTransaction();
+        try {
+            $orderInfo = [
+                'user_id'=>$patientInfo['user_id'],
+                'organization_id'=>$org_id,
+                'order_sn'=>$patientInfo['user_id'],
+                'product_type'=>4,
+                'order_status'=>3,
+                'payment_status'=>2,
+            ];
+            $order = Order::create($orderInfo);
+            $order_sn = build_sn($order['id']);
+            Order::where('id', $order['id'])->update(['order_sn' => $order_sn]);
+
+            //保存订单患者信息
+            $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();
+            $addPatient['order_id'] = $order['id'];
+            $addPatient['patient_id'] = $data['user'];
+            $addPatient['organization_id'] = $org_id;
+            $addPatient['time_period_id'] = $data['timer'];
+            $addPatient['appoint_start_time'] = strtotime($data['date'].' '.$timeInfo['start_time_period'].':00');
+            $addPatient['appoint_end_time'] = strtotime($data['date'].' '.$timeInfo['end_time_period'].':00');
+
+            $patienter = OrderPatient::create($addPatient);
+            // todo 需要完善疫苗订单
+//            $vaccine = [
+//                'order_id'=>$order['id'],
+//                'order_patient_id'=>$patienter['id'],
+//                'vaccine_id'=>$orgVaccine['vaccine_id'],
+//                'vaccine_type'=>$orgVaccine['type'],
+//                'vaccine_price'=>$orgVaccine['price'],
+//                'vaccine_name'=>$vaccineInfo['name'],
+//                'vaccine_remark'=>$vaccineInfo['remark'],
+//                'vaccine_supplier'=>$orgVaccine['supplier'],
+//            ];
+//
+//            OrderVaccine::create($vaccine);
+            DB::commit();
+        } catch ( Exception $e){
+            DB::rollBack();
+            return $this->response()->error('添加订单失败');
+        }
+
+
+
+
         return $this->response()->success('导入完成!')->refresh();
 
     }
@@ -30,10 +87,10 @@ class FasteOrder extends Action
         $org_id = Admin::user()->org_id;
         $ids = OrganizationVaccine::where(['org_id'=>$org_id])->pluck('vaccine_id');
         $vaccine = Vaccine::whereIn('id',$ids)->pluck('name','id');
-        $this->select('user', '接种人')->options($patient);
-        $this->select('vaccine', '疫苗')->options($vaccine);
-        $this->date('date','时间');
-        $this->select('timer','时间段');
+        $this->select('user', '接种人')->options($patient)->rules('required',['required'=>'请选择接种患者']);
+        $this->select('vaccine', '疫苗')->options($vaccine)->rules('required',['required'=>'请选择疫苗']);
+        $this->date('date','时间')->rules('required',['required'=>'请选择时间']);
+        $this->select('timer','时间段')->rules('required',['required'=>'请选择时间段']);
     }
 
     public function html()
@@ -47,14 +104,20 @@ HTML;
     {
 
         return <<<EOT
-
         $('#date').blur(function () {
             var url = '';
             var date = $('#date').val();
             console.log(date);
-
+            $.get("/cdms/api/getDateVaccine",{date: this.value}, function (data) {
+                var html = '';
+                for(let key  in data){
+                console.log(key + '---' + data[key])
+                 html += '<option value="'+key+'">'+data[key]+'</option>';
+                }
+                $('select[name="timer"]').empty();
+                $('select[name="timer"]').append(html);
+            });
         });
-
 EOT;
     }
 }

+ 26 - 0
app/Community/Controllers/ApiController.php

xqd
@@ -96,6 +96,32 @@ class ApiController extends Controller
         return redirect('/cdms/nurse_users');
     }
 
+    public function getDateVaccine()
+    {
+        $date = request('d');
+        $org_id = Admin::user()->org_id;
+        return [
+            1=>'09:00',
+            3=>'10:00',
+            4=>'11:00',
+            6=>'12:00',
+            7=>'13:00',
+        ];
+        $timeIds = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date])->distinct('time_period_id')->get(['time_period_id'])->toArray();
+        if(empty($timeIds)) return [];
+        $times = TimePeriod::whereIn('id',$timeIds)->where('start_time_period','>',date('H:i:s',time()))->get();
+        foreach ($times as $info){
+            $timer[$info['id']] = $info['start_time_period'].'-'.$info['end_time_period'];
+        }
+        return [
+            ['id'=>1,'text'=>'09:00'],
+            ['id'=>2,'text'=>'10:00'],
+            ['id'=>3,'text'=>'11:00'],
+        ];
+        return $timer;
+
+    }
+
     //发送短信
     public function sendmsg()
     {

+ 3 - 0
app/Community/routes.php

xqd
@@ -14,6 +14,9 @@ Route::resource('order_nurses', OrderNurseController::class);
 Route::resource('vaccines', VaccineController::class);
 Route::resource('order_vaccines', OrderVaccinesController::class);
 Route::resource('vaccine_users', VaccineUserController::class);
+//获取疫苗日期排班
+Route::get('/api/getDateVaccine', 'ApiController@getDateVaccine');
+
 Route::resource('organization_vaccines', Vaccine\OrganizationVaccineController::class);
 
 Route::resource('docters', DocterOrgController::class);