| xqd
@@ -12,6 +12,7 @@ use App\Models\DocterSetting;
|
|
|
use App\Models\Doctertimes;
|
|
|
use App\Models\Order;
|
|
|
use App\Models\Organization;
|
|
|
+use App\Models\OrganizationSettings;
|
|
|
use App\Models\PatientRemark;
|
|
|
use App\Models\Schedule;
|
|
|
use App\Models\SchedulePeriod;
|
| xqd
@@ -467,45 +468,45 @@ class ApiController extends Controller
|
|
|
}
|
|
|
|
|
|
//获取用户信息
|
|
|
- public function getScheduleInfo()
|
|
|
- {
|
|
|
-
|
|
|
- $user = Admin::user();
|
|
|
- $org_id = $user->org_id;
|
|
|
- $docter_id = $user->docter_id;
|
|
|
-
|
|
|
- $is_docter = CdmsUsers::where('docter_id',$docter_id)->where('docter_id','!=','')->first();
|
|
|
- if(empty($org_id) && empty($docter_id)){
|
|
|
- return json_encode(['code'=>601,'msg'=>'缺少必要参数','data'=>'']);
|
|
|
- }
|
|
|
- $role = 1;
|
|
|
- if($is_docter){
|
|
|
- $role = 2;
|
|
|
- }
|
|
|
- $lists =[];
|
|
|
- if($role == 1){
|
|
|
- $ids = DocterOrganization::where(['organization_id'=>$org_id])->pluck('docter_id')->toArray();
|
|
|
- $list = Docter::whereIn('id',$ids)->where('is_then',1)->get(['id','name']);
|
|
|
- foreach ($list as $val){
|
|
|
- $lists[] = ['value'=>$val->id,'label'=>$val->name];
|
|
|
- }
|
|
|
- $name = Organization::where('id',$org_id)->value('name');
|
|
|
- $user_id = $org_id;
|
|
|
- } else {
|
|
|
- $ids = DocterOrganization::where(['docter_id'=>$docter_id])->pluck('organization_id');
|
|
|
- $list = Organization::whereIn('id',$ids)->get(['id','name']);
|
|
|
- foreach ($list as $val){
|
|
|
- $lists[] = ['value'=>$val->id,'label'=>$val->name];
|
|
|
- }
|
|
|
- $name = Docter::where('id',$docter_id)->value('name');
|
|
|
- $user_id = $docter_id;
|
|
|
- }
|
|
|
- $data['user_id'] = $user_id;
|
|
|
- $data['name'] = $name;
|
|
|
- $data['role'] = $role;
|
|
|
- $data['list'] = $lists;
|
|
|
- return (json_encode(['code'=>200,'msg'=>'ok','data'=>$data]));
|
|
|
- }
|
|
|
+// public function getScheduleInfo()
|
|
|
+// {
|
|
|
+//
|
|
|
+// $user = Admin::user();
|
|
|
+// $org_id = $user->org_id;
|
|
|
+// $docter_id = $user->docter_id;
|
|
|
+//
|
|
|
+// $is_docter = CdmsUsers::where('docter_id',$docter_id)->where('docter_id','!=','')->first();
|
|
|
+// if(empty($org_id) && empty($docter_id)){
|
|
|
+// return json_encode(['code'=>601,'msg'=>'缺少必要参数','data'=>'']);
|
|
|
+// }
|
|
|
+// $role = 1;
|
|
|
+// if($is_docter){
|
|
|
+// $role = 2;
|
|
|
+// }
|
|
|
+// $lists =[];
|
|
|
+// if($role == 1){
|
|
|
+// $ids = DocterOrganization::where(['organization_id'=>$org_id])->pluck('docter_id')->toArray();
|
|
|
+// $list = Docter::whereIn('id',$ids)->where('is_then',1)->get(['id','name']);
|
|
|
+// foreach ($list as $val){
|
|
|
+// $lists[] = ['value'=>$val->id,'label'=>$val->name];
|
|
|
+// }
|
|
|
+// $name = Organization::where('id',$org_id)->value('name');
|
|
|
+// $user_id = $org_id;
|
|
|
+// } else {
|
|
|
+// $ids = DocterOrganization::where(['docter_id'=>$docter_id])->pluck('organization_id');
|
|
|
+// $list = Organization::whereIn('id',$ids)->get(['id','name']);
|
|
|
+// foreach ($list as $val){
|
|
|
+// $lists[] = ['value'=>$val->id,'label'=>$val->name];
|
|
|
+// }
|
|
|
+// $name = Docter::where('id',$docter_id)->value('name');
|
|
|
+// $user_id = $docter_id;
|
|
|
+// }
|
|
|
+// $data['user_id'] = $user_id;
|
|
|
+// $data['name'] = $name;
|
|
|
+// $data['role'] = $role;
|
|
|
+// $data['list'] = $lists;
|
|
|
+// return (json_encode(['code'=>200,'msg'=>'ok','data'=>$data]));
|
|
|
+// }
|
|
|
|
|
|
//获取图文订单
|
|
|
public function get_chat_order()
|
| xqd
@@ -543,147 +544,141 @@ class ApiController extends Controller
|
|
|
|
|
|
}
|
|
|
|
|
|
- //更新用戶設置
|
|
|
- public function updateDocterSetting()
|
|
|
- {
|
|
|
- $docter_id = request('docter_id',1);
|
|
|
- if(empty($docter_id)){
|
|
|
- return apiReturn(604,'参数错误');
|
|
|
- }
|
|
|
-
|
|
|
- //添加时间段
|
|
|
- if(2 == 3){
|
|
|
- $data = ['docter_id'=>$docter_id,'am_start'=>'8:30','am_end'=>'11:30','pm_start'=>'12:00','pm_end'=>'15:00','ev_start'=>'19:00','ev_end'=>'22:00','service_time'=>15];
|
|
|
- $amtimes[] = explode(':',$data['am_start']);
|
|
|
- $amtimes[] = explode(':',$data['am_end']);
|
|
|
-// $amcha = ($amtimes[1][0] - $amtimes[0][0])*60 +($amtimes[1][1] - $amtimes[0][1]);
|
|
|
-// $amCount = $amcha/$data['service_time'];
|
|
|
- $amCount = intval(floor((strtotime($data['am_end']) - strtotime($data['am_start'])) / (60*$data['service_time'])));
|
|
|
-
|
|
|
- $pmtimes[] = explode(':',$data['pm_start']);
|
|
|
- $pmtimes[] = explode(':',$data['pm_end']);
|
|
|
- $pmCount =intval(floor((strtotime($data['pm_end']) - strtotime($data['pm_start'])) / (60*$data['service_time'])));
|
|
|
-
|
|
|
-
|
|
|
- $evtimes[] = explode(':',$data['ev_start']);
|
|
|
- $evtimes[] = explode(':',$data['ev_end']);
|
|
|
- $evcha = ($evtimes[1][0] - $evtimes[0][0])*60 +($evtimes[1][1] - $evtimes[0][1]);
|
|
|
- $evCount = $evcha/$data['service_time'];
|
|
|
-
|
|
|
-
|
|
|
- for($i=1;$i<=$amCount;$i++){
|
|
|
- $amdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($data['am_start']) + ($i-1)*$data['service_time']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($data['am_start']) + $i*$data['service_time']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($amdata);
|
|
|
- }
|
|
|
-
|
|
|
- for($i=1;$i<=$pmCount;$i++){
|
|
|
- $pmdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($data['pm_start']) + ($i-1)*$data['service_time']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($data['pm_start']) + $i*$data['service_time']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($pmdata);
|
|
|
- }
|
|
|
-
|
|
|
- for($i=1;$i<=$evCount;$i++){
|
|
|
- $evdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($data['ev_start']) + ($i-1)*$data['service_time']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($data['ev_start']) + $i*$data['service_time']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($evdata);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $config = [['startTime'=>"08:30","endTime"=>"11:30"],["startTime"=>"13:30","endTime"=>"16:00"],["startTime"=>"18:30","endTime"=>"19:30"]];
|
|
|
- $setting = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'type'=>2,
|
|
|
- 'status'=>2,
|
|
|
- 'show_days'=>7,
|
|
|
- 'service_num'=>7,
|
|
|
- 'service_time'=>json_encode($config)
|
|
|
- ];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $is_have = DocterSetting::where(['docter_id'=>$docter_id])->value('id');
|
|
|
- if($is_have){
|
|
|
- DocterSetting::where(['docter_id'=>$docter_id])->update($setting);
|
|
|
- } else {
|
|
|
- DocterSetting::insert($setting);
|
|
|
- }
|
|
|
- return apiReturn(200,'ok');
|
|
|
- }
|
|
|
+// //更新用戶設置
|
|
|
+// public function updateDocterSetting()
|
|
|
+// {
|
|
|
+// $docter_id = request('docter_id',1);
|
|
|
+// if(empty($docter_id)){
|
|
|
+// return apiReturn(604,'参数错误');
|
|
|
+// }
|
|
|
+//
|
|
|
+// //添加时间段
|
|
|
+// if(2 == 3){
|
|
|
+// $data = ['docter_id'=>$docter_id,'am_start'=>'8:30','am_end'=>'11:30','pm_start'=>'12:00','pm_end'=>'15:00','ev_start'=>'19:00','ev_end'=>'22:00','service_time'=>15];
|
|
|
+// $amtimes[] = explode(':',$data['am_start']);
|
|
|
+// $amtimes[] = explode(':',$data['am_end']);
|
|
|
+//// $amcha = ($amtimes[1][0] - $amtimes[0][0])*60 +($amtimes[1][1] - $amtimes[0][1]);
|
|
|
+//// $amCount = $amcha/$data['service_time'];
|
|
|
+// $amCount = intval(floor((strtotime($data['am_end']) - strtotime($data['am_start'])) / (60*$data['service_time'])));
|
|
|
+//
|
|
|
+// $pmtimes[] = explode(':',$data['pm_start']);
|
|
|
+// $pmtimes[] = explode(':',$data['pm_end']);
|
|
|
+// $pmCount =intval(floor((strtotime($data['pm_end']) - strtotime($data['pm_start'])) / (60*$data['service_time'])));
|
|
|
+//
|
|
|
+//
|
|
|
+// $evtimes[] = explode(':',$data['ev_start']);
|
|
|
+// $evtimes[] = explode(':',$data['ev_end']);
|
|
|
+// $evcha = ($evtimes[1][0] - $evtimes[0][0])*60 +($evtimes[1][1] - $evtimes[0][1]);
|
|
|
+// $evCount = $evcha/$data['service_time'];
|
|
|
+//
|
|
|
+//
|
|
|
+// for($i=1;$i<=$amCount;$i++){
|
|
|
+// $amdata = [
|
|
|
+// 'docter_id'=>$docter_id,
|
|
|
+// 'start_time_period'=> date('H:i',strtotime($data['am_start']) + ($i-1)*$data['service_time']*60),
|
|
|
+// 'end_time_period'=> date('H:i',strtotime($data['am_start']) + $i*$data['service_time']*60),
|
|
|
+// ];
|
|
|
+// TimePeriod::insert($amdata);
|
|
|
+// }
|
|
|
+//
|
|
|
+// for($i=1;$i<=$pmCount;$i++){
|
|
|
+// $pmdata = [
|
|
|
+// 'docter_id'=>$docter_id,
|
|
|
+// 'start_time_period'=> date('H:i',strtotime($data['pm_start']) + ($i-1)*$data['service_time']*60),
|
|
|
+// 'end_time_period'=> date('H:i',strtotime($data['pm_start']) + $i*$data['service_time']*60),
|
|
|
+// ];
|
|
|
+// TimePeriod::insert($pmdata);
|
|
|
+// }
|
|
|
+//
|
|
|
+// for($i=1;$i<=$evCount;$i++){
|
|
|
+// $evdata = [
|
|
|
+// 'docter_id'=>$docter_id,
|
|
|
+// 'start_time_period'=> date('H:i',strtotime($data['ev_start']) + ($i-1)*$data['service_time']*60),
|
|
|
+// 'end_time_period'=> date('H:i',strtotime($data['ev_start']) + $i*$data['service_time']*60),
|
|
|
+// ];
|
|
|
+// TimePeriod::insert($evdata);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $config = [['startTime'=>"08:30","endTime"=>"11:30"],["startTime"=>"13:30","endTime"=>"16:00"],["startTime"=>"18:30","endTime"=>"19:30"]];
|
|
|
+// $setting = [
|
|
|
+// 'docter_id'=>$docter_id,
|
|
|
+// 'type'=>2,
|
|
|
+// 'status'=>2,
|
|
|
+// 'show_days'=>7,
|
|
|
+// 'service_num'=>7,
|
|
|
+// 'service_time'=>json_encode($config)
|
|
|
+// ];
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// $is_have = DocterSetting::where(['docter_id'=>$docter_id])->value('id');
|
|
|
+// if($is_have){
|
|
|
+// DocterSetting::where(['docter_id'=>$docter_id])->update($setting);
|
|
|
+// } else {
|
|
|
+// DocterSetting::insert($setting);
|
|
|
+// }
|
|
|
+// return apiReturn(200,'ok');
|
|
|
+// }
|
|
|
|
|
|
//获取周排班模板
|
|
|
public function getWeekSchedule()
|
|
|
{
|
|
|
- $docter_id = request('docter_id',1);
|
|
|
- $org_id = request('org_id',1);
|
|
|
- $type = request('type',2);
|
|
|
- $role = request('role',2);
|
|
|
+ $docter_id = intval(request('docter_id'));
|
|
|
+ $org_id = intval(request('org_id'));
|
|
|
+ $type = intval(request('type'));
|
|
|
if(empty($docter_id) || empty($type)){
|
|
|
return apiReturn(604,'缺少必要参数');
|
|
|
}
|
|
|
|
|
|
- $docter_id = 1;
|
|
|
- $docter_setting = DocterSetting::where(['docter_id'=>$docter_id,'type'=>$type])->first();
|
|
|
- $times = [];
|
|
|
- if(!empty($docter_setting)){
|
|
|
- $time_period = object_array(json_decode($docter_setting->service_time));
|
|
|
- $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[0]['startTime']),intval($time_period[0]['endTime'])])->pluck('id')->toArray();
|
|
|
- $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[1]['startTime']),intval($time_period[1]['endTime'])])->pluck('id')->toArray();
|
|
|
- $times[] = 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){
|
|
|
- dd('no have times');
|
|
|
+ if($type == 1){
|
|
|
+ $role = 2;
|
|
|
+ $setting = DocterSetting::where(['docter_id'=>$docter_id,'type'=>$type])->first();
|
|
|
+ } else {
|
|
|
+ $role = 1;
|
|
|
+ $setting = OrganizationSettings::where(['org_id'=>$docter_id])->first();
|
|
|
}
|
|
|
|
|
|
//周字段映射
|
|
|
- $week_arr = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'];
|
|
|
+ $week_arr = [1=>'monday',2=>'tuesday',3=>'wednesday',4=>'thursday',5=>'friday',6=>'saturday',7=>'sunday'];
|
|
|
$data = [
|
|
|
- [
|
|
|
- 'date'=>"上午",
|
|
|
- 'monday'=>false,
|
|
|
- 'tuesday'=>false,
|
|
|
- 'wednesday'=>false,
|
|
|
- 'thursday'=>false,
|
|
|
- 'friday'=>false,
|
|
|
- 'saturday'=>false,
|
|
|
- 'sunday'=>false,
|
|
|
- ],
|
|
|
- [
|
|
|
- 'date'=>"下午",
|
|
|
- 'monday'=>false,
|
|
|
- 'tuesday'=>false,
|
|
|
- 'wednesday'=>false,
|
|
|
- 'thursday'=>false,
|
|
|
- 'friday'=>false,
|
|
|
- 'saturday'=>false,
|
|
|
- 'sunday'=>false,
|
|
|
- ],
|
|
|
- [
|
|
|
- 'date'=>"晚上",
|
|
|
- 'monday'=>false,
|
|
|
- 'tuesday'=>false,
|
|
|
- 'wednesday'=>false,
|
|
|
- 'thursday'=>false,
|
|
|
- 'friday'=>false,
|
|
|
- 'saturday'=>false,
|
|
|
- 'sunday'=>false,
|
|
|
- ]
|
|
|
- ];
|
|
|
+ [
|
|
|
+ 'date'=>"上午",
|
|
|
+ 'monday'=>false,
|
|
|
+ 'tuesday'=>false,
|
|
|
+ 'wednesday'=>false,
|
|
|
+ 'thursday'=>false,
|
|
|
+ 'friday'=>false,
|
|
|
+ 'saturday'=>false,
|
|
|
+ 'sunday'=>false,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'date'=>"下午",
|
|
|
+ 'monday'=>false,
|
|
|
+ 'tuesday'=>false,
|
|
|
+ 'wednesday'=>false,
|
|
|
+ 'thursday'=>false,
|
|
|
+ 'friday'=>false,
|
|
|
+ 'saturday'=>false,
|
|
|
+ 'sunday'=>false,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'date'=>"晚上",
|
|
|
+ 'monday'=>false,
|
|
|
+ 'tuesday'=>false,
|
|
|
+ 'wednesday'=>false,
|
|
|
+ 'thursday'=>false,
|
|
|
+ 'friday'=>false,
|
|
|
+ 'saturday'=>false,
|
|
|
+ 'sunday'=>false,
|
|
|
+ ]
|
|
|
+ ];
|
|
|
if($role == 2){
|
|
|
- for ($i=0;$i<6;$i++){
|
|
|
+ for ($i=0;$i<=7;$i++){
|
|
|
+ if($i == 0) continue;
|
|
|
for($j=0;$j<=2;$j++){
|
|
|
- $is_self_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'organization_id'=>$org_id,'week'=>$i+1])->whereIn('time_period_id',$times[$j])->count();
|
|
|
- $is_other_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'week'=>$i+1])->where('organization_id','!=',$org_id)->whereIn('time_period_id',$times[$j])->count();
|
|
|
+ $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();
|
|
|
if($is_self_have){
|
|
|
$data[$j][$week_arr[$i]] = true;
|
|
|
}
|
| xqd
@@ -695,8 +690,8 @@ class ApiController extends Controller
|
|
|
} else {
|
|
|
for ($i=0;$i<6;$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+1])->whereIn('time_period_id',$times[$j])->count();
|
|
|
- $is_other_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'week'=>$i+1])->where('docter_id','!=',$docter_id)->whereIn('time_period_id',$times[$j])->count();
|
|
|
+ $is_self_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'organization_id'=>$org_id,'week'=>$i+1])->count();
|
|
|
+ $is_other_have = WeekSchedule::where(['docter_id'=>$docter_id,'schedule_type'=>$type,'week'=>$i+1])->where('docter_id','!=',$docter_id)->count();
|
|
|
if($is_self_have){
|
|
|
$data[$j][$week_arr[$i]] = true;
|
|
|
}
|
| xqd
@@ -762,9 +757,9 @@ class ApiController extends Controller
|
|
|
];
|
|
|
if(!empty($docter_setting)){
|
|
|
$time_period = object_array(json_decode($docter_setting->service_time));
|
|
|
- $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[0]['startTime']),intval($time_period[0]['endTime'])])->pluck('id')->toArray();
|
|
|
- $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[1]['startTime']),intval($time_period[1]['endTime'])])->pluck('id')->toArray();
|
|
|
- $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[2]['startTime']),intval($time_period[2]['endTime'])])->pluck('id')->toArray();
|
|
|
+ $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[1]['amStartTime']),intval($time_period[1]['amEndTime'])])->pluck('id')->toArray();
|
|
|
+ $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[2]['pmStartTime']),intval($time_period[2]['pmEndTime'])])->pluck('id')->toArray();
|
|
|
+ $times[] = TimePeriod::where(['docter_id'=>$docter_id])->whereBetween('end_time_period',[intval($time_period[3]['nightStartTime']),intval($time_period[3]['nightEndTime'])])->pluck('id')->toArray();
|
|
|
}
|
|
|
|
|
|
|
| xqd
@@ -899,4 +894,588 @@ class ApiController extends Controller
|
|
|
dd($week_schedule);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ //获取月排班
|
|
|
+ public function get_month_schedule()
|
|
|
+ {
|
|
|
+ $date = request('date');
|
|
|
+ $org_id = intval(request('org_id'));
|
|
|
+ $docter_id = intval(request('docter_id'));
|
|
|
+ $type = intval(request('type'));
|
|
|
+ $role = intval(request('role'));
|
|
|
+ $start_time = strtotime($date);
|
|
|
+ $month_day = date("t",$start_time);
|
|
|
+ $end_time = ($start_time + $month_day * 86400);
|
|
|
+ $start_date = date('Y-m-d',$start_time);
|
|
|
+ $end_date = date('Y-m-d',$end_time);
|
|
|
+ $types = [1=>1,2=>2,3=>3];
|
|
|
+
|
|
|
+
|
|
|
+ if($type == 1){
|
|
|
+ $schedule_data = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>0])
|
|
|
+ ->whereBetween('schedule_date',[$start_date,$end_date])->pluck('schedule_date','id')->toArray();
|
|
|
+ $settingConfig = DocterSetting::where(['docter_id'=>$docter_id])->first();
|
|
|
+ $serviceConfig = object_array(json_decode($settingConfig['service_time']));
|
|
|
+ } else {
|
|
|
+ $schedule_data = Schedule::where(['docter_id'=>0,'organization_id'=>$org_id])->
|
|
|
+ whereBetween('schedule_date',[$start_date,$end_date])->pluck('schedule_date','id')->toArray();
|
|
|
+ $settingConfig = OrganizationSettings::where(['org_id'=>$org_id])->first();
|
|
|
+ $serviceConfig = object_array(json_decode($settingConfig['service_time']));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!empty($settingConfig)){
|
|
|
+ $baseData = [
|
|
|
+ ['status'=>false,'type'=>1,'start'=>$serviceConfig[1]['amStartTime'],'end'=>$serviceConfig[1]['amEndTime']],
|
|
|
+ ['status'=>false,'type'=>2,'start'=>$serviceConfig[2]['pmStartTime'],'end'=>$serviceConfig[2]['pmEndTime']],
|
|
|
+ ['status'=>false,'type'=>3,'start'=>$serviceConfig[3]['nightStartTime'],'end'=>$serviceConfig[3]['nightEndTime']],
|
|
|
+ ];
|
|
|
+
|
|
|
+ } else{
|
|
|
+ $serviceConfig = '';
|
|
|
+ $baseData = [
|
|
|
+ ['status'=>false,'type'=>1,'start'=>$serviceConfig[1]['amStartTime'],'end'=>$serviceConfig[1]['amEndTime']],
|
|
|
+ ['status'=>false,'type'=>2,'start'=>$serviceConfig[2]['pmStartTime'],'end'=>$serviceConfig[2]['pmEndTime']],
|
|
|
+ ['status'=>false,'type'=>3,'start'=>$serviceConfig[3]['nightStartTime'],'end'=>$serviceConfig[3]['nightEndTime']],
|
|
|
+ ];
|
|
|
+
|
|
|
+ self::baseMonthSchedule($month_day,$baseData);
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ for($i=1;$i<=$month_day; $i++){
|
|
|
+ //$startKey = date('d',time());
|
|
|
+ $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'=>$scheduleDate,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ if($type == 1){
|
|
|
+ $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'=>$scheduleDate,
|
|
|
+ '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'=>$scheduleDate,
|
|
|
+ 'week'=>$week,
|
|
|
+ 'day'=>$scheduleDate
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+//// if(empty( $schedule_data[$scheduleDate])) continue;
|
|
|
+//// $schedule_id = $schedule_data[$schedule_data];
|
|
|
+// if($type == 1){
|
|
|
+// $today = SchedulePeriod::where(['docter_id'=>$docter_id,'schedule_date'=>$scheduleDate])->get(['organization_id','type'])->GroupBy('type');
|
|
|
+//
|
|
|
+// dd($today);
|
|
|
+// }
|
|
|
+//// date'=>($i+1),'day'=>$now_date,'schedulelingList'=>$arr,'week'=>$week
|
|
|
+//// dd($scheduleList);
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// $status = [1=>true,2=>'other',3=>false];
|
|
|
+//
|
|
|
+// for($i=0;$i<$month_day;$i++){
|
|
|
+// $now_time = $start_time + $i*86400;
|
|
|
+// $now_date = date('Y-m-d',$now_time);
|
|
|
+// $week = date('N',$now_time);
|
|
|
+// $arr = [
|
|
|
+// ['status'=>false,'type'=>1,'start'=>"09:00",'end'=>'11:30'],
|
|
|
+// ['status'=>true,'type'=>2,'start'=>'13:30','end'=>'16:30'],
|
|
|
+// ['status'=>false,'type'=>3,'start'=>'19:30','end'=>'21:00'],
|
|
|
+// ];
|
|
|
+// if($i%2 == 0){
|
|
|
+// $arr = [
|
|
|
+// ['status'=>false,'type'=>1,'start'=>"09:00",'end'=>'11:30'],
|
|
|
+// ['status'=>true,'type'=>2,'start'=>'13:30','end'=>'16:30'],
|
|
|
+// ['status'=>false,'type'=>3,'start'=>'19:30','end'=>'21:00'],
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// if($i%3 == 0){
|
|
|
+// $arr = [
|
|
|
+// ['status'=>true,'type'=>1,'start'=>"09:00",'end'=>'11:30'],
|
|
|
+// ['status'=>'other','type'=>2,'start'=>'13:30','end'=>'16:30'],
|
|
|
+// ['status'=>true,'type'=>3,'start'=>'19:30','end'=>'21:00'],
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// if($i%4 == 0){
|
|
|
+// $arr = [
|
|
|
+// ['status'=>'other','type'=>1,'start'=>"09:00",'end'=>'11:30'],
|
|
|
+// ['status'=>false,'type'=>2,'start'=>'13:30','end'=>'16:30'],
|
|
|
+// ['status'=>false,'type'=>3,'start'=>'19:30','end'=>'21:00'],
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// if($i == 14){
|
|
|
+// $arr = [
|
|
|
+// ['status'=>false,'type'=>1,'start'=>"09:00",'end'=>'11:30'],
|
|
|
+// ['status'=>false,'type'=>2,'start'=>'13:30','end'=>'16:30'],
|
|
|
+// ['status'=>false,'type'=>3,'start'=>'19:30','end'=>'21:00'],
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $all_time[] = ['date'=>($i+1),'day'=>$now_date,'schedulelingList'=>$arr,'week'=>$week];
|
|
|
+ }
|
|
|
+ return apiReturn(200,'ok',$scheduleList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function getDocterSetting()
|
|
|
+ {
|
|
|
+ $docter_id = intval(request('docter_id'));
|
|
|
+ $org_id = intval(request('org_id'));
|
|
|
+ $type = intval(request('type'));
|
|
|
+
|
|
|
+ $setting = DocterSetting::where(['docter_id'=>$docter_id])->first();
|
|
|
+ if($type == 1){
|
|
|
+ $setting = OrganizationSettings::where(['org_id'=>$org_id])->first();
|
|
|
+ }
|
|
|
+ $docterConfig = SystemConfig::get('docter_config');
|
|
|
+ if(!empty($setting)){
|
|
|
+ $setting = $setting->toArray();
|
|
|
+ } else {
|
|
|
+ $configData = [
|
|
|
+ 'amStartTime'=>$docterConfig['morning_start'],
|
|
|
+ 'amEndTime'=>$docterConfig['morning_end'],
|
|
|
+ 'amNum'=>0,
|
|
|
+ 'pmStartTime'=>$docterConfig['afternoon_start'],
|
|
|
+ 'pmEndTime'=>$docterConfig['afternoon_start'],
|
|
|
+ 'pmNum'=>0,
|
|
|
+ 'nightStartTime'=>$docterConfig['evening_start'],
|
|
|
+ 'nightEndTime'=>$docterConfig['evening_end'],
|
|
|
+ 'nightNum'=>0,
|
|
|
+ 'serviceNum'=>1,
|
|
|
+ 'showDayNumber'=>7,
|
|
|
+ 'status'=>false,
|
|
|
+ 'timeSpan'=>30,
|
|
|
+ ];
|
|
|
+ return apiReturn(200,'ok',$configData);
|
|
|
+ }
|
|
|
+ $config = object_array(json_decode($setting['service_time']));
|
|
|
+
|
|
|
+ $status = $setting['status'] ? true: false;
|
|
|
+ $configData = [
|
|
|
+ 'amEndTime'=>$config[1]['amEndTime'],
|
|
|
+ 'amNum'=>$config[1]['amPerson'],
|
|
|
+ 'amStartTime'=>$config[1]['amStartTime'],
|
|
|
+ 'nightEndTime'=>$config[3]['nightEndTime'],
|
|
|
+ 'nightNum'=>$config[3]['nightPerson'],
|
|
|
+ 'nightStartTime'=>$config[3]['nightStartTime'],
|
|
|
+ 'pmEndTime'=>$config[2]['pmEndTime'],
|
|
|
+ 'pmNum'=>$config[2]['pmPerson'],
|
|
|
+ 'pmStartTime'=>$config[2]['pmStartTime'],
|
|
|
+ 'serviceNum'=>$setting['service_num'],
|
|
|
+ 'showDayNumber'=>$setting['show_days'],
|
|
|
+ 'status'=>$status,
|
|
|
+ 'timeSpan'=>$setting['service_times'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ return apiReturn(200,'ok',$configData);
|
|
|
+
|
|
|
+ }
|
|
|
+ //更新用戶設置
|
|
|
+ public function updateDocterSetting()
|
|
|
+ {
|
|
|
+ $docter_id = intval(request('docter_id'));
|
|
|
+ $configData = request('configData');
|
|
|
+ $type = intval(request('type'));//医生类型 1 机构 2 医生
|
|
|
+ $org_id = intval(request('org_id'));
|
|
|
+ $configData = object_array(json_decode($configData));
|
|
|
+ if(empty($docter_id) || empty($configData)){
|
|
|
+ return apiReturn(604,'参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $setting = DocterSetting::where(['docter_id'=>$docter_id])->first();
|
|
|
+ if($type != 1){
|
|
|
+ $setting = OrganizationSettings::where(['org_id'=>$org_id])->first();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($setting)){
|
|
|
+
|
|
|
+ }
|
|
|
+ $self_config = object_array(json_decode($setting['service_time']));
|
|
|
+ //改变时间段
|
|
|
+ $changeTimer = [];
|
|
|
+ //是否改变了服务时长
|
|
|
+ $changeSeviceTime = false;
|
|
|
+
|
|
|
+ //同时服务人数
|
|
|
+ $serviceNum = intval($configData['serviceNum']);
|
|
|
+
|
|
|
+ //服务时长
|
|
|
+ $serviceTime = intval($configData['timeSpan']);
|
|
|
+
|
|
|
+ if(empty($setting) || $serviceTime != intval($setting['service_times'])){
|
|
|
+ $changeSeviceTime = true;
|
|
|
+ $changeTimer = [1,2,3];
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if($configData['amStartTime'] !== $self_config[1]['amStartTime'] || $configData['amEndTime'] !== $self_config[1]['amEndTime']){
|
|
|
+ $changeTimer[] = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if($configData['pmStartTime'] !== $self_config[2]['pmStartTime'] || $configData['pmEndTime'] !== $self_config[2]['pmEndTime']){
|
|
|
+ $changeTimer[] = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($configData['nightStartTime'] !== $self_config[3]['nightStartTime'] || $configData['nightEndTime'] !== $self_config[3]['nightEndTime']){
|
|
|
+ $changeTimer[] = 3;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加时间段
|
|
|
+
|
|
|
+ $countArr = [
|
|
|
+ 1=>$configData['amNum'],
|
|
|
+ 2=>$configData['pmNum'],
|
|
|
+ 3=>$configData['nightNum'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $c_r = [
|
|
|
+ 1=>['count'=>$configData['amNum'],'start_time'=>$configData['amStartTime'],'end_time'=>$configData['amEndTime']],
|
|
|
+ 2=>['count'=>$configData['pmNum'],'start_time'=>$configData['pmStartTime'],'end_time'=>$configData['pmEndTime']],
|
|
|
+ 3=>['count'=>$configData['nightNum'],'start_time'=>$configData['nightStartTime'],'end_time'=>$configData['nightEndTime']]
|
|
|
+ ];
|
|
|
+ $changeTimer = [1,2,3];
|
|
|
+ //todo 零时关闭排班功能,后续需要解除
|
|
|
+ if($changeSeviceTime || !empty($changeTimer)){
|
|
|
+
|
|
|
+ foreach ($changeTimer as $tType){
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ //1.删除旧时间段,并删除排班数据
|
|
|
+ $type == 1 ? $id = $docter_id : $id = $org_id;
|
|
|
+
|
|
|
+ //todo 暂时未删除周排班
|
|
|
+ self::delteScheduleInfo($id,$type);
|
|
|
+ $count = intval($countArr[$tType] / $serviceNum);
|
|
|
+ //2.创建新时间段
|
|
|
+ self::makeTimePeriod($type,$docter_id,$org_id,$tType,$c_r[$tType],$count,$serviceTime);
|
|
|
+ if($type == 1){
|
|
|
+ $time_periods = TimePeriod::where(['org_id' => '', 'docter_id' => $docter_id, 'type' => $tType])->pluck('id')->toArray();
|
|
|
+ $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $type, 'organization_id'=>0,'type' =>1])->distinct('type')
|
|
|
+ ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
+ $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id'=>0])->pluck('schedule_date', 'id')->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => $tType,'schedule_type'=>$type])
|
|
|
+ ->distinct('type')
|
|
|
+ ->orderBy('week')
|
|
|
+ ->get(['week','organization_id'])
|
|
|
+ ->GroupBy('week')
|
|
|
+ ->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($type !=1 ){
|
|
|
+ $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => 0, 'type' => $tType])->pluck('id')->toArray();
|
|
|
+ $schedule = Schedule::where(['docter_id' => 0, 'organization_id'=>$org_id])->pluck('schedule_date', 'id')->toArray();
|
|
|
+ $self_schedule = SelfSchedule::where(['docter_id' => 0, 'schedule_type' => $type,'organization_id'=>$org_id,'type' =>$tType])->distinct('type')
|
|
|
+ ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['organization_id' =>$org_id, 'type' => $tType,'schedule_type'=>$type])
|
|
|
+ ->distinct('type')
|
|
|
+ ->orderBy('week')
|
|
|
+ ->pluck('type')
|
|
|
+ ->GroupBy('week')
|
|
|
+ ->toArray();
|
|
|
+ }
|
|
|
+ if (empty($week_schedule)) {
|
|
|
+// Schedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+// SelfSchedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ } else {
|
|
|
+ //3.以周模板添加2个月的数据
|
|
|
+ self::makeSchedule($docter_id,$org_id,$type,$schedule,$week_schedule,$time_periods);
|
|
|
+
|
|
|
+ //4.回复自己设置的排班
|
|
|
+ self::makeSelfScheeule($docter_id,$org_id,$type,$time_periods,$self_schedule);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ dd($e->getMessage());
|
|
|
+ DB::rollBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// {"1":{"amStartTime":"08:00","amEndTime":"12:00","amPerson":3},"2":{"pmStartTime":"14:00","pmEndTime":"18:00","pmPerson":5},"3":{"nightStartTime":"18:00","nightEndTime":"23:00","nightPerson":4}}
|
|
|
+ $config = [
|
|
|
+ 1=>['amStartTime'=>$configData['amStartTime'],"amEndTime"=>$configData['amEndTime'],'amPerson'=>$configData['amNum']],
|
|
|
+ 2=>["pmStartTime"=>$configData['pmStartTime'],"pmEndTime"=>$configData['pmEndTime'],'pmPerson'=>$configData['pmNum']],
|
|
|
+ 3=>["nightStartTime"=>$configData['nightStartTime'],"nightEndTime"=>$configData['nightEndTime'],'nightPerson'=>$configData['nightNum']]
|
|
|
+ ];
|
|
|
+ $setting = [
|
|
|
+ 'docter_id'=>$docter_id,
|
|
|
+ 'type'=>$type,
|
|
|
+ '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'=>$docter_id])->value('id');
|
|
|
+ if($is_have){
|
|
|
+ DocterSetting::where(['docter_id'=>$docter_id])->update($setting);
|
|
|
+ } else {
|
|
|
+ DocterSetting::insert($setting);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ unset($setting['docter_id']);
|
|
|
+ $setting['org_id'] = $org_id;
|
|
|
+ $is_have = OrganizationSettings::where(['id'=>$docter_id])->value('id');
|
|
|
+ if($is_have){
|
|
|
+ OrganizationSettings::where(['org_id'=>$org_id])->update($setting);
|
|
|
+ } else {
|
|
|
+ OrganizationSettings::insert($setting);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return apiReturn(200,'ok');
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取用户信息
|
|
|
+ public function getScheduleInfo()
|
|
|
+ {
|
|
|
+ $id = intval(request('id'));
|
|
|
+ $isDocter = CdmsUsers::where('docter_id',$id)->first();
|
|
|
+ $isOrg = CdmsUsers::where('org_id',$id)->first();
|
|
|
+ $org_id = null;
|
|
|
+ $role = 1;
|
|
|
+
|
|
|
+ if(empty($id)){
|
|
|
+ return json_encode(['status'=>601,'msg'=>'缺少必要参数','data'=>'']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($isDocter){
|
|
|
+ $org_id = $isDocter->org_id;
|
|
|
+ $docter = Docter::where(['id'=>$id])->first();
|
|
|
+ $role = 2;
|
|
|
+ } else {
|
|
|
+ if(!empty($isOrg->org_id)){
|
|
|
+ $org_id = $isOrg->org_id;
|
|
|
+ } else {
|
|
|
+ $role = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $lists =[];
|
|
|
+ if($role == 1){
|
|
|
+ $ids = DocterOrganization::where(['organization_id'=>$org_id])->pluck('docter_id')->toArray();
|
|
|
+ $list = Docter::whereIn('id',$ids)->distinct('id')->get(['id','name']);
|
|
|
+ foreach ($list as $val){
|
|
|
+ $lists[] = ['value'=>$val->id,'label'=>$val->name];
|
|
|
+ }
|
|
|
+ $name = Organization::where('id',$org_id)->value('name');
|
|
|
+ } else if($role == 2){
|
|
|
+ $ids = DocterOrganization::where(['docter_id'=>$id])->distinct('docter_id')->pluck('organization_id')->toArray();
|
|
|
+ $list = Organization::whereIn('id',$ids)->get(['id','name']);
|
|
|
+ foreach ($list as $val){
|
|
|
+ $lists[] = ['value'=>$val->id,'label'=>$val->name];
|
|
|
+ }
|
|
|
+ $name = Docter::where('id',$id)->value('name');
|
|
|
+ } else {
|
|
|
+ $name = '';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $type = 1;
|
|
|
+ $data['user_id'] = $id;
|
|
|
+ $data['name'] = $name;
|
|
|
+ $data['org_id'] = $org_id;
|
|
|
+ $data['docter_type'] = 0;
|
|
|
+ $data['list'] = [];
|
|
|
+
|
|
|
+ if(!empty($docter)){
|
|
|
+ $data['docter_type'] = $docter->type;
|
|
|
+ if($docter->type == 1){
|
|
|
+ $data['list'] = $lists;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data['role'] = $role;
|
|
|
+ return (json_encode(['code'=>200,'msg'=>'ok','data'=>$data]));
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * @param
|
|
|
+ * $id int 医生或社区id
|
|
|
+ * $type int 排班类型
|
|
|
+ * @descript 删除排班数据
|
|
|
+ */
|
|
|
+ public static function delteScheduleInfo($id,$type){
|
|
|
+ if($type == 1){
|
|
|
+ TimePeriod::where(['docter_id'=>$id,'type'=>$type])->where('org_id','=',0)->delete();
|
|
|
+ SchedulePeriod::where(['docter_id'=>$id,'type'=>$type])->where('organization_id','=',0)->delete();
|
|
|
+ } else {
|
|
|
+ TimePeriod::where(['org_id'=>$id,'type'=>$type])->where('docter_id','=',0)->delete();
|
|
|
+ SchedulePeriod::where(['organization_id'=>$id,'type'=>$type])->where('docter_id','=',0)->delete();
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //插入时间段
|
|
|
+ public static function makeTimePeriod($scheduleType,$docterId,$orgId,$timeType,$timeConfig,$timerCount,$serviceTime)
|
|
|
+ {
|
|
|
+ for($i=1;$i<=$timerCount;$i++){
|
|
|
+ $timePreiod = [
|
|
|
+ 'org_id'=>$orgId,
|
|
|
+ 'docter_id'=>$docterId,
|
|
|
+ 'type'=>$timeType,
|
|
|
+ 'start_time_period'=> date('H:i',strtotime($timeConfig['start_time']) + ($i-1)*$serviceTime*60),
|
|
|
+ 'end_time_period'=> date('H:i',strtotime($timeConfig['start_time']) + $i*$serviceTime*60),
|
|
|
+ ];
|
|
|
+ if($scheduleType == 1){
|
|
|
+ $timePreiod['org_id'] = 0;
|
|
|
+ $timePreiod['docter_id'] = $docterId;
|
|
|
+ } else {
|
|
|
+ $timePreiod['docter_id'] = 0;
|
|
|
+ $timePreiod['org_id'] = $orgId;
|
|
|
+ }
|
|
|
+ $isHave = TimePeriod::where($timePreiod)->count();
|
|
|
+ if($isHave) continue;
|
|
|
+ TimePeriod::insert($timePreiod);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //以周模板进行排班
|
|
|
+ public static function makeSchedule ($docterId,$orgId,$type,$schedule,$weekSchedule,$timePeriods){
|
|
|
+
|
|
|
+ if(empty($schedule) || count($schedule) < 58){
|
|
|
+ $start = strtotime(date('Y-m-1',time()));
|
|
|
+ $today = date('j',time());
|
|
|
+ $allDay = date('t',time());
|
|
|
+
|
|
|
+ //门诊排班
|
|
|
+ if($type == 1){
|
|
|
+ $scheduleData['docter_id']=$docterId;
|
|
|
+ $scheduleData['organization_id']= 0;
|
|
|
+ } else {
|
|
|
+ $scheduleData['docter_id']=0;
|
|
|
+ $scheduleData['organization_id']= $orgId;
|
|
|
+ }
|
|
|
+
|
|
|
+ //第一个月
|
|
|
+ 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['schedule_date'] = $date;
|
|
|
+ $scheduleData['schedule_day'] = $numDate;
|
|
|
+
|
|
|
+ $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
+ if ($scheduleIsHave) continue;
|
|
|
+ Schedule::insertGetId($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['schedule_date'] = $date;
|
|
|
+ $scheduleData['schedule_day'] = $numDate;
|
|
|
+ $scheduleIsHave = Schedule::where($scheduleData)->count();
|
|
|
+ if ($scheduleIsHave) continue;
|
|
|
+ Schedule::insertGetId($scheduleData);
|
|
|
+ }
|
|
|
+ $schedule = Schedule::where(['docter_id'=>$docterId,'organization_id'=>0])->where('schedule_date','>',date('Y-m-d',time()))
|
|
|
+ ->distinct('schedule_date')->pluck('schedule_date','id')->toArray();
|
|
|
+ if($type == 2){
|
|
|
+ $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)));
|
|
|
+ foreach ($weekSchedule as $w) {
|
|
|
+
|
|
|
+ //门诊和儿保,计免排班分开
|
|
|
+ if($type == 1){
|
|
|
+ $realWeek = $w[0]['week'];
|
|
|
+ $oId = $w = $w[0]['organization_id'];
|
|
|
+ } else {
|
|
|
+ $realWeek = $w;
|
|
|
+ $oId = $orgId;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($week == $realWeek) {
|
|
|
+ foreach ($timePeriods as $idt) {
|
|
|
+ $s_t = [
|
|
|
+ 'organization_id' => $oId,
|
|
|
+ 'docter_id' => $docterId,
|
|
|
+ 'type' => $type,
|
|
|
+ 'schedule_date' => $date,
|
|
|
+ 'schedule_id' => $id,
|
|
|
+ 'time_period_id' => $idt
|
|
|
+ ];
|
|
|
+ $scheduleIsHave = SchedulePeriod::where($s_t)->count();
|
|
|
+ if ($scheduleIsHave) continue;
|
|
|
+ $s_t['created_at'] = Carbon::now();
|
|
|
+ $s_t['updated_at'] = Carbon::now();
|
|
|
+ SchedulePeriod::insert($s_t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //自己排班
|
|
|
+ public function makeSelfScheeule($docterId,$orgId,$type,$timesPeriods,$selfSchedule){
|
|
|
+ if($type == 1){
|
|
|
+ $orgId = 0;
|
|
|
+ SelfSchedule::where(['type'=>1,'docter_id'=>$docterId,'organization_id'=>0,'schedule_type'=>$type])->whereIn('time_period_id',$timesPeriods)->delete();
|
|
|
+ } else {
|
|
|
+ SelfSchedule::where(['type'=>1,'docter_id'=>0,'organization_id'=>$orgId,'schedule_type'=>$type])->whereIn('time_period_id',$timesPeriods)->delete();
|
|
|
+ $docterId = 0;
|
|
|
+ }
|
|
|
+ foreach ($selfSchedule as $val) {
|
|
|
+ $self_data = $val;
|
|
|
+ $self_data['organization_id'] = $orgId;
|
|
|
+ $self_data['docter_id'] = $docterId;
|
|
|
+ foreach ($timesPeriods as $idt) {
|
|
|
+ $self_data['time_period_id'] = $idt;
|
|
|
+ $is_self_have = SelfSchedule::where($self_data)->count();
|
|
|
+ if ($is_self_have) continue;
|
|
|
+ $self_data['created_at'] = Carbon::now();
|
|
|
+ $self_data['updated_at'] = Carbon::now();
|
|
|
+ SelfSchedule::insert($self_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|