| xqd
@@ -547,83 +547,88 @@ class ApiController extends Controller
|
|
|
$week = date('N',$start_time + ($i-1) * 86400);
|
|
|
$scheduleDate = date('Y-m-d',$start_time + ($i-1) * 86400);
|
|
|
|
|
|
- if(empty($schedule_data)){
|
|
|
- $scheduleList[] = [
|
|
|
- 'schedulelingList'=>$baseData,
|
|
|
- 'date'=>$i,
|
|
|
- 'week'=>$week,
|
|
|
- 'day'=>$scheduleDate
|
|
|
- ];
|
|
|
- } else {
|
|
|
+ $scheduleList[$i-1] = [
|
|
|
+ 'schedulelingList'=>$baseData,
|
|
|
+ 'date'=>$i,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
|
|
|
+ $newBase = $baseData;
|
|
|
+
|
|
|
+ if($type == 1){//门诊
|
|
|
+ $today = SchedulePeriod::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'organization_id'=>$org_id])->distinct('organization_id')
|
|
|
+ ->distinct('type')->get(['organization_id','type'])->GroupBy('type')->toArray();
|
|
|
|
|
|
- if($type == 1){//门诊
|
|
|
- $today = SchedulePeriod::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate])->where('organization_id','=',$org_id)->distinct('organization_id')
|
|
|
- ->distinct('type')->get(['organization_id','type'])->GroupBy('type')->toArray();
|
|
|
- $self = SelfSchedule::where(['schedule_date'=>$scheduleDate,'docter_id'=>$docter_id,'organization_id'=>$org_id])
|
|
|
- ->pluck('type','organization_id')->toArray();
|
|
|
// //检查排班详情
|
|
|
// self::checkDaySchedule($date,$type,$docter_id,$org_id);
|
|
|
// //检查自己排班
|
|
|
// self::checkSelfDaySchedule($date,$type,$docter_id,$org_id);
|
|
|
// echo '周几'.$week.' 日期 '.$scheduleDate.PHP_EOL;
|
|
|
|
|
|
- if(empty($today)){
|
|
|
- $scheduleList[] = [
|
|
|
- 'schedulelingList'=>$baseData,
|
|
|
- 'date'=>$i,
|
|
|
- 'week'=>$week,
|
|
|
- 'day'=>$scheduleDate
|
|
|
- ];
|
|
|
- } else {
|
|
|
+ if(empty($today)){
|
|
|
+ $scheduleList[$i-1] = [
|
|
|
+ 'schedulelingList'=>$baseData,
|
|
|
+ 'date'=>$i,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
// echo '周几'.$week.' 日期 '.$scheduleDate;
|
|
|
- $newBase =$baseData;
|
|
|
// dump($today);
|
|
|
- foreach ($today as $tType => $orginfo){
|
|
|
- $orgids = array_column($orginfo,'organization_id');
|
|
|
- $idSum = array_sum($orgids);
|
|
|
- if($org_id == $idSum) $newBase[$tType-1]['status'] = true;
|
|
|
- if($org_id != $idSum) $newBase[$tType-1]['status'] = 'other';
|
|
|
- if(in_array($tType,$self))
|
|
|
- foreach($self as $key=>$org){
|
|
|
- $newBase[$tType-1]['status'] = true;
|
|
|
- if($org != $org_id) $newBase[$tType-1]['status'] = 'other';
|
|
|
- }
|
|
|
- }
|
|
|
-// dump($newBase);
|
|
|
- $scheduleList[] = [
|
|
|
- 'schedulelingList'=>$newBase,
|
|
|
- 'date'=>$i,
|
|
|
- 'week'=>$week,
|
|
|
- 'day'=>$scheduleDate
|
|
|
- ];
|
|
|
+ foreach ($today as $tType => $orginfo){
|
|
|
+ $orgids = array_column($orginfo,'organization_id');
|
|
|
+ $idSum = array_sum($orgids);
|
|
|
+ if($org_id == $idSum) $newBase[$tType-1]['status'] = true;
|
|
|
+ if($org_id != $idSum) $newBase[$tType-1]['status'] = 'other';
|
|
|
}
|
|
|
- } else {
|
|
|
- $today = SchedulePeriod::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate])->where('organization_id','!=',0)->distinct('organization_id')
|
|
|
- ->distinct('type')->get(['organization_id','type'])->GroupBy('type')->toArray();
|
|
|
+//
|
|
|
+ }
|
|
|
+ //覆盖自定义排班
|
|
|
+ $self = SelfSchedule::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'organization_id'=>$org_id])->get(['type'])->GroupBy('type')->toArray();
|
|
|
+ if(!empty($self)){
|
|
|
+ foreach($self as $k=>$sf){
|
|
|
+ $newBase[$k-1]['status'] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scheduleList[$i-1] = [
|
|
|
+ 'schedulelingList'=>$newBase,
|
|
|
+ 'date'=>$i,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $today = SchedulePeriod::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate])->where('organization_id','!=',0)->distinct('organization_id')
|
|
|
+ ->distinct('type')->get(['organization_id','type'])->GroupBy('type')->toArray();
|
|
|
|
|
|
- if(empty($today)){
|
|
|
- $scheduleList[] = [
|
|
|
- 'schedulelingList'=>$baseData,
|
|
|
- 'date'=>$i,
|
|
|
- 'week'=>$week,
|
|
|
- 'day'=>$scheduleDate
|
|
|
- ];
|
|
|
- } else {
|
|
|
- foreach ($today as $type => $orginfo){
|
|
|
- $orgids = array_column($orginfo,'organization_id');
|
|
|
- $idSum = array_sum($orgids);
|
|
|
- if($org_id == $idSum) $baseData[$type]['status'] = true;
|
|
|
- if($org_id != $idSum) $baseData[$type]['status'] = 'other';
|
|
|
- }
|
|
|
- $scheduleList[] = [
|
|
|
- 'schedulelingList'=>$baseData,
|
|
|
- 'date'=>$i,
|
|
|
- 'week'=>$week,
|
|
|
- 'day'=>$scheduleDate
|
|
|
- ];
|
|
|
+ if(empty($today)){
|
|
|
+ $scheduleList[$i-1] = [
|
|
|
+ 'schedulelingList'=>$baseData,
|
|
|
+ 'date'=>$i,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ foreach ($today as $type => $orginfo){
|
|
|
+ $orgids = array_column($orginfo,'organization_id');
|
|
|
+ $idSum = array_sum($orgids);
|
|
|
+ if($org_id == $idSum) $newBase[$type]['status'] = true;
|
|
|
+ if($org_id != $idSum) $newBase[$type]['status'] = 'other';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //覆盖自定义排班
|
|
|
+ $self = SelfSchedule::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'organization_id'=>$org_id])->get(['type'])->GroupBy('type')->toArray();
|
|
|
+ if(!empty($self)){
|
|
|
+ foreach($self as $k=>$sf){
|
|
|
+ $newBase[$k-1]['status'] = true;
|
|
|
}
|
|
|
}
|
|
|
+ $scheduleList[$i-1] = [
|
|
|
+ 'schedulelingList'=>$newBase,
|
|
|
+ 'date'=>$i,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
}
|
|
|
//// if(empty( $schedule_data[$scheduleDate])) continue;
|
|
|
//// $schedule_id = $schedule_data[$schedule_data];
|
| xqd
@@ -1130,12 +1135,12 @@ class ApiController extends Controller
|
|
|
//todo 上线取消默认值
|
|
|
$schdule_data = request('schedule_data');
|
|
|
$docter_id = intval(request('docter_id'));
|
|
|
- $type = intval(request('type'));
|
|
|
+ $type = intval(request('type'));//排班类型 1门诊 2...
|
|
|
$org_id = intval(request('org_id'));
|
|
|
$date = request('date');
|
|
|
//判断排班类型
|
|
|
|
|
|
- if(empty($schdule_data) || empty($docter_id) || !isset($org_id) || empty($type)){
|
|
|
+ if(empty($schdule_data) || !isset($org_id) || empty($type)){
|
|
|
return apiReturn(601,'缺少必要参数');
|
|
|
}
|
|
|
//获取医生排班配置
|
| xqd
@@ -1149,23 +1154,22 @@ class ApiController extends Controller
|
|
|
}
|
|
|
|
|
|
|
|
|
- $schdule_data = [
|
|
|
- ['status'=>true,'type'=>1,'start'=>"09:00",'end'=>'11:30','date'=>15,'week'=>1],
|
|
|
- ['status'=>true,'type'=>2,'start'=>'13:30','end'=>'16:30','date'=>15,'week'=>1],
|
|
|
- ['status'=>false,'type'=>3,'start'=>'19:30','end'=>'21:00','date'=>15,'week'=>1],
|
|
|
- ];
|
|
|
+// $schdule_data = [
|
|
|
+// ['status'=>true,'type'=>1,'start'=>"09:00",'end'=>'11:30','date'=>15,'week'=>1],
|
|
|
+// ['status'=>true,'type'=>2,'start'=>'13:30','end'=>'16:30','date'=>15,'week'=>1],
|
|
|
+// ['status'=>false,'type'=>3,'start'=>'19:30','end'=>'21:00','date'=>15,'week'=>1],
|
|
|
+// ];
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
- foreach ($schdule_data as $t=>$v){
|
|
|
+ foreach ($schedule['schedulelingList'] as $t=>$v){
|
|
|
|
|
|
- $today = date('Y-m-d',(strtotime($date) + (intval($v['date'])-1) *86400) );
|
|
|
- $week = $schdule_data[0]['week'];
|
|
|
- $num_date = intval(str_replace('-','',$today));
|
|
|
+ $today = $schedule['day'];
|
|
|
+ $week =$schedule['week'];
|
|
|
|
|
|
if($v['status'] == true){
|
|
|
+ $num_date = intval(date('Ymd',strtotime($today)));
|
|
|
$sche_data = ['organization_id'=>$org_id,'schedule_date'=>$today,'schedule_day'=>$num_date];
|
|
|
-
|
|
|
//判断是否有排班信息
|
|
|
$s_id = Schedule::where($sche_data)->value('id');
|
|
|
if(!$s_id){
|
| xqd
@@ -1174,14 +1178,14 @@ class ApiController extends Controller
|
|
|
|
|
|
//获取时间段
|
|
|
$timeperiods = TimePeriod::where(['docter_id'=>intval($docter_id),'org_id'=>intval($org_id),'type'=>intval($v['type'])])->pluck('id')->toArray();
|
|
|
- if($type == 2){
|
|
|
- $timeperiods = TimePeriod::where(['docter_id'=>intval($docter_id),'org_id'=>0,'type'=>intval($v['type'])])->pluck('id')->toArray();
|
|
|
+ if($type != 1){
|
|
|
+ $timeperiods = TimePeriod::where(['docter_id'=>intval(0),'org_id'=>$org_id,'type'=>intval($v['type'])])->pluck('id')->toArray();
|
|
|
}
|
|
|
|
|
|
if(empty($timeperiods)){
|
|
|
return apiReturn(603,'没有时间段');
|
|
|
- self::setTimeperiod($type,$docter_id,$org_id);
|
|
|
- $timeperiods = self::getTypeTimeperiod($type,$docter_id,$org_id,intval($v['type']));
|
|
|
+// self::setTimeperiod($type,$docter_id,$org_id);
|
|
|
+// $timeperiods = self::getTypeTimeperiod($type,$docter_id,$org_id,intval($v['type']));
|
|
|
}
|
|
|
foreach ($timeperiods as $id){
|
|
|
$data = [
|
| xqd
@@ -1195,8 +1199,7 @@ class ApiController extends Controller
|
|
|
|
|
|
//检查是否已经有数据
|
|
|
$self_count = SelfSchedule::where($data)->value('id');
|
|
|
- if($self_count) continue;
|
|
|
- SelfSchedule::insert($data);
|
|
|
+ if(!$self_count) SelfSchedule::insert($data);
|
|
|
}
|
|
|
|
|
|
} else if($v['status'] == false){
|
| xqd
@@ -1211,17 +1214,19 @@ class ApiController extends Controller
|
|
|
$self_count = SelfSchedule::where($data)->count();
|
|
|
if($self_count) SelfSchedule::where($data)->delete();
|
|
|
|
|
|
- //检查是否是有周排班
|
|
|
- $week_schedule = WeekSchedule::where(['week'=>$week,'docter_id'=>$docter_id,'type'=>intval($v['type']),'organization_id'=>$org_id])->count();
|
|
|
- if(!$week_schedule) continue;
|
|
|
-
|
|
|
- //获取排班id
|
|
|
- $s_id = Schedule::where(['schedule_date'=>$today,'docter_id'=>$org_id])->value('id');
|
|
|
- if(!$s_id) continue;
|
|
|
+// //检查是否是有周排班
|
|
|
+// $week_schedule = WeekSchedule::where(['week'=>$week,'docter_id'=>$docter_id,'type'=>intval($v['type']),'organization_id'=>$org_id])->count();
|
|
|
+// if(!$week_schedule) continue;
|
|
|
+//
|
|
|
+// //获取排班id
|
|
|
+ $s_id = Schedule::where(['schedule_date'=>$today,'docter_id'=>$docter_id,'organization_id'=>$org_id])->value('id');
|
|
|
+ if($s_id) {
|
|
|
+ Schedule::where(['id'=>$s_id])->delete();
|
|
|
+ SchedulePeriod::where(['schedule_id'=>$s_id])->delete();
|
|
|
+ }
|
|
|
+// //删除排班和详细排班数据
|
|
|
|
|
|
- //删除排班和详细排班数据
|
|
|
- Schedule::where(['id'=>$s_id])->delete();
|
|
|
- TimePeriod::where(['docter_id'=>$docter_id,'org_id'=>$org_id,'type'=>$t,'schedule_id'=>$s_id])->delete();
|
|
|
+// TimePeriod::where(['docter_id'=>$docter_id,'org_id'=>$org_id,'type'=>$t,'schedule_id'=>$s_id])->delete();
|
|
|
}
|
|
|
}
|
|
|
DB::commit();
|