Browse Source

schedulePeriodList

Mike 4 years ago
parent
commit
b3e57081dd
1 changed files with 61 additions and 6 deletions
  1. 61 6
      app/Http/Controllers/Api/V1/DocterController.php

+ 61 - 6
app/Http/Controllers/Api/V1/DocterController.php

xqd xqd xqd
@@ -176,6 +176,44 @@ class DocterController extends AuthController
         return ($data);
     }
 
+//    public function schedulePeriodList()
+//    {
+//        $req = request()->post();
+//        $this->validate(request(), [
+//            'docter_id' => 'required|integer',
+//            'organization_id' => 'integer',
+//            'per_page' => 'integer',
+//            'latitude' => 'numeric',
+//            'longitude' => 'numeric',
+//        ]);
+//        $user = $this->user;
+//        //todo Schedule表 考虑是否有必要性,日期可以通过timePeriod取到。
+//        $builder = Schedule::with(['schedulePeriod.timePeriod', 'schedulePeriod.organization'])->where('docter_id', $req['docter_id'])->where('schedule_day', '>=', date('Ymd'));
+//        if (!empty($req['organization_id'])) {
+//            $builder->where('organization_id', $req['organization_id']);
+//        }
+//        $data = $builder->paginate($req['per_page']??15)->toArray();
+//        if (!empty($data)) {
+//            foreach ($data['data'] as $k => &$v) {
+//                foreach ($v['schedule_period'] as $k1 => &$v1) {
+//                    if (!empty($v1['organization'])) {
+//                        $v1['organization']['distance'] = get_user_distance($user, $v1['organization']['latitude'], $v1['organization']['longitude']);
+//                    }
+//                    $docterSettings = DocterSetting::select(['service_num'])->where('docter_id', $req['docter_id'])->where('type', 1)->where('org_id', $v1['organization_id'])->first();
+//                    if (empty($docterSettings)) {
+//                        $v1['can_appoint_num'] = 0;
+//                    }
+//                    else {
+//                        $can_appoint_num = $docterSettings['service_num'] - $v1['order_num'];
+//                        $v1['can_appoint_num'] = $can_appoint_num < 0 ? 0 : $can_appoint_num;
+//                    }
+//                }
+//            }
+//        }
+//
+//        return out($data);
+//    }
+
     public function schedulePeriodList()
     {
         $req = request()->post();
@@ -187,15 +225,16 @@ class DocterController extends AuthController
             'longitude' => 'numeric',
         ]);
         $user = $this->user;
-        //todo Schedule表 考虑是否有必要性,日期可以通过timePeriod取到。
-        $builder = Schedule::with(['schedulePeriod.timePeriod', 'schedulePeriod.organization'])->where('docter_id', $req['docter_id'])->where('schedule_day', '>=', date('Ymd'));
+        $builder = schedulePeriod::with(['timePeriod', 'organization'])->where('docter_id', $req['docter_id'])->where('schedule_date', '>=', date('Y-m-d'));
         if (!empty($req['organization_id'])) {
             $builder->where('organization_id', $req['organization_id']);
         }
         $data = $builder->paginate($req['per_page']??15)->toArray();
+        //日期有重复,不同机构排班
+        $newdata = array();
         if (!empty($data)) {
-            foreach ($data['data'] as $k => &$v) {
-                foreach ($v['schedule_period'] as $k1 => &$v1) {
+//            foreach ($data['data'] as $k => &$v) {
+                foreach ($data as $k1 => $v1) {
                     if (!empty($v1['organization'])) {
                         $v1['organization']['distance'] = get_user_distance($user, $v1['organization']['latitude'], $v1['organization']['longitude']);
                     }
@@ -207,11 +246,27 @@ 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;
                     }
+
+                    if(empty($newdata[$v1['time_period']])){
+                        $newdata[$v1['schedule_date']] = $v1;
+                    }else{
+                        $newd = $newdata[$v1['schedule_date']];
+                        foreach ($newd['time_period'] as $k2 => $v2) {
+                            array_push($v1['time_period'],$v2);
+                        }
+                        $newdata[$v['schedule_date']] = $v1;
+
+                    }
                 }
-            }
+
+//            }
+        }
+        $res = array();
+        foreach ($newdata as $v) {
+            if (!empty($v['time_period']))$res[] = $v;
         }
 
-        return out($data);
+        return out($res);
     }
 
     public function timePeriodList()