Browse Source

周排班逻辑优化

Swdz-WangHaiJun 4 years ago
parent
commit
637929e909

+ 22 - 16
app/Community/Controllers/ApiController.php

xqd xqd xqd xqd xqd xqd xqd
@@ -277,8 +277,7 @@ class ApiController extends Controller
 
         if($type == 1){
             if($role == 2){
-                for ($i=0;$i<=7;$i++){
-                    if($i == 0) continue;
+                for ($i=1;$i<=7;$i++){
                     for($j=0;$j<=2;$j++){
                         $is_self_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'organization_id'=>$org_id,'week'=>$i,'type'=>$j+1])->count();
                         $is_other_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'week'=>$i,'type'=>$j+1])->where('organization_id','!=',$org_id)->count();
@@ -376,14 +375,14 @@ class ApiController extends Controller
                         $new_week_data = $week_data;
                         $new_week_data ['type'] = $i;
                         $new_week_data ['week'] = $key;
-                        $k++;
 //                        echo '时间列类型'.($i+1).'----'.$key.'星期数'.'<br>';
                         foreach ($times[$i-1] as $id){
                             $new_week_data['time_period_id'] = $id;
-                            $is_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'type'=>$i,'week'=>$key,'organization_id'=>$org_id])
+                            $is_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'type'=>$i,'week'=>$key,'time_period_id'=>$id])
                                 ->where('time_period_id',$id)->value('id');
                             if($is_have) continue;
                             WeekSchedule::insert($new_week_data);
+                            $k++;
                         }
                     } else if ($schedule == false) {
                         if($type == 1){
@@ -393,8 +392,8 @@ class ApiController extends Controller
                             $is_have = WeekSchedule::where(['docter_id' => 0, 'organization_id' => $org_id, 'schedule_type' => $type,'type'=>$i,'week'=>$key])->whereIn('time_period_id', $times[$i-1])->value('id');
                             if($is_have) WeekSchedule::where(['docter_id' => 0, 'organization_id' => $org_id, 'schedule_type' => $type,'type'=>$i,'week'=>$key])->whereIn('time_period_id', $times[$i-1])->delete();
                         }
+//                        $k++;
                     }
-                    $k++;
 
                 }
             }
@@ -753,6 +752,7 @@ class ApiController extends Controller
         $setting  = DocterSetting::where(['docter_id'=>$docter_id,'org_id'=>$org_id])->first();
         if($type != 1){
             $setting = OrganizationSettings::where(['org_id'=>$org_id])->first();
+            $docter_id = 0;
         }
 
         $self_config = object_array(json_decode($setting['service_time']));
@@ -815,9 +815,7 @@ class ApiController extends Controller
             DB::beginTransaction();
             try {
                 //1.删除旧时间段,并删除排班数据
-                if($type !=1 ){
-                    $docter_id = 0;
-                }
+
                 //todo 暂时未删除周排班
                 self::deleteScheduleInfo($docter_id,$tType,$org_id);
                 $count = $countArr[$i];
@@ -1013,6 +1011,7 @@ class ApiController extends Controller
     //以周模板进行排班
     public static function makeSchedule ($docterId,$orgId,$tType,$schedule,$timePeriods,$serviceNum){
 
+
         if(empty($schedule) || count($schedule) < 58){
             $start = strtotime(date('Y-m-1',time()));
             $today = date('j',time());
@@ -1025,37 +1024,44 @@ class ApiController extends Controller
 
                 $date = date('Y-m-d',$todayTimer);
                 $numDate = date('Ymd',$todayTimer);
+                $scheduleData['docter_id'] = $docterId;
                 $scheduleData['schedule_date'] = $date;
                 $scheduleData['schedule_day'] = $numDate;
+                $scheduleData['organization_id'] = $orgId;
 
                 $scheduleIsHave = Schedule::where($scheduleData)->count();
-                if ($scheduleIsHave) continue;
-                Schedule::insertGetId($scheduleData);
+                $scheduleData['per_time_num'] = $serviceNum;
+                if (!$scheduleIsHave)  Schedule::insert($scheduleData);
+
             }
             $nextStart = strtotime(date('Y-m-1',strtotime('next month')));
             $nextAllDay = date('t',strtotime('nex month'));
 
-
             //第二个月
             for($j=1;$j<=$nextAllDay;$j++){
                 $todayTimer = $nextStart + (($j-1)*86400);
                 $week = date('N',$todayTimer);
                 $date = date('Y-m-d',$todayTimer);
                 $numDate = date('Ymd',$todayTimer);
+                $scheduleData['docter_id'] = $docterId;
                 $scheduleData['schedule_date'] = $date;
                 $scheduleData['schedule_day'] = $numDate;
+                $scheduleData['organization_id'] = $orgId;
                 $scheduleIsHave = Schedule::where($scheduleData)->count();
-                if ($scheduleIsHave) continue;
-                Schedule::insertGetId($scheduleData);
+                $scheduleData['per_time_num'] = $serviceNum;
+                if (!$scheduleIsHave)  Schedule::insert($scheduleData);
+
             }
-            $schedule = Schedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId])->where('schedule_date','>',date('Y-m-d',time()))
+
+            //todo 插入第三个月后的当日号
+
+            $schedule = Schedule::where(['docter_id'=>$docterId,'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,'organization_id'=>$orgId])->where('schedule_date','>',date('Y-m-d',time()))
+                $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();
             }
         }
-
         foreach ($schedule as $id => $date) {
             $week = intval(date('N', strtotime($date)));
 //            echo '医生id '.$docterId.' 机构id '.$orgId.' 周几 '.$week;

File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.545de3dc.js


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.545de3dc.js.map


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.857d2f8e.js


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.857d2f8e.js.map


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.907254c1.js


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.907254c1.js.map


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.cde6b82d.js


File diff suppressed because it is too large
+ 0 - 0
public/cdms/static/js/app.cde6b82d.js.map


+ 1 - 1
resources/views/cdms/schedule.blade.php

xqd
@@ -1 +1 @@
-<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>scheduling</title><link href="static/css/app.b0dfcc84.css" rel="preload" as="style"><link href="static/css/chunk-vendors.767f701c.css" rel="preload" as="style"><link href="static/js/app.857d2f8e.js" rel="preload" as="script"><link href="static/js/chunk-vendors.feab90c7.js" rel="preload" as="script"><link href="static/css/chunk-vendors.767f701c.css" rel="stylesheet"><link href="static/css/app.b0dfcc84.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but scheduling doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="static/js/chunk-vendors.feab90c7.js"></script><script src="static/js/app.857d2f8e.js"></script></body></html>
+<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>scheduling</title><link href="static/css/app.b0dfcc84.css" rel="preload" as="style"><link href="static/css/chunk-vendors.767f701c.css" rel="preload" as="style"><link href="static/js/app.907254c1.js" rel="preload" as="script"><link href="static/js/chunk-vendors.feab90c7.js" rel="preload" as="script"><link href="static/css/chunk-vendors.767f701c.css" rel="stylesheet"><link href="static/css/app.b0dfcc84.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but scheduling doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="static/js/chunk-vendors.feab90c7.js"></script><script src="static/js/app.907254c1.js"></script></body></html>

Some files were not shown because too many files changed in this diff