Browse Source

医生端,排班

lizhen_gitee 11 months ago
parent
commit
6475e1feed
1 changed files with 47 additions and 1 deletions
  1. 47 1
      application/api/controller/doctor/Index.php

+ 47 - 1
application/api/controller/doctor/Index.php

@@ -17,7 +17,7 @@ class Index extends Apic
     protected $noNeedLogin = [];
     protected $noNeedRight = '*';
 
-
+    //获取排班详情
     public function paiban_info(){
         $today = date('Y-m-d');
         $today_start = strtotime(date('Y-m-d'));
@@ -79,6 +79,52 @@ class Index extends Apic
 
     }
 
+    //修改排班
+    public function paiban_edit(){
+        $active_data = input('active_data','','htmlspecialchars_decode');
+        if(!$active_data){
+            $this->error();
+        }
+
+        $active_data = json_decode($active_data,true);
+        if(!is_array($active_data)){
+            $this->error();
+        }
+
+        $old_active = [];//需要删除的
+        foreach($active_data as $key => $val){
+
+            if(!isset($val['activetime']) || !isset($val['active']) || empty($val['activetime'])){continue;}
+            $val['active'] = $val['active'] == 1 ? 1 : 0;
+
+            $old_active[] = $val['activetime'];
+
+            //需要新增的
+            $data = [
+                'doctor_id'  => $this->auth->id,
+                'activetime' => $val['activetime'],
+                'active'     => $val['active'],
+            ];
+
+            $all_data[] = $data;
+        }
+
+        Db::startTrans();
+        $rs_del = Db::name('doctor_paiban')->where('doctor_id',$this->auth->id)->where('activetime','IN',$old_active)->delete();
+        if($rs_del === false){
+            Db::rollback();
+            $this->error('设置失败');
+        }
+
+        $rs_add = Db::name('doctor_paiban')->insertAll($all_data);
+        if($rs_add === false){
+            Db::rollback();
+            $this->error('设置失败');
+        }
+
+        Db::commit();
+        $this->success('设置成功');
+    }