zilong преди 4 години
родител
ревизия
9b99dbd454
променени са 1 файла, в които са добавени 19 реда и са изтрити 0 реда
  1. 19 0
      app/Http/Controllers/Api/V1/DocterController.php

+ 19 - 0
app/Http/Controllers/Api/V1/DocterController.php

xqd xqd xqd
@@ -18,6 +18,7 @@ use App\Models\SchedulePeriod;
 use App\Models\ServicePack;
 use App\Models\SystemConfig;
 use App\Models\Team;
+use App\Models\VaccineAppoint;
 use DB;
 
 class DocterController extends AuthController
@@ -240,6 +241,7 @@ class DocterController extends AuthController
         $this->validate(request(), [
             'organization_id' => 'required|integer',
             'schedule_type' => 'required|integer',
+            'vaccine_id' => 'integer',
             'latitude' => 'numeric',
             'longitude' => 'numeric',
         ]);
@@ -261,6 +263,23 @@ class DocterController extends AuthController
                         $can_appoint_num = $docterSettings['service_num'] - $v1['order_num'];
                         $v1['can_appoint_num'] = $can_appoint_num < 0 ? 0 : $can_appoint_num;
                     }
+                    //疫苗要判断具体时间段可接种
+                    $v1['can_appoint'] = 1;
+                    if (!empty($req['vaccine_id'])) {
+                        $week_appoints = VaccineAppoint::where('vaccine_id', $req['vaccine_id'])->pluck('week_appoint')->toArray();
+                        if (!empty($week_appoints)) {
+                            $start_time = strtotime($v1['schedule_date'].' '.$v1['time_period']['start_time_period'].':00');
+                            $week = date('N', $start_time);
+                            $period = (int)date('Hi', $start_time);
+                            $appoint = '1'.$week;
+                            if ($period >= 1200) {
+                                $appoint = '2'.$week;
+                            }
+                            if (!in_array($appoint, $week_appoints)) {
+                                $v1['can_appoint'] = 0;
+                            }
+                        }
+                    }
                     //预约时间已经过了,就不展示了
                     $schedule_time = strtotime($v1['schedule_date'].' '.$v1['time_period']['end_time_period'].':00');
                     if ($schedule_time < time()) {