Browse Source

修改日排班

root 4 years ago
parent
commit
6e1326245d
2 changed files with 82 additions and 17 deletions
  1. 67 17
      app/Http/Controllers/Api/V2/DoctorController.php
  2. 15 0
      app/Models/SchedueFlags.php

+ 67 - 17
app/Http/Controllers/Api/V2/DoctorController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -44,6 +44,7 @@ use App\Models\DocterServiceTimes;
 use App\Models\CallLog;
 use App\Models\ImMessage;
 use App\Models\DocterLable;
+use App\Models\SchedueFlags as Sflag;
 
 /**
  * 医生相关类
@@ -654,7 +655,7 @@ class DoctorController extends AuthController
 
                                 $timeList = $this->getTimeHoures($v['service_times']);
                                 foreach ($timeList as $kk => $vv) {
-                                    $times_data[$k][$kk]['type'] = 2;
+                                    $times_data[$k][$kk]['type'] = 1;
                                     $times_data[$k][$kk]['docter_id'] = $doctor_id;
                                     $times_data[$k][$kk]['start_time_period'] = $vv[0];
                                     $times_data[$k][$kk]['end_time_period'] = $vv[1];
@@ -924,7 +925,7 @@ class DoctorController extends AuthController
                     // 第二步, 根据时长去生成24小时的时间段,也要存id
                     $timeList = $this->getTimeHoures($v['service_times']);
                     foreach ($timeList as $kk => $vv) {
-                        $times_data[$k][$kk]['type'] = 2;
+                        $times_data[$k][$kk]['type'] = 1;
                         $times_data[$k][$kk]['docter_id'] = $doctor_id;
                         $times_data[$k][$kk]['start_time_period'] = $vv[0];
                         $times_data[$k][$kk]['end_time_period'] = $vv[1];
@@ -1037,7 +1038,7 @@ class DoctorController extends AuthController
 
 
     /**
-     * 获取地区/联动医院
+     * 联动医院
      * Auth:Yuanhang-Liu
      * Date:2020/10/14 17:17 *
      * @return \Illuminate\Http\JsonResponse
@@ -2341,11 +2342,13 @@ class DoctorController extends AuthController
             $morningWhere[] = ['end_time_period', '<=', $zaoTimes[1]];
             $morningWhere['docter_id'] = $doctor_id;
             $morningWhere['org_id'] = $org_id;
-
             $morningd = TimePeriod::where($morningWhere)->get()->toArray();
+            if (count($morningd)>1){
+                array_pop($morningd);
+            }
 
-            array_pop($morningd);
             $morning = array_column($morningd, 'id');
+
             return $morning;
         } elseif ($type == 2) {
             $afternoondWhere[] = ['start_time_period', '>=', $zhongTimes[0]];
@@ -2353,7 +2356,9 @@ class DoctorController extends AuthController
             $afternoondWhere['docter_id'] = $doctor_id;
             $afternoondWhere['org_id'] = $org_id;
             $afternoond = TimePeriod::where($afternoondWhere)->get()->toArray();
-            array_pop($afternoond);
+            if (count($afternoond)>1){
+                array_pop($afternoond);
+            }
             $afternoon = array_column($afternoond, 'id');
             return $afternoon;
 
@@ -2363,7 +2368,9 @@ class DoctorController extends AuthController
             $nightWhere['docter_id'] = $doctor_id;
             $nightWhere['org_id'] = $org_id;
             $nightd = TimePeriod::where($nightWhere)->get()->toArray();
-            array_pop($nightd);
+            if (count($nightd)>1){
+                array_pop($nightd);
+            }
             $night = array_column($nightd, 'id');
             return $night;
 
@@ -2373,7 +2380,10 @@ class DoctorController extends AuthController
             $morningWhere['docter_id'] = $doctor_id;
             $morningWhere['org_id'] = $org_id;
             $morningd = TimePeriod::where($morningWhere)->get()->toArray();
-            array_pop($morningd);
+            if (count($morningd)>1){
+                array_pop($morningd);
+            }
+
             $morning = array_column($morningd, 'id');
 
             $afternoondWhere[] = ['start_time_period', '>=', $zhongTimes[0]];
@@ -2381,7 +2391,10 @@ class DoctorController extends AuthController
             $afternoondWhere['docter_id'] = $doctor_id;
             $afternoondWhere['org_id'] = $org_id;
             $afternoond = TimePeriod::where($afternoondWhere)->get()->toArray();
-            array_pop($afternoond);
+            if (count($afternoond)>1){
+                array_pop($afternoond);
+            }
+
             $afternoon = array_column($afternoond, 'id');
 
             $nightWhere[] = ['start_time_period', '>=', $wanTimes[0]];
@@ -2389,7 +2402,9 @@ class DoctorController extends AuthController
             $nightWhere['docter_id'] = $doctor_id;
             $nightWhere['org_id'] = $org_id;
             $nightd = TimePeriod::where($nightWhere)->get()->toArray();
-            array_pop($nightd);
+            if (count($nightd)>1){
+                array_pop($nightd);
+            }
             $night = array_column($nightd, 'id');
             return [$morning, $afternoon, $night];
         }
@@ -2660,6 +2675,11 @@ class DoctorController extends AuthController
 //        $type_data = explode(',', $req['type']);
         DB::beginTransaction();
         try {
+            $findFlag = Sflag::where(['docter_id'=>$doctor_id,'schedule_date'=>$req['schedule_date']])->first();
+            if (!$findFlag){
+                Sflag::create(['schedule_date'=>$req['schedule_date'],'docter_id'=>$doctor_id]);
+            }
+
             $type_data = json_decode($req['type'],true);
 
             $finds = SelfSchedule::where(['schedule_date' => $req['schedule_date'], 'docter_id' => $doctor_id, 'schedule_type' => 1])->delete();
@@ -2693,11 +2713,11 @@ class DoctorController extends AuthController
             }
 
 
+
             if (!$flag){
                 $lists = Schedule::where(['docter_id'=>$doctor_id,'schedule_date'=>$req['schedule_date']])->first();
-
-
                 if($lists){
+
                     SchedulePeriod::where(['docter_id'=>$doctor_id,'schedule_date'=>$req['schedule_date']])->delete();
                     if($save_data){
                         $chong = [];
@@ -2783,7 +2803,6 @@ class DoctorController extends AuthController
         $doctor_id = $user['id'];
         $selfScheduleList = SelfSchedule::where('docter_id', '=', $doctor_id)->get();
         $weekSchduleList = WeekSchedule::with('organization')->where('docter_id', '=', $doctor_id)->groupBy('type', 'week')->orderBy('week', 'asc')->get()->toArray();
-
         // 占用效率
         $scheduleLists = [];
         $moth_date = $this->date_bool($req['start_day'], $req['end_day']);
@@ -2848,6 +2867,8 @@ class DoctorController extends AuthController
             }
         }
         $newList = [];
+
+
         foreach ($moth_date as $k => $v) {
             $newList[$k]['date'] = $v['date'];
             $newList[$k]['ident']['zao'] = 0;
@@ -2863,10 +2884,20 @@ class DoctorController extends AuthController
             }
         }
 
+
         $selfList = [];
         if ($selfScheduleList) {
+            $putArr = [];
             // 自定义排班数组
             $selfScheduleList = $selfScheduleList->toArray();
+
+
+
+
+
+
+
+
             foreach ($selfScheduleList as $k => $v) {
                 if (!isset($selfList[$v['schedule_date']])) {
                     $selfList[$v['schedule_date']] = $v;
@@ -2893,7 +2924,29 @@ class DoctorController extends AuthController
                     }
                 }
             }
-
+            // 自定义的
+            $pusList = Sflag::where('docter_id',$doctor_id)->get();
+            //然后查看下自定义排班是否删除了
+            if ($pusList){
+                foreach ($pusList as $k=>$v){
+                    foreach ($selfScheduleList as $kk=>$vv){
+                        if ($v['schedule_date']==$vv['schedule_date']){
+                            unset($pusList[$k]);
+                        }
+                    }
+                }
+                foreach ($pusList as $k=>$v){
+                    $bl = [
+                        'schedule_date'=>$v['schedule_date'],
+                        'ident'=>[
+                            'zao_id'=>0,
+                            'xia_id'=>0,
+                            'wan_id'=>0,
+                        ],
+                    ];
+                    $selfList[$v['schedule_date']] = $bl;
+                }
+            }
             foreach ($selfList as $k => $v) {
                 foreach ($newList as $kk => $vv) {
                     if ($v['schedule_date'] == $vv['date']) {
@@ -2904,8 +2957,6 @@ class DoctorController extends AuthController
                     }
                 }
             }
-
-
         }
         return out($newList);
     }
@@ -2933,7 +2984,6 @@ class DoctorController extends AuthController
             $maf[$k]['type'] = $req['type'];
             $maf[$k]['order_num'] = 0;
         }
-
         return $maf;
     }
 

+ 15 - 0
app/Models/SchedueFlags.php

xqd
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: lyh
+ * Date: 20-10-4
+ * Time: 下午7:11
+ */
+
+namespace App\Models;
+
+class SchedueFlags extends BaseModel
+{
+    protected $table='schedue_flags';
+ 
+}