| xqd
@@ -137,60 +137,60 @@ class ApiController extends Controller
|
|
|
|
|
|
|
|
|
//设置自己排班
|
|
|
- public function setSelfSchedule()
|
|
|
- {
|
|
|
- $docter_id = request('docter_id');
|
|
|
- $org_id = request('org_id');
|
|
|
- $date = request('date');
|
|
|
- $type = request('type','1,2'); //1 上午,2 下午,3 晚上
|
|
|
- $schedule_type = request('schedule_type');
|
|
|
- $self_setting = DocterSetting::where(['docter_id'=>$docter_id])->first();
|
|
|
- $times = [];
|
|
|
- if(!empty($self_setting)){
|
|
|
- $time_period = object_array(json_decode($self_setting->service_time));
|
|
|
- $times[1] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[0]['startTime']),intval($time_period[0]['endTime'])])->pluck('id')->toArray();
|
|
|
- $times[2] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[1]['startTime']),intval($time_period[1]['endTime'])])->pluck('id')->toArray();
|
|
|
- $times[3] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[2]['startTime']),intval($time_period[2]['endTime'])])->pluck('id')->toArray();
|
|
|
- }
|
|
|
- if(count($times) <3){
|
|
|
- return apiReturn(602,'请设置真确的时间段');
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($docter_id) || empty($org_id) || empty('date') || empty($type) || empty($schedule_type)){
|
|
|
- return apiReturn(601,'缺少必要参数');
|
|
|
- }
|
|
|
-
|
|
|
- if(strtotime($date) < strtotime('tomorrow')){
|
|
|
- return apiReturn(602,'只能排明天以後的');
|
|
|
- }
|
|
|
-
|
|
|
- $week = date("w",strtotime($date));
|
|
|
- $types = explode(',',$type);
|
|
|
- if(!empty($types)){
|
|
|
- foreach ($types as $t){
|
|
|
- $self_schedule = [
|
|
|
- 'schedule_date'=>$date,
|
|
|
- 'week'=>intval($week),
|
|
|
- 'schedule_type'=>$schedule_type,
|
|
|
- 'organization_id'=>$org_id,
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'type'=>intval($t)
|
|
|
- ];
|
|
|
- foreach ($times[intval($t)] as $id){
|
|
|
- $self_schedule['time_period_id'] = $id;
|
|
|
- $is_have = SelfSchedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id,'schedule_date'=>$date,'type'=>intval($t),'week'=>$week,'time_period_id'=>$id])->value('id');
|
|
|
- if($is_have) continue;
|
|
|
- SelfSchedule::insert($self_schedule);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $cha = array_diff([1,2,3],$types);
|
|
|
- foreach ($cha as $t){
|
|
|
- SelfSchedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id,'schedule_date'=>$date,'type'=>intval($t)])->delete();
|
|
|
- }
|
|
|
- }
|
|
|
- return apiReturn(200,'ok');
|
|
|
- }
|
|
|
+// public function setSelfSchedule()
|
|
|
+// {
|
|
|
+// $docter_id = request('docter_id');
|
|
|
+// $org_id = request('org_id');
|
|
|
+// $date = request('date');
|
|
|
+// $type = request('type','1,2'); //1 上午,2 下午,3 晚上
|
|
|
+// $schedule_type = request('schedule_type');
|
|
|
+// $self_setting = DocterSetting::where(['docter_id'=>$docter_id])->first();
|
|
|
+// $times = [];
|
|
|
+// if(!empty($self_setting)){
|
|
|
+// $time_period = object_array(json_decode($self_setting->service_time));
|
|
|
+// $times[1] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[0]['startTime']),intval($time_period[0]['endTime'])])->pluck('id')->toArray();
|
|
|
+// $times[2] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[1]['startTime']),intval($time_period[1]['endTime'])])->pluck('id')->toArray();
|
|
|
+// $times[3] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[2]['startTime']),intval($time_period[2]['endTime'])])->pluck('id')->toArray();
|
|
|
+// }
|
|
|
+// if(count($times) <3){
|
|
|
+// return apiReturn(602,'请设置真确的时间段');
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(empty($docter_id) || empty($org_id) || empty('date') || empty($type) || empty($schedule_type)){
|
|
|
+// return apiReturn(601,'缺少必要参数');
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(strtotime($date) < strtotime('tomorrow')){
|
|
|
+// return apiReturn(602,'只能排明天以後的');
|
|
|
+// }
|
|
|
+//
|
|
|
+// $week = date("w",strtotime($date));
|
|
|
+// $types = explode(',',$type);
|
|
|
+// if(!empty($types)){
|
|
|
+// foreach ($types as $t){
|
|
|
+// $self_schedule = [
|
|
|
+// 'schedule_date'=>$date,
|
|
|
+// 'week'=>intval($week),
|
|
|
+// 'schedule_type'=>$schedule_type,
|
|
|
+// 'organization_id'=>$org_id,
|
|
|
+// 'docter_id'=>$docter_id,
|
|
|
+// 'type'=>intval($t)
|
|
|
+// ];
|
|
|
+// foreach ($times[intval($t)] as $id){
|
|
|
+// $self_schedule['time_period_id'] = $id;
|
|
|
+// $is_have = SelfSchedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id,'schedule_date'=>$date,'type'=>intval($t),'week'=>$week,'time_period_id'=>$id])->value('id');
|
|
|
+// if($is_have) continue;
|
|
|
+// SelfSchedule::insert($self_schedule);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $cha = array_diff([1,2,3],$types);
|
|
|
+// foreach ($cha as $t){
|
|
|
+// SelfSchedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id,'schedule_date'=>$date,'type'=>intval($t)])->delete();
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return apiReturn(200,'ok');
|
|
|
+// }
|
|
|
|
|
|
|
|
|
//获取图文订单
|
| xqd
@@ -429,7 +429,7 @@ class ApiController extends Controller
|
|
|
$schedule_ids = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_day','>',$today)->pluck('id')->toArray();
|
|
|
// Schedule::where(['docter_id'=>$docterId])->where('schedule_day','>',$today)->delete();
|
|
|
//删除具体排班
|
|
|
- SchedulePeriod::where('organization_id',$orgId)->whereIn('schedule_id',$schedule_ids)->delete();
|
|
|
+ SchedulePeriod::where('organization_id',$orgId)->where('me_sure',0)->whereIn('schedule_id',$schedule_ids)->delete();
|
|
|
$allScheduleData = [];
|
|
|
//插入两个月的数据
|
|
|
for ($i=1;$i<60;$i++){
|
| xqd
@@ -472,6 +472,7 @@ class ApiController extends Controller
|
|
|
|
|
|
$scheduleIsHave = SchedulePeriod::where($s_t)->count();
|
|
|
$s_t['order_num'] = 0;
|
|
|
+ $s_t['me_sure'] = 0;
|
|
|
if (!$scheduleIsHave) $allData[] = $s_t;
|
|
|
|
|
|
}
|
| xqd
@@ -566,12 +567,12 @@ class ApiController extends Controller
|
|
|
}
|
|
|
//覆盖自定义排班
|
|
|
// echo '医生id '.$docter_id.' 机构id '.$org_id.' 周几'.$week.' 日期 '.$scheduleDate.'<br>';
|
|
|
- $self = SelfSchedule::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'schedule_type'=>$sType])->get()->GroupBy('type')->toArray();
|
|
|
- if(!empty($self)){
|
|
|
- foreach($self as $k=>$sf){
|
|
|
- $newBase[$k-1]['status'] = true;
|
|
|
- }
|
|
|
- }
|
|
|
+// $self = SelfSchedule::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'schedule_type'=>$sType])->get()->GroupBy('type')->toArray();
|
|
|
+// if(!empty($self)){
|
|
|
+// foreach($self as $k=>$sf){
|
|
|
+// $newBase[$k-1]['status'] = true;
|
|
|
+// }
|
|
|
+// }
|
|
|
$scheduleList[$i-1] = [
|
|
|
'schedulelingList'=>$newBase,
|
|
|
'date'=>$i,
|
| xqd
@@ -598,12 +599,12 @@ class ApiController extends Controller
|
|
|
}
|
|
|
}
|
|
|
//覆盖自定义排班
|
|
|
- $self = SelfSchedule::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'schedule_type'=>$sType,'organization_id'=>$org_id])->get(['type'])->GroupBy('type')->toArray();
|
|
|
- if(!empty($self)){
|
|
|
- foreach($self as $k=>$sf){
|
|
|
- $newBase[$k-1]['status'] = true;
|
|
|
- }
|
|
|
- }
|
|
|
+// $self = SelfSchedule::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate,'schedule_type'=>$sType,'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,
|
| xqd
@@ -624,7 +625,8 @@ class ApiController extends Controller
|
|
|
$sType = intval(request('type'));
|
|
|
if($sType != 1) $docter_id = 0;
|
|
|
|
|
|
- $setting = DocterSetting::where(['docter_id'=>$docter_id,'org_id'=>$org_id,'type'=>$sType])->first();
|
|
|
+// $setting = DocterSetting::where(['docter_id'=>$docter_id,'org_id'=>$org_id,'type'=>$sType])->first();
|
|
|
+ $setting = self::getSetting($sType,$docter_id,$org_id);
|
|
|
|
|
|
$docterConfig = SystemConfig::get('docter_config');
|
|
|
if(!empty($setting)){
|
| xqd
@@ -647,9 +649,10 @@ class ApiController extends Controller
|
|
|
];
|
|
|
return apiReturn(200,'ok',$configData);
|
|
|
}
|
|
|
- $config = object_array(json_decode($setting['service_time']));
|
|
|
|
|
|
- $status = $setting['status'] ? true: false;
|
|
|
+ $config = object_array(json_decode($setting['service_time']));
|
|
|
+
|
|
|
+ $status = $setting['status'] == 2 ? true: false;
|
|
|
$configData = [
|
|
|
'amEndTime'=>$config[1]['amEndTime'],
|
|
|
'amNum'=>$config[1]['amPerson'],
|
| xqd
@@ -766,27 +769,17 @@ class ApiController extends Controller
|
|
|
|
|
|
$time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => $sType])->whereBetween('end_time_period',$times[$tType])->pluck('id')->toArray();
|
|
|
$schedule = Schedule::where(['docter_id' => $docter_id,'schedule_type' => $sType])->pluck('schedule_date', 'id')->toArray();
|
|
|
- $self_schedule = SelfSchedule::where(['docter_id' => 0, 'schedule_type' => $sType,'organization_id'=>$org_id,'type' =>$tType])->distinct('type')
|
|
|
- ->orderBy('schedule_date')->where('schedule_date','>',$Today)->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
+// $self_schedule = SelfSchedule::where(['docter_id' => 0, 'schedule_type' => $sType,'organization_id'=>$org_id,'type' =>$tType])->distinct('type')
|
|
|
+// ->orderBy('schedule_date')->where('schedule_date','>',$Today)->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
|
|
|
if($sType == 1){
|
|
|
- $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType,'schedule_type'=>$sType])
|
|
|
- ->distinct('type')
|
|
|
- ->orderBy('week')
|
|
|
- ->get(['week','organization_id'])
|
|
|
- ->GroupBy('week')
|
|
|
- ->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType,'schedule_type'=>$sType]);
|
|
|
} else {
|
|
|
-
|
|
|
- $week_schedule = WeekSchedule::where(['organization_id' =>$org_id, 'type' => $tType,'schedule_type'=>$sType])
|
|
|
- ->distinct('type')
|
|
|
- ->orderBy('week')
|
|
|
- ->pluck('type')
|
|
|
- ->GroupBy('week')
|
|
|
- ->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['organization_id' =>$org_id, 'type' => $tType,'schedule_type'=>$sType]);
|
|
|
}
|
|
|
+ $week=$week_schedule->count();
|
|
|
|
|
|
- if (empty($week_schedule)) {
|
|
|
+ if ($week==0) {
|
|
|
// return apiReturn(603,'请设置周排班');
|
|
|
// Schedule::where(['docter_id' => $docter_id])->delete();
|
|
|
// SelfSchedule::where(['docter_id' => $docter_id])->delete();
|
| xqd
@@ -795,7 +788,7 @@ class ApiController extends Controller
|
|
|
self::makeSchedule($sType,$docter_id,$org_id,$tType,$schedule,$time_periods);
|
|
|
|
|
|
//4.恢复自己设置的排班
|
|
|
- self::makeSelfScheeule($docter_id,$org_id,$sType,$tType,$time_periods,$self_schedule);
|
|
|
+// self::makeSelfScheeule($docter_id,$org_id,$sType,$tType,$time_periods,$self_schedule);
|
|
|
|
|
|
//TODO 删除周排班,插入新周排班
|
|
|
self::changeWeekSchedule($docter_id,$org_id,$sType,$tType,$time_periods);
|
| xqd
@@ -814,11 +807,14 @@ class ApiController extends Controller
|
|
|
2=>["pmStartTime"=>$configData['pmStartTime'],"pmEndTime"=>$configData['pmEndTime'],'pmPerson'=>$configData['pmNum']],
|
|
|
3=>["nightStartTime"=>$configData['nightStartTime'],"nightEndTime"=>$configData['nightEndTime'],'nightPerson'=>$configData['nightNum']]
|
|
|
];
|
|
|
+ $status = $configData['status'];
|
|
|
+ $real_status = 2;
|
|
|
+ if($status == false) $real_status = 1;
|
|
|
$setting = [
|
|
|
'docter_id'=>$docter_id,
|
|
|
'org_id'=>$org_id,
|
|
|
'type'=>$sType,
|
|
|
- 'status'=>$configData['status'],
|
|
|
+ 'status'=>$real_status,
|
|
|
'show_days'=>$configData['showDayNumber'],
|
|
|
'service_num'=>$configData['serviceNum'],
|
|
|
'service_times'=>$configData['timeSpan'],
|
| xqd
@@ -900,9 +896,9 @@ class ApiController extends Controller
|
|
|
*/
|
|
|
public static function deleteScheduleInfo($docter_id,$sType,$timeType,$orgId=0){
|
|
|
if($docter_id != 0){
|
|
|
- SchedulePeriod::where(['docter_id'=>$docter_id,'type'=>$timeType])->where('organization_id','=',$orgId)->delete();
|
|
|
+ SchedulePeriod::where(['docter_id'=>$docter_id,'type'=>$timeType,'me_sure'=>0])->where('organization_id','=',$orgId)->delete();
|
|
|
} else {
|
|
|
- SchedulePeriod::where(['organization_id'=>$orgId,'type'=>$timeType])->where('docter_id',0)->delete();
|
|
|
+ SchedulePeriod::where(['organization_id'=>$orgId,'type'=>$timeType,'me_sure'=>0])->where('docter_id',0)->delete();
|
|
|
}
|
|
|
return true;
|
|
|
}
|
| xqd
@@ -924,7 +920,7 @@ class ApiController extends Controller
|
|
|
|
|
|
if($isHave == 0) $allData[] = $timePreiod;
|
|
|
}
|
|
|
- dump($allData);
|
|
|
+// dump($allData);
|
|
|
dump(TimePeriod::insert($allData));
|
|
|
return true;
|
|
|
}
|
| xqd
@@ -932,121 +928,194 @@ class ApiController extends Controller
|
|
|
//以周模板进行排班
|
|
|
public static function makeSchedule ($sType,$docterId,$orgId,$tType,$schedule,$timePeriods){
|
|
|
|
|
|
- if(empty($schedule) || count($schedule) < 58){
|
|
|
- $start = strtotime(date('Y-m-1',time()));
|
|
|
+// if(empty($schedule) || count($schedule) < 58){
|
|
|
+
|
|
|
$today = date('j',time());
|
|
|
$allDay = date('t',time());
|
|
|
|
|
|
- //第一个月
|
|
|
- for ($i=$today;$i<=$allDay;$i++){
|
|
|
- $todayTimer = $start + (($i - 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['schedule_type'] = $sType;
|
|
|
-
|
|
|
- $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
-// $scheduleData['per_time_num'] = $serviceNum;
|
|
|
- if (!$scheduleIsHave) Schedule::insert($scheduleData);
|
|
|
-
|
|
|
- }
|
|
|
+// //第一个月
|
|
|
+// for ($i=$today;$i<=$allDay;$i++){
|
|
|
+// $todayTimer = $start + (($i - 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['schedule_type'] = $sType;
|
|
|
+//
|
|
|
+// $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
+//// $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['schedule_type'] = $sType;
|
|
|
+// $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
+//// $scheduleData['per_time_num'] = $serviceNum;
|
|
|
+// if (!$scheduleIsHave) Schedule::insert($scheduleData);
|
|
|
+// }
|
|
|
+// $allScheduleData = [];
|
|
|
+// //插入两个月的数据
|
|
|
+// for ($i=1;$i<60;$i++){
|
|
|
+// $todayTimer = $start + (($i - 1) *86400);
|
|
|
+// $date = date('Y-m-d',$todayTimer);
|
|
|
+// $numDate = date('Ymd',$todayTimer);
|
|
|
+//
|
|
|
+// $scheduleData['docter_id'] = $docterId;
|
|
|
+// $scheduleData['schedule_date'] = $date;
|
|
|
+// $scheduleData['schedule_day'] = $numDate;
|
|
|
+// $scheduleData['schedule_type'] = $sType;
|
|
|
+//
|
|
|
+// $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
+//// $scheduleData['per_time_num'] = $serviceNum;
|
|
|
+// //循环外批量插入
|
|
|
+// if (!$scheduleIsHave) $allScheduleData[] = $scheduleData;
|
|
|
+// }
|
|
|
+// if($allScheduleData) Schedule::insert($allScheduleData);
|
|
|
|
|
|
- $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['schedule_type'] = $sType;
|
|
|
- $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
-// $scheduleData['per_time_num'] = $serviceNum;
|
|
|
- if (!$scheduleIsHave) Schedule::insert($scheduleData);
|
|
|
- }
|
|
|
|
|
|
//todo 插入第三个月后的当日号
|
|
|
- $schedule = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_date','>=',date('Y-m-d',time()))
|
|
|
- ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
|
|
|
+// $schedule = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->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,'schedule_type'=>$sType])->where('schedule_date','>=',date('Y-m-d',time()))
|
|
|
// ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
|
|
|
// }
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
//
|
|
|
$allData = [];
|
|
|
+ $allMesure = [];
|
|
|
+ $start = time();
|
|
|
|
|
|
- foreach ($schedule as $id => $date) {
|
|
|
+
|
|
|
+ for ($i=1;$i<60;$i++){
|
|
|
+ $todayTimer = $start + (($i - 1) *86400);
|
|
|
+ $date = date('Y-m-d',$todayTimer);
|
|
|
$week = intval(date('N', strtotime($date)));
|
|
|
+
|
|
|
+ //更新自已定义排班
|
|
|
+ $mesure= SchedulePeriod::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_date'=>$date,'type'=>$tType,'schedule_type'=>$sType,'me_sure'=>1]);
|
|
|
+ $mesureIds = $mesure->pluck('id')->toArray();
|
|
|
+ $mesure->delete();
|
|
|
+ foreach ($timePeriods as $idt) {
|
|
|
+ if(!empty($mesureIds)){
|
|
|
+ $scheduleId = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_date',$date)->value('id');
|
|
|
+ if ($scheduleId==0) {
|
|
|
+ $numDate = date('Ymd',$todayTimer);
|
|
|
+ $scheduleData['docter_id'] = $docterId;
|
|
|
+ $scheduleData['schedule_date'] = $date;
|
|
|
+ $scheduleData['schedule_day'] = $numDate;
|
|
|
+ $scheduleData['schedule_type'] = $sType;
|
|
|
+// dd($scheduleData);
|
|
|
+ $scheduleId = Schedule::insertGetId($scheduleData);
|
|
|
+ }
|
|
|
+ $s_t = [
|
|
|
+ 'me_sure' => 1,
|
|
|
+ 'docter_id' => $docterId,
|
|
|
+ 'organization_id' => $orgId,
|
|
|
+ 'type' => $tType,
|
|
|
+ 'schedule_date' => $date,
|
|
|
+ 'schedule_type'=>$sType,
|
|
|
+ 'schedule_id' => $scheduleId,
|
|
|
+ 'time_period_id' => $idt
|
|
|
+ ];
|
|
|
+ $allMesure[] =$s_t;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// echo '医生id '.$docterId.' 机构id '.$orgId.' 周几 '.$week;
|
|
|
$real_id = WeekSchedule::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'week'=>$week,'type'=>$tType,'schedule_type'=>$sType])->first();
|
|
|
- if (!empty($real_id)) {
|
|
|
- foreach ($timePeriods as $idt) {
|
|
|
- $s_t = [
|
|
|
- 'docter_id' => $docterId,
|
|
|
- 'organization_id' => $orgId,
|
|
|
- 'type' => $tType,
|
|
|
- 'schedule_date' => $date,
|
|
|
- 'schedule_type'=>$sType,
|
|
|
- 'schedule_id' => $id,
|
|
|
- 'time_period_id' => $idt
|
|
|
- ];
|
|
|
- $scheduleIsHave = SchedulePeriod::where($s_t)->count();
|
|
|
- $s_t['order_num'] = 0;
|
|
|
- if ($scheduleIsHave) continue;
|
|
|
- $allData [] = $s_t;
|
|
|
+ if (!empty($real_id)) {
|
|
|
+
|
|
|
+ foreach ($timePeriods as $idt) {
|
|
|
+ $scheduleId = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType])->where('schedule_date',$date)->value('id');
|
|
|
+ if ($scheduleId==0) {
|
|
|
+ $numDate = date('Ymd',$todayTimer);
|
|
|
+ $scheduleData['docter_id'] = $docterId;
|
|
|
+ $scheduleData['schedule_date'] = $date;
|
|
|
+ $scheduleData['schedule_day'] = $numDate;
|
|
|
+ $scheduleData['schedule_type'] = $sType;
|
|
|
+// dd($scheduleData);
|
|
|
+ $scheduleId = Schedule::insertGetId($scheduleData);
|
|
|
}
|
|
|
+ $s_t = [
|
|
|
+ 'me_sure' => 0,
|
|
|
+ 'docter_id' => $docterId,
|
|
|
+ 'organization_id' => $orgId,
|
|
|
+ 'type' => $tType,
|
|
|
+ 'schedule_date' => $date,
|
|
|
+ 'schedule_type'=>$sType,
|
|
|
+ 'schedule_id' => $scheduleId,
|
|
|
+ 'time_period_id' => $idt
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ $scheduleIsHave = SchedulePeriod::where($s_t)->count();
|
|
|
+ $s_t['order_num'] = 0;
|
|
|
+ if($scheduleIsHave==0)$allData [] = $s_t;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+ }
|
|
|
}
|
|
|
- $res = SchedulePeriod::insert($allData);
|
|
|
+ if(!empty($allData)) SchedulePeriod::insert($allData);
|
|
|
+ if(!empty($allMesure)) SchedulePeriod::insert($allMesure);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//自己排班
|
|
|
- public static function makeSelfScheeule($docterId,$orgId,$sType,$timeType,$timesPeriods,$selfSchedule){
|
|
|
-
|
|
|
- $date = date('Y-m-d',time());
|
|
|
-
|
|
|
- //删除自己排班数据
|
|
|
- SelfSchedule::where(['type'=>$timeType,'docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_type'=>$sType])->where('schedule_date','>',$date)->delete();
|
|
|
- $allData = [];
|
|
|
- foreach ($selfSchedule as $val) {
|
|
|
- $self_data = $val;
|
|
|
- $self_data['organization_id'] = $orgId;
|
|
|
- $self_data['docter_id'] = $docterId;
|
|
|
- $self_data['schedule_type'] = $sType;
|
|
|
- $s_id = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType,'schedule_date'=>$val['schedule_date']])->value('id');
|
|
|
- $numDay = intval(str_replace('-','',$val['schedule_date']));
|
|
|
-// if(empty($s_id)) {
|
|
|
-// Schedule::insert(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_date'=>$val['schedule_date'],'schedule_day'=>$numDay]);
|
|
|
+// public static function makeSelfScheeule($docterId,$orgId,$sType,$timeType,$timesPeriods,$selfSchedule){
|
|
|
+//
|
|
|
+// $date = date('Y-m-d',time());
|
|
|
+//
|
|
|
+// //删除自己排班数据
|
|
|
+// SelfSchedule::where(['type'=>$timeType,'docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_type'=>$sType])->where('schedule_date','>',$date)->delete();
|
|
|
+// $allData = [];
|
|
|
+// foreach ($selfSchedule as $val) {
|
|
|
+// $self_data = $val;
|
|
|
+// $self_data['organization_id'] = $orgId;
|
|
|
+// $self_data['docter_id'] = $docterId;
|
|
|
+// $self_data['schedule_type'] = $sType;
|
|
|
+// $s_id = Schedule::where(['docter_id'=>$docterId,'schedule_type'=>$sType,'schedule_date'=>$val['schedule_date']])->value('id');
|
|
|
+// SchedulePeriod::where(['docter_id'=>$docterId,'organization_id'=>$orgId,'schedule_type'=>$sType,'schedule_date'=>$val['schedule_date'],'schedule_id'=>$s_id])->whereIn('time_period_id',$timesPeriods)->delete();
|
|
|
+//
|
|
|
+// if(empty($s_id)) continue;
|
|
|
+// foreach ($timesPeriods as $id) {
|
|
|
+// $self_data['time_period_id'] = $id;
|
|
|
+// $is_self_have = SelfSchedule::where($self_data)->count();
|
|
|
+// if($is_self_have) continue;
|
|
|
+// $is_schedule_period = SchedulePeriod::where($self_data)->count();
|
|
|
+// if($is_schedule_period) continue;
|
|
|
+//
|
|
|
+// $allData[] =$self_data;
|
|
|
+//
|
|
|
+// $self_data['schedule_id'] = $s_id;
|
|
|
+// unset($self_data['week']);
|
|
|
+// $allScheduleData [] = $self_data;
|
|
|
// }
|
|
|
- SchedulePeriod::where(['schedule_id'=>$s_id])->whereIn('time_period_id',$timesPeriods)->delete();
|
|
|
-
|
|
|
- foreach ($timesPeriods as $id) {
|
|
|
- $self_data['time_period_id'] = $id;
|
|
|
- $is_self_have = SelfSchedule::where($self_data)->count();
|
|
|
- if($is_self_have) continue;
|
|
|
- $self_data['schedule_id'] = $s_id;
|
|
|
- if(empty($s_id)) continue;
|
|
|
- $is_schedule_period = SchedulePeriod::where($self_data)->count();
|
|
|
-
|
|
|
- $allScheduleData [] = $self_data;
|
|
|
- $allData[] =$self_data;
|
|
|
- }
|
|
|
- }
|
|
|
- if(!empty($allData)) SelfSchedule::insert($allData);
|
|
|
- if(!empty($allScheduleData)) SchedulePeriod::insert($allScheduleData);
|
|
|
- }
|
|
|
+// }
|
|
|
+// if(!empty($allData)) SelfSchedule::insert($allData);
|
|
|
+// if(!empty($allScheduleData)) SchedulePeriod::insert($allScheduleData);
|
|
|
+// }
|
|
|
|
|
|
|
|
|
public function setDaySchedule()
|
| xqd
@@ -1098,11 +1167,11 @@ class ApiController extends Controller
|
|
|
$today = $schedule['day'];
|
|
|
$week = intval($schedule['week']);
|
|
|
|
|
|
- if($v['status'] == true){
|
|
|
+ if($v['status'] == true){ //设置
|
|
|
$num_date = intval(date('Ymd',strtotime($today)));
|
|
|
$sche_data = ['docter_id'=>intval($docter_id),'schedule_type'=>$sType,'schedule_date'=>$today,'schedule_day'=>$num_date];
|
|
|
//判断是否有排班信息
|
|
|
- $s_id = Schedule::where($sche_data)->count();
|
|
|
+ $s_id = Schedule::where($sche_data)->value('id');
|
|
|
if(!$s_id){
|
|
|
$s_id = Schedule::insertGetId($sche_data);
|
|
|
}
|
| xqd
@@ -1119,29 +1188,29 @@ class ApiController extends Controller
|
|
|
$data = [
|
|
|
'organization_id'=>$org_id,
|
|
|
'time_period_id'=>$id,
|
|
|
- 'week'=>$week,
|
|
|
+ 'me_sure'=>1,
|
|
|
'type'=>$v['type'],
|
|
|
'schedule_date'=>$today,
|
|
|
+ 'schedule_id'=>$s_id,
|
|
|
'schedule_type'=>$sType,
|
|
|
'docter_id'=>$docter_id,
|
|
|
];
|
|
|
|
|
|
// dump($data);
|
|
|
//检查是否已经有数据
|
|
|
- $self_count = SelfSchedule::where($data)->count();
|
|
|
- if(!$self_count) SelfSchedule::insert($data);
|
|
|
+// $self_count = SelfSchedule::where($data)->count();
|
|
|
+// if(!$self_count) SelfSchedule::insert($data);
|
|
|
|
|
|
- unset($data['week']);
|
|
|
- $data['schedule_id']=$s_id;
|
|
|
+// unset($data['week']);
|
|
|
$is_schedule_period = SchedulePeriod::where($data)->count();
|
|
|
if(!$is_schedule_period) SchedulePeriod::insert($data);
|
|
|
|
|
|
}
|
|
|
|
|
|
- } else if($v['status'] == false){
|
|
|
+ } else if($v['status'] == false){ //取消
|
|
|
$data = [
|
|
|
'organization_id'=>$org_id,
|
|
|
- 'week'=>$week,
|
|
|
+// 'week'=>$week,
|
|
|
'type'=>$v['type'],
|
|
|
'docter_id'=>$docter_id,
|
|
|
'schedule_type'=>$sType,
|
| xqd
@@ -1149,11 +1218,11 @@ class ApiController extends Controller
|
|
|
];
|
|
|
// dump($data);
|
|
|
//判断是否有自己的排班
|
|
|
- $self_count = SelfSchedule::where($data)->count();
|
|
|
- if($self_count) SelfSchedule::where($data)->delete();
|
|
|
+// $self_count = SelfSchedule::where($data)->count();
|
|
|
+// if($self_count) SelfSchedule::where($data)->delete();
|
|
|
|
|
|
|
|
|
- unset($data['week']);
|
|
|
+// unset($data['week']);
|
|
|
//删除详细排班
|
|
|
$count_period = SchedulePeriod::where($data)->count();
|
|
|
if($count_period) SchedulePeriod::where($data)->delete();
|
| xqd
@@ -1166,11 +1235,11 @@ class ApiController extends Controller
|
|
|
// //删除排班日期
|
|
|
$s_id = Schedule::where(['schedule_date'=>$today,'schedule_type'=>$sType,'docter_id'=>$docter_id])->value('id');
|
|
|
unset($data['type']);
|
|
|
- $scount = SelfSchedule::where($data)->count();
|
|
|
+// $scount = SelfSchedule::where($data)->count();
|
|
|
$pcount = SchedulePeriod::where($data)->count();
|
|
|
|
|
|
|
|
|
- if($s_id && $scount == 0 && $pcount == 0) {
|
|
|
+ if($s_id && $pcount == 0) {
|
|
|
Schedule::where(['id'=>$s_id])->delete();
|
|
|
}
|
|
|
// //删除排班和详细排班数据
|
| xqd
@@ -1219,6 +1288,9 @@ class ApiController extends Controller
|
|
|
|
|
|
public static function setDefultSetting($type,$docterId,$orgId)
|
|
|
{
|
|
|
+ if($type != 1){
|
|
|
+ $docterId = 0;
|
|
|
+ }
|
|
|
|
|
|
$configData = [
|
|
|
'amEndTime'=>"11:30",
|
| xqd
@@ -1244,17 +1316,18 @@ class ApiController extends Controller
|
|
|
|
|
|
$setting = [
|
|
|
'type'=>$type,
|
|
|
+ 'docter_id'=>$docterId,
|
|
|
'org_id'=>$orgId,
|
|
|
'status'=>$configData['status'],
|
|
|
'show_days'=>$configData['showDayNumber'],
|
|
|
'service_num'=>$configData['serviceNum'],
|
|
|
'service_times'=>$configData['timeSpan'],
|
|
|
- 'service_time'=>json_encode($config)
|
|
|
];
|
|
|
|
|
|
if($type == 1){
|
|
|
- $is_have = DocterSetting::where(['docter_id'=>$docterId,'org_id'=>$orgId])->count();
|
|
|
+ $is_have = DocterSetting::where(['docter_id'=>$docterId,'org_id'=>$orgId,'type'=>$type])->count();
|
|
|
if(!$is_have){
|
|
|
+ $setting['service_time'] = json_encode($config);
|
|
|
$setting['docter_id'] = $docterId;
|
|
|
DocterSetting::insert($setting);
|
|
|
} else {
|
| xqd
@@ -1263,12 +1336,12 @@ class ApiController extends Controller
|
|
|
return true;
|
|
|
} else {
|
|
|
|
|
|
- $is_have = OrganizationSettings::where(['org_id'=>$orgId])->count();
|
|
|
+ $is_have = DocterSetting::where(['docter_id'=>$docterId,'org_id'=>$orgId,'type'=>$type])->count();
|
|
|
if(!$is_have){
|
|
|
- OrganizationSettings::insert($setting);
|
|
|
+ $setting['service_time'] = json_encode($config);
|
|
|
+ DocterSetting::insert($setting);
|
|
|
} else {
|
|
|
- $setting['org_id'] = $docterId;
|
|
|
- OrganizationSettings::where(['org_id'=>$orgId])->update($setting);
|
|
|
+ DocterSetting::where(['org_id'=>$orgId,'docter_id'=>0])->update($setting);
|
|
|
}
|
|
|
}
|
|
|
|
| xqd
@@ -1276,13 +1349,14 @@ class ApiController extends Controller
|
|
|
}
|
|
|
|
|
|
public static function getSetting($type,$docterId,$orgId){
|
|
|
+ if($type != 1) $docterId = 0;
|
|
|
//默认为门诊排班医生配置
|
|
|
- $setting = DocterSetting::where(['docter_id'=>$docterId,'org_id'=>$orgId])->first();
|
|
|
+ $setting = DocterSetting::where(['docter_id'=>$docterId,'org_id'=>$orgId,'type'=>$type])->first();
|
|
|
//获取社区排班设置
|
|
|
- if($type == 2) $setting = OrganizationSettings::where(['org_id'=>$orgId])->first();
|
|
|
+ if($type !=1 ) $setting = DocterSetting::where(['org_id'=>$orgId,'type'=>$type,'docter_id'=>$docterId])->first();
|
|
|
if(empty($setting)){
|
|
|
self::setDefultSetting($type,$docterId,$orgId);
|
|
|
- self::getSetting($type,$docterId,$orgId);
|
|
|
+ $setting = self::getSetting($type,$docterId,$orgId);
|
|
|
}
|
|
|
return $setting;
|
|
|
}
|