瀏覽代碼

修复日排班

liuyuanhang 4 年之前
父節點
當前提交
8d90383aa5
共有 1 個文件被更改,包括 19 次插入3 次删除
  1. 19 3
      app/Http/Controllers/Api/V2/DoctorController.php

+ 19 - 3
app/Http/Controllers/Api/V2/DoctorController.php

xqd xqd xqd
@@ -2112,8 +2112,6 @@ class DoctorController extends AuthController
 
 
 
-
-
     /**
      * 修改某一天的数据
      * @author Liu-Yh
@@ -2141,16 +2139,19 @@ class DoctorController extends AuthController
         DB::beginTransaction();
         try {
             $type_data = json_decode($req['type'],true);
+
             $where = [];
             $where['schedule_date'] = $req['schedule_date'];
             $where['docter_id'] = $doctor_id;
             $where['schedule_type'] = 1;
             $where['organization_id'] = $req['organization_id'];
+
             if ($type_data['mon']==0&&$type_data['aft']==0&&$type_data['nig']==0){
                 // 进行删除
                 unset($where['organization_id']);
                 SchedulePeriod::where($where)->delete();
                 Schedule::where($where)->delete();
+                DB::commit();
                 return out();
             }
             SchedulePeriod::where($where)->delete();
@@ -2187,11 +2188,26 @@ class DoctorController extends AuthController
 
             if (!$flag){
                 $lists = Schedule::where(['docter_id'=>$doctor_id,'schedule_date'=>$req['schedule_date']])->first();
+                $schedule_id = 0;
                 if($lists){
+                    $schedule_id = $lists['id'];
+                }else{
+                    $lists2 = Schedule::create(['schedule_type'=>1,'schedule_date'=>$req['schedule_date'],'schedule_day'=>str_replace('-','/',$req['schedule_date']),'week'=>$req['week'],'docter_id'=>$doctor_id,'organization_id'=>0,'per_time_num'=>0]);
+                    if ($lists2){
+                        $schedule_id = $lists2['id'];
+                    }else{
+                        return out('', 500, "日期增加失败");
+
+                    }
+                }
+
+
+
+                if($schedule_id){
                     if($save_data){
                         $chong = [];
                         foreach ($save_data as $k => $v) {
-                            $chong[$k]['schedule_id'] = $lists['id'];
+                            $chong[$k]['schedule_id'] = $schedule_id;
                             $chong[$k]['docter_id'] = $v['docter_id'];
                             $chong[$k]['order_num'] = 0;
                             $chong[$k]['organization_id'] = $v['organization_id'];