浏览代码

Merge branch 'master' of http://git.9026.com/swdz-WangHaijun/BaoMa

ChenWuJie 4 年之前
父节点
当前提交
ce5f7f9af9
共有 2 个文件被更改,包括 97 次插入99 次删除
  1. 36 38
      app/Community/Controllers/ApiController.php
  2. 61 61
      app/Http/Controllers/Api/V1/DocterController.php

+ 36 - 38
app/Community/Controllers/ApiController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -342,10 +342,10 @@ class ApiController extends Controller
         }
 
         $docter_setting = DocterSetting::where(['docter_id'=>$docter_id,'org_id'=>$org_id,'type'=>$sType])->first();
-        $serviceNum = 0;
+//        $serviceNum = 0;
         $times = [];
         if(!empty($docter_setting)){
-            $serviceNum = $docter_setting->service_num;
+//            $serviceNum = $docter_setting->service_num;
             $time_period = object_array(json_decode($docter_setting->service_time));
             $allCount = TimePeriod::where(['docter_id'=>$docter_id,'org_id'=>$org_id])->count();
             if($allCount == 0) return apiReturn(603,'请设置时间段');
@@ -413,23 +413,23 @@ class ApiController extends Controller
             DB::rollBack();
             return apiReturn(602,$e->getLine().'行'.$e->getMessage());
         }
-        self::setmonthScheduel($docter_id,$org_id,$sType,$serviceNum,$times);
+        self::setmonthScheduel($docter_id,$org_id,$sType,$times);
 
         return apiReturn(200,'ok',$k);
     }
 
     //设置月排班
-    public function setmonthScheduel($docterId,$orgId,$sType,$serviceNum,$timePeriods)
+    public function setmonthScheduel($docterId,$orgId,$sType,$timePeriods)
     {
 
         $today = intval(date('Ymd',time()));
         $start = time();
 
         //删除排班
-        $schedule_ids = Schedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId])->where('schedule_day','>',$today)->pluck('id')->toArray();
-        Schedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId])->where('schedule_day','>',$today)->delete();
+        $schedule_ids = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_day','>',$today)->pluck('id')->toArray();
+//        Schedule::where(['docter_id'=>$docterId])->where('schedule_day','>',$today)->delete();
         //删除具体排班
-        SchedulePeriod::whereIn('schedule_id',$schedule_ids)->delete();
+        SchedulePeriod::where('organization_id',$orgId)->whereIn('schedule_id',$schedule_ids)->delete();
         $allScheduleData = [];
         //插入两个月的数据
         for ($i=1;$i<60;$i++){
@@ -440,24 +440,24 @@ class ApiController extends Controller
             $scheduleData['docter_id'] = $docterId;
             $scheduleData['schedule_date'] = $date;
             $scheduleData['schedule_day'] = $numDate;
-            $scheduleData['organization_id'] = $orgId;
+            $scheduleData['schedule_type'] = $sType;
 
             $scheduleIsHave = Schedule::where($scheduleData)->count();
-            $scheduleData['per_time_num'] = $serviceNum;
+//            $scheduleData['per_time_num'] = $serviceNum;
             //循环外批量插入
             if (!$scheduleIsHave) $allScheduleData[] = $scheduleData;
         }
         if($allScheduleData) Schedule::insert($allScheduleData);
 
 //        echo '医生id '.$docterId.' 机构id '.$orgId . 'times ';
-        $schedule = Schedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId])->where('schedule_date','>=',date('Y-m-d',time()))
+        $schedule = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_date','>=',date('Y-m-d',time()))
             ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
 
         $allData = [];
         for($tType = 1; $tType<=3 ; $tType++){
             foreach ($schedule as $id => $date) {
                 $week = intval(date('N', strtotime($date)));
-                $real_id = WeekSchedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'week'=>$week,'type'=>$tType])->first();
+                $real_id = WeekSchedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_type'=>$sType,'week'=>$week,'type'=>$tType])->first();
                 if (!empty($real_id)) {
                     foreach ($timePeriods[$tType-1] as $idt) {
                         $s_t= [
@@ -471,7 +471,7 @@ class ApiController extends Controller
                         ];
 
                         $scheduleIsHave = SchedulePeriod::where($s_t)->count();
-                        $s_t['order_num'] = $serviceNum;
+                        $s_t['order_num'] = 0;
                         if (!$scheduleIsHave) $allData[] = $s_t;
 
                     }
@@ -484,8 +484,8 @@ class ApiController extends Controller
 
         //删除 Schedule里面SchedulePeriod 没有的日期
         foreach ($schedule as $date) {
-            $c = SchedulePeriod::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_type'=> $sType])->where('schedule_date',$date)->count();
-            if($c==0) Schedule::where('schedule_date',$date)->delete();
+            $c = SchedulePeriod::where(['docter_id'=>$docterId,'schedule_date'=>$date,'schedule_type'=> $sType])->count();
+            if($c==0) Schedule::where(['docter_id'=>$docterId,'schedule_date'=>$date,'schedule_type' => $sType])->delete();
         }
         return apiReturn('200','ok');
 
@@ -694,7 +694,7 @@ class ApiController extends Controller
         $Today = date('Y-m-d',time());
 
         //同时服务人数
-        $serviceNum = intval($configData['serviceNum']);
+//        $serviceNum = intval($configData['serviceNum']);
 
         //服务时长
         $serviceTime = intval($configData['timeSpan']);
@@ -764,11 +764,12 @@ class ApiController extends Controller
 //                $timeCount = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id])->count();
 //                if($timeCount == 0) return apiReturn(603,'请设置时间段');
 
+                $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period',$times[$tType])->pluck('id')->toArray();
+                $schedule = Schedule::where(['docter_id' => $docter_id,'schedule_type' => $sType])->pluck('schedule_date', 'id')->toArray();
+                $self_schedule = SelfSchedule::where(['docter_id' => 0, 'schedule_type' => $sType,'organization_id'=>$org_id,'type' =>$tType])->distinct('type')
+                    ->orderBy('schedule_date')->where('schedule_date','>',$Today)->get(['schedule_date', 'type', 'week'])->toArray();
+
                 if($sType == 1){
-                    $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period',$times[$tType])->pluck('id')->toArray();
-                    $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $sType, 'organization_id'=>$org_id,'type' =>$tType])->distinct('type')
-                        ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
-                    $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id'=>0])->pluck('schedule_date', 'id')->toArray();
                     $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType,'schedule_type'=>$sType])
                         ->distinct('type')
                         ->orderBy('week')
@@ -776,10 +777,7 @@ class ApiController extends Controller
                         ->GroupBy('week')
                         ->toArray();
                 } else {
-                    $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => 0, 'type' =>$sType])->whereBetween('end_time_period',$times[$tType])->pluck('id')->toArray();
-                    $schedule = Schedule::where(['docter_id' => 0, 'organization_id'=>$org_id])->pluck('schedule_date', 'id')->toArray();
-                    $self_schedule = SelfSchedule::where(['docter_id' => 0, 'schedule_type' => $sType,'organization_id'=>$org_id,'type' =>$tType])->distinct('type')
-                        ->orderBy('schedule_date')->where('schedule_date','>',$Today)->get(['schedule_date', 'type', 'week'])->toArray();
+
                     $week_schedule = WeekSchedule::where(['organization_id' =>$org_id, 'type' => $tType,'schedule_type'=>$sType])
                         ->distinct('type')
                         ->orderBy('week')
@@ -794,7 +792,7 @@ class ApiController extends Controller
                     // SelfSchedule::where(['docter_id' => $docter_id])->delete();
                 } else {
                     //3.以周模板添加2个月的数据
-                    self::makeSchedule($sType,$docter_id,$org_id,$tType,$schedule,$time_periods,$serviceNum);
+                    self::makeSchedule($sType,$docter_id,$org_id,$tType,$schedule,$time_periods);
 
                     //4.恢复自己设置的排班
                     self::makeSelfScheeule($docter_id,$org_id,$sType,$tType,$time_periods,$self_schedule);
@@ -932,7 +930,7 @@ class ApiController extends Controller
     }
 
     //以周模板进行排班
-    public static function makeSchedule ($sType,$docterId,$orgId,$tType,$schedule,$timePeriods,$serviceNum){
+    public static function makeSchedule ($sType,$docterId,$orgId,$tType,$schedule,$timePeriods){
 
         if(empty($schedule) || count($schedule) < 58){
             $start = strtotime(date('Y-m-1',time()));
@@ -949,10 +947,10 @@ class ApiController extends Controller
                 $scheduleData['docter_id'] = $docterId;
                 $scheduleData['schedule_date'] = $date;
                 $scheduleData['schedule_day'] = $numDate;
-                $scheduleData['organization_id'] = $orgId;
+                $scheduleData['schedule_type'] = $sType;
 
                 $scheduleIsHave = Schedule::where($scheduleData)->count();
-                $scheduleData['per_time_num'] = $serviceNum;
+//                $scheduleData['per_time_num'] = $serviceNum;
                 if (!$scheduleIsHave)  Schedule::insert($scheduleData);
 
             }
@@ -969,19 +967,19 @@ class ApiController extends Controller
                 $scheduleData['docter_id'] = $docterId;
                 $scheduleData['schedule_date'] = $date;
                 $scheduleData['schedule_day'] = $numDate;
-                $scheduleData['organization_id'] = $orgId;
+                $scheduleData['schedule_type'] = $sType;
                 $scheduleIsHave = Schedule::where($scheduleData)->count();
-                $scheduleData['per_time_num'] = $serviceNum;
+//                $scheduleData['per_time_num'] = $serviceNum;
                 if (!$scheduleIsHave)  Schedule::insert($scheduleData);
             }
 
             //todo 插入第三个月后的当日号
-            $schedule = Schedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId])->where('schedule_date','>=',date('Y-m-d',time()))
+            $schedule = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_date','>=',date('Y-m-d',time()))
                 ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
-            if($docterId == 0){
-                $schedule = Schedule::where(['docter_id'=>0,'organization_id'=>$orgId])->where('schedule_date','>=',date('Y-m-d',time()))
-                    ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
-            }
+//            if($docterId == 0){
+//                $schedule = Schedule::where(['docter_id'=>0,'schedule_type'=>$sType])->where('schedule_date','>=',date('Y-m-d',time()))
+//                    ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
+//            }
         }
 
         //
@@ -1003,7 +1001,7 @@ class ApiController extends Controller
                             'time_period_id' => $idt
                         ];
                         $scheduleIsHave = SchedulePeriod::where($s_t)->count();
-                        $s_t['order_num'] = $serviceNum;
+                        $s_t['order_num'] = 0;
                         if ($scheduleIsHave) continue;
                         $allData []  = $s_t;
                     }
@@ -1027,7 +1025,7 @@ class ApiController extends Controller
             $self_data['organization_id'] = $orgId;
             $self_data['docter_id'] = $docterId;
             $self_data['schedule_type'] = $sType;
-            $s_id = Schedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_date'=>$val['schedule_date']])->value('id');
+            $s_id = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType,'schedule_date'=>$val['schedule_date']])->value('id');
             $numDay = intval(str_replace('-','',$val['schedule_date']));
 //            if(empty($s_id)) {
 //                Schedule::insert(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_date'=>$val['schedule_date'],'schedule_day'=>$numDay]);
@@ -1102,7 +1100,7 @@ class ApiController extends Controller
 
                 if($v['status'] == true){
                     $num_date = intval(date('Ymd',strtotime($today)));
-                    $sche_data = ['docter_id'=>intval($docter_id),'organization_id'=>$org_id,'schedule_date'=>$today,'schedule_day'=>$num_date];
+                    $sche_data = ['docter_id'=>intval($docter_id),'schedule_type'=>$sType,'schedule_date'=>$today,'schedule_day'=>$num_date];
                     //判断是否有排班信息
                     $s_id = Schedule::where($sche_data)->count();
                     if(!$s_id){
@@ -1166,7 +1164,7 @@ class ApiController extends Controller
 //                    if(!$week_schedule) continue;
 //
 //                    //删除排班日期
-                        $s_id = Schedule::where(['schedule_date'=>$today,'docter_id'=>$docter_id,'organization_id'=>$org_id])->value('id');
+                        $s_id = Schedule::where(['schedule_date'=>$today,'schedule_type'=>$sType,'docter_id'=>$docter_id])->value('id');
                         unset($data['type']);
                         $scount = SelfSchedule::where($data)->count();
                         $pcount = SchedulePeriod::where($data)->count();

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

xqd xqd xqd
@@ -176,44 +176,6 @@ 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();
@@ -225,16 +187,15 @@ class DocterController extends AuthController
             'longitude' => 'numeric',
         ]);
         $user = $this->user;
-        $builder = schedulePeriod::with(['timePeriod', 'organization'])->where('docter_id', $req['docter_id'])->where('schedule_date', '>=', date('Y-m-d'));
+        //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();
-        //日期有重复,不同机构排班
-        $newdata = array();
         if (!empty($data)) {
-//            foreach ($data['data'] as $k => &$v) {
-                foreach ($data as $k1 => $v1) {
+            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']);
                     }
@@ -246,29 +207,68 @@ 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($res);
+        return out($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;
+//        $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 ($data 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;
+//                    }
+//
+//                    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($res);
+//    }
+
     public function timePeriodList()
     {
         $req = request()->post();