| xqd
@@ -173,8 +173,6 @@ class ScheDuleController extends Controller
|
|
|
->where('organization_id','!=',$org_id)->where('docter_id','=',$docter_id)->count();
|
|
|
$is_mo_self = SchedulePeriod::whereIn('schedule_id',$sche_dule)->where('schedule_date',$str_time)->whereIn('time_period_id',$times[$j])
|
|
|
->where('organization_id',$org_id)->where('docter_id',$docter_id)->count();
|
|
|
-// echo $i.'--'.$j.'is_self---'.$is_mo_self.'<br>';
|
|
|
-
|
|
|
if($is_mo_self){
|
|
|
$sche_dule_arr[$j][$week_arr[$i]] = true;
|
|
|
}
|
| xqd
@@ -322,38 +320,38 @@ class ScheDuleController extends Controller
|
|
|
$first_day = strtotime($start_time);
|
|
|
//周字段映射
|
|
|
$week_arr = ['monday','tuesday','wednesday','thursday','friday','saturday','sunday'];
|
|
|
-// $data = [
|
|
|
-// [
|
|
|
-// 'date'=>"上午",
|
|
|
-// 'monday'=>false,
|
|
|
-// 'tuesday'=>false,
|
|
|
-// 'wednesday'=>false,
|
|
|
-// 'thursday'=>true,
|
|
|
-// 'friday'=>false,
|
|
|
-// 'saturday'=>false,
|
|
|
-// 'sunday'=>false,
|
|
|
-// ],
|
|
|
-// [
|
|
|
-// 'date'=>"下午",
|
|
|
-// 'monday'=>false,
|
|
|
-// 'tuesday'=>true,
|
|
|
-// 'wednesday'=>false,
|
|
|
-// 'thursday'=>false,
|
|
|
-// 'friday'=>false,
|
|
|
-// 'saturday'=>false,
|
|
|
-// 'sunday'=>false,
|
|
|
-// ],
|
|
|
-// [
|
|
|
-// 'date'=>"晚上",
|
|
|
-// 'monday'=>false,
|
|
|
-// 'tuesday'=>false,
|
|
|
-// 'wednesday'=>true,
|
|
|
-// 'thursday'=>false,
|
|
|
-// 'friday'=>false,
|
|
|
-// 'saturday'=>false,
|
|
|
-// 'sunday'=>false,
|
|
|
-// ]
|
|
|
-// ];
|
|
|
+ $data = [
|
|
|
+ [
|
|
|
+ 'date'=>"上午",
|
|
|
+ 'monday'=>false,
|
|
|
+ 'tuesday'=>false,
|
|
|
+ 'wednesday'=>false,
|
|
|
+ 'thursday'=>true,
|
|
|
+ 'friday'=>false,
|
|
|
+ 'saturday'=>false,
|
|
|
+ 'sunday'=>false,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'date'=>"下午",
|
|
|
+ 'monday'=>false,
|
|
|
+ 'tuesday'=>true,
|
|
|
+ 'wednesday'=>false,
|
|
|
+ 'thursday'=>false,
|
|
|
+ 'friday'=>false,
|
|
|
+ 'saturday'=>false,
|
|
|
+ 'sunday'=>false,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'date'=>"晚上",
|
|
|
+ 'monday'=>false,
|
|
|
+ 'tuesday'=>false,
|
|
|
+ 'wednesday'=>true,
|
|
|
+ 'thursday'=>false,
|
|
|
+ 'friday'=>false,
|
|
|
+ 'saturday'=>false,
|
|
|
+ 'sunday'=>false,
|
|
|
+ ]
|
|
|
+ ];
|
|
|
|
|
|
|
|
|
//时段区间id
|
| xqd
@@ -550,14 +548,21 @@ class ScheDuleController extends Controller
|
|
|
$org_id = request('org_id');
|
|
|
$date = request('date');
|
|
|
$type = request('type','1,2'); //1 上午,2 下午,3 晚上
|
|
|
- $schedule_type = request('schedule_type');
|
|
|
+ $schedule_type = request('schedule_type',1);
|
|
|
+ $Ttype = 1;
|
|
|
+ if($schedule_type == 1) $Ttype = 2;
|
|
|
$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();
|
|
|
+ $where = ['docter_id'=>$docter_id,'type'=>$Ttype];
|
|
|
+ if($Ttype == 1){
|
|
|
+ $where['org_id'] = $org_id;
|
|
|
+ }
|
|
|
+// dd($time_period);
|
|
|
+ $times[1] = TimePeriod::where($where)->whereBetween('end_time_period',[intval($time_period[1]['amStartTime']),intval($time_period[1]['amEndTime'])])->pluck('id')->toArray();
|
|
|
+ $times[2] = TimePeriod::where($where)->whereBetween('end_time_period',[intval($time_period[2]['pmStartTime']),intval($time_period[2]['pmEndTime'])])->pluck('id')->toArray();
|
|
|
+ $times[3] = TimePeriod::where($where)->whereBetween('end_time_period',[intval($time_period[3]['nightStartTime']),intval($time_period[3]['nightEndTime'])])->pluck('id')->toArray();
|
|
|
}
|
|
|
if(count($times) <3){
|
|
|
return apiReturn(602,'请设置真确的时间段');
|
| xqd
@@ -583,6 +588,7 @@ class ScheDuleController extends Controller
|
|
|
'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');
|
| xqd
@@ -602,28 +608,31 @@ class ScheDuleController extends Controller
|
|
|
//更新用戶設置
|
|
|
public function updateDocterSetting()
|
|
|
{
|
|
|
- $docter_id = request('docter_id',1);
|
|
|
- $configData = request('configData');
|
|
|
- $type = request('type');
|
|
|
+ $docter_id = intval(request('docter_id',1));
|
|
|
+ $configData = request('configData',1);
|
|
|
+ $type = request('type',1);//医生类型 1 机构 2 医生
|
|
|
+ $schedule_type = request('schedule_type',1); //排班类型 1门诊 2计免 3儿保
|
|
|
+ $org_id = intval(request('org_id',0));
|
|
|
if(empty($docter_id) || empty($configData)){
|
|
|
return apiReturn(604,'参数错误');
|
|
|
}
|
|
|
|
|
|
- $configData = object_array(json_decode($configData));
|
|
|
-// $configData = [
|
|
|
-// 'amEndTime'=>"11:30",
|
|
|
-// 'amNum'=>20,
|
|
|
-// 'amStartTime'=>"09:00",
|
|
|
-// 'nightEndTime'=>"19:30",
|
|
|
-// 'nightNum'=>8,
|
|
|
-// 'nightStartTime'=>"11:30",
|
|
|
-// 'pmEndTime'=>"16:00",
|
|
|
-// 'pmNum'=>20,
|
|
|
-// 'pmStartTime'=>"13:30",
|
|
|
-// 'serviceNum'=>2,
|
|
|
-// 'status'=>false,
|
|
|
-// 'timeSpan'=>15,
|
|
|
-// ];
|
|
|
+// $configData = object_array(json_decode($configData));
|
|
|
+ $configData = [
|
|
|
+ 'amEndTime'=>"11:30",
|
|
|
+ 'amNum'=>5,
|
|
|
+ 'amStartTime'=>"09:00",
|
|
|
+ 'nightEndTime'=>"20:30",
|
|
|
+ 'nightStartTime'=>"19:00",
|
|
|
+ 'nightNum'=>3,
|
|
|
+ 'pmEndTime'=>"16:00",
|
|
|
+ 'pmNum'=>5,
|
|
|
+ 'pmStartTime'=>"13:30",
|
|
|
+ 'showDayNumber'=>7,
|
|
|
+ 'serviceNum'=>2,
|
|
|
+ 'status'=>false,
|
|
|
+ 'timeSpan'=>30,
|
|
|
+ ];
|
|
|
|
|
|
// configData: {
|
|
|
// amEndTime: "11:30", //上午结束时间 string
|
| xqd
@@ -640,14 +649,19 @@ class ScheDuleController extends Controller
|
|
|
// status: false, // 是否开启 true false
|
|
|
// timeSpan: "15", // 就诊时长 string
|
|
|
// },
|
|
|
+// $config = [
|
|
|
+// ['amStartTime'],
|
|
|
+// ];
|
|
|
$setting = DocterSetting::where(['docter_id'=>$docter_id])->first()->toArray();
|
|
|
|
|
|
$self_config = object_array(json_decode($setting['service_time']));
|
|
|
+
|
|
|
$is_new = [];
|
|
|
+ $is_change = false;
|
|
|
//
|
|
|
-// if(intval($configData['timeSpan']) != $setting['service_num']){
|
|
|
-// $is_new[] = 4 ;
|
|
|
-// }
|
|
|
+ if(intval($configData['timeSpan']) != $setting['service_num']){
|
|
|
+ $is_change = true;
|
|
|
+ }
|
|
|
//
|
|
|
// if($configData['amStartTime'] != $self_config[1]['amStartTime'] || $configData['amEndTime'] != $self_config[1]['amEndTime']){
|
|
|
// $is_new[] = 1;
|
| xqd
@@ -660,7 +674,10 @@ class ScheDuleController extends Controller
|
|
|
// if($configData['nightStartTime'] != $self_config[3]['nightStartTime'] || $configData['nightEndTime'] != $self_config[3]['nightEndTime']){
|
|
|
// $is_new[] = 3;
|
|
|
// }
|
|
|
-//
|
|
|
+
|
|
|
+ if(intval($configData['timeSpan']) != $setting['service_num']){
|
|
|
+ $is_new = [1,2,3];
|
|
|
+ }
|
|
|
// configData: {
|
|
|
// amEndTime: "11:30", //上午结束时间 string
|
|
|
// amNum: 20, //上午号源 Num
|
| xqd
@@ -677,82 +694,136 @@ class ScheDuleController extends Controller
|
|
|
// timeSpan: "15", // 就诊时长 string
|
|
|
// },
|
|
|
//添加时间段
|
|
|
- $is_new = [1];
|
|
|
- if(count($is_new) > 5){
|
|
|
-// $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(':',$configData['amStartTime']);
|
|
|
-// $amtimes[] = explode(':',$configData['amEndTime']);
|
|
|
-// $amcha = ($amtimes[1][0] - $amtimes[0][0])*60 +($amtimes[1][1] - $amtimes[0][1]);
|
|
|
-// $amCount = $amcha/$data['service_time'];
|
|
|
-// $amCount = intval(floor((strtotime($configData['amEndTime']) - strtotime($configData['amStartTime'])) / (60*$configData['timeSpan'])));
|
|
|
-
|
|
|
-// $pmtimes[] = explode(':',$configData['pmStartTime']);
|
|
|
-// $pmtimes[] = explode(':',$configData['pmEndTime']);
|
|
|
-// $pmCount =intval(floor((strtotime($configData['pmEndTime']) - strtotime($configData['pmStartTime'])) / (60*$configData['timeSpan'])));
|
|
|
-//
|
|
|
-//
|
|
|
-// $evtimes[] = explode(':',$configData['nightStartTime']);
|
|
|
-// $evtimes[] = explode(':',$configData['nightEndTime']);
|
|
|
-// $evcha = ($evtimes[1][0] - $evtimes[0][0])*60 +($evtimes[1][1] - $evtimes[0][1]);
|
|
|
-// $evCount = $evcha/$configData['service_time'];
|
|
|
- $amCount = $configData['amNum'];
|
|
|
- $pmCount = $configData['pmNum'];
|
|
|
- $evCount = $configData['nightNum'];
|
|
|
-
|
|
|
-
|
|
|
- $today_id = Schedule::where(['docter_id'=>$docter_id])->where('schedule_date','=',date('Y-m-d'))->value('id');
|
|
|
- if(in_array(4,$is_new)){
|
|
|
- TimePeriod::where(['docter_id'=>$docter_id])->delete();
|
|
|
- $schuedule_ids = Schedule::where(['docter_id'=>$docter_id])->where(['schedule_date','>',date('Y-m-d')])->pluck('id')->toArray();
|
|
|
- SchedulePeriod::where(['docter_id'=>$docter_id])->whereIn('schedule_id',$schuedule_ids)->delete();
|
|
|
-
|
|
|
- for($i=1;$i<=$amCount;$i++){
|
|
|
- $amdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($configData['amStartTime']) + ($i-1)*$configData['timeSpan']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($configData['amStartTime']) + $i*$configData['timeSpan']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($amdata);
|
|
|
- }
|
|
|
-
|
|
|
- for($i=1;$i<=$pmCount;$i++){
|
|
|
- $pmdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($configData['pmStartTime']) + ($i-1)*$configData['timeSpan']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($configData['pmStartTime']) + $i*$configData['timeSpan']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($pmdata);
|
|
|
- }
|
|
|
-
|
|
|
- for($i=1;$i<=$evCount;$i++){
|
|
|
- $evdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + ($i-1)*$configData['timeSpan']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + $i*$configData['timeSpan']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($evdata);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(in_array(1,$is_new)){
|
|
|
-
|
|
|
- TimePeriod::where(['docter_id'=>$docter_id,'type'=>1])->delete();
|
|
|
- $old_ids = SelfSchedule::where(['docter_id'=>$docter_id,'type'=>1])->distinct('week')->pluck('week','type')->toArray();
|
|
|
-
|
|
|
- $schedule_ids = Schedule::where(['docter_id'=>$docter_id])->where(['schedule_date','>',date('Y-m-d')])->pluck('id')->toArray();
|
|
|
- SelfSchedule::where(['docter_id'=>$docter_id,'type'=>1])->whereIn('schedule_id',$schedule_ids)->delete();
|
|
|
-
|
|
|
- SchedulePeriod::where(['docter_id'=>$docter_id])->whereIn('schedule_id',$schedule_ids)->delete();
|
|
|
- for($i=1;$i<=$amCount;$i++){
|
|
|
- $amdata = [
|
|
|
- 'docter_id'=>$docter_id,
|
|
|
- 'start_time_period'=> date('H:i',strtotime($configData['amStartTime']) + ($i-1)*$configData['timeSpan']*60),
|
|
|
- 'end_time_period'=> date('H:i',strtotime($configData['amStartTime']) + $i*$configData['timeSpan']*60),
|
|
|
- ];
|
|
|
- TimePeriod::insert($amdata);
|
|
|
+ $is_new = [2,3];
|
|
|
+ $amCount = $configData['amNum'];
|
|
|
+ $pmCount = $configData['pmNum'];
|
|
|
+ $evCount = $configData['nightNum'];
|
|
|
+ $c_r = [
|
|
|
+ ['count'=>$configData['amNum'],'start_time'=>$configData['amStartTime'],'end_time'=>$configData['amEndTime']],
|
|
|
+ ['count'=>$configData['pmNum'],'start_time'=>$configData['pmStartTime'],'end_time'=>$configData['pmEndTime']],
|
|
|
+ ['count'=>$configData['nightNum'],'start_time'=>$configData['nightStartTime'],'end_time'=>$configData['nightEndTime']]
|
|
|
+ ];
|
|
|
+ if($is_change){
|
|
|
+
|
|
|
+ if(in_array(1,$is_new)) {
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => 1])->pluck('id')->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => 1])->distinct('type')->orderBy('week')->pluck('week')->toArray();
|
|
|
+ $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $schedule_type, 'type' => 1])->distinct('type')
|
|
|
+ ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
+ SchedulePeriod::where(['docter_id' => $docter_id])->where('schedule_date', '>', date('Y-m-d', time()))->delete();
|
|
|
+ if (empty($week_schedule)) {
|
|
|
+ Schedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ SelfSchedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ } else {
|
|
|
+ $schedule = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id])
|
|
|
+ ->where('schedule_date','>',date('Y-m-d',time()))->pluck('schedule_date','id')->toArray();
|
|
|
+// $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id' => $org_id])->pluck('schedule_date', 'id')->toArray();
|
|
|
+ foreach ($schedule as $id => $date) {
|
|
|
+ $week = intval(date('N', strtotime($date)));
|
|
|
+ foreach ($week_schedule as $w) {
|
|
|
+ if ($week == $w) {
|
|
|
+ foreach ($time_periods as $idt) {
|
|
|
+ $s_t = [
|
|
|
+ 'organization_id' => $org_id,
|
|
|
+ 'docter_id' => $docter_id,
|
|
|
+ 'type' => $type,
|
|
|
+ 'schedule_date' => $date,
|
|
|
+ 'schedule_id' => $id,
|
|
|
+ 'time_period_id' => $idt
|
|
|
+ ];
|
|
|
+ $schedule_is_have = SchedulePeriod::where($s_t)->count();
|
|
|
+ if ($schedule_is_have) continue;
|
|
|
+ $s_t['created_at'] = Carbon::now();
|
|
|
+ $s_t['updated_at'] = Carbon::now();
|
|
|
+ if ($self_schedule == 1) $s_t['me_sure'] = 1;
|
|
|
+ SchedulePeriod::insert($s_t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SelfSchedule::where(['type'=>1,'docter_id'=>$docter_id,'organization_id'=>$org_id])->whereIn('time_period_id',$time_periods)->delete();
|
|
|
+ foreach ($self_schedule as $val) {
|
|
|
+ $self_data = $val;
|
|
|
+ $self_data['organization_id'] = $org_id;
|
|
|
+ $self_data['docter_id'] = $docter_id;
|
|
|
+ foreach ($time_periods 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ dd($e->getMessage());
|
|
|
+ DB::rollBack();
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+// SelfSchedule::where(['docter_id'=>$docter_id,'type'=>1])->whereIn('schedule_id',$schedule_ids)->delete();
|
|
|
if(in_array(2,$is_new)){
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => 2])->pluck('id')->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => 2])->distinct('type')->orderBy('week')->pluck('week')->toArray();
|
|
|
+ $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $schedule_type, 'type' => 2])->distinct('type')
|
|
|
+ ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
+ SchedulePeriod::where(['docter_id' => $docter_id])->where('schedule_date', '>', date('Y-m-d', time()))->delete();
|
|
|
+ if (empty($week_schedule)) {
|
|
|
+ Schedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ SelfSchedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ } else {
|
|
|
+ $schedule = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id])
|
|
|
+ ->where('schedule_date','>',date('Y-m-d',time()))->pluck('schedule_date','id')->toArray();
|
|
|
+ $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id' => $org_id])->pluck('schedule_date', 'id')->toArray();
|
|
|
+ foreach ($schedule as $id => $date) {
|
|
|
+ $week = intval(date('N', strtotime($date)));
|
|
|
+ foreach ($week_schedule as $w) {
|
|
|
+ if ($week == $w) {
|
|
|
+ foreach ($time_periods as $idt) {
|
|
|
+ $s_t = [
|
|
|
+ 'organization_id' => $org_id,
|
|
|
+ 'docter_id' => $docter_id,
|
|
|
+ 'type' => $type,
|
|
|
+ 'schedule_date' => $date,
|
|
|
+ 'schedule_id' => $id,
|
|
|
+ 'time_period_id' => $idt
|
|
|
+ ];
|
|
|
+ $schedule_is_have = SchedulePeriod::where($s_t)->count();
|
|
|
+ if ($schedule_is_have) continue;
|
|
|
+ $s_t['created_at'] = Carbon::now();
|
|
|
+ $s_t['updated_at'] = Carbon::now();
|
|
|
+ if ($self_schedule == 1) $s_t['me_sure'] = 1;
|
|
|
+ SchedulePeriod::insert($s_t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SelfSchedule::where(['type'=>2,'docter_id'=>$docter_id,'organization_id'=>$org_id])->whereIn('time_period_id',$time_periods)->delete();
|
|
|
+ foreach ($self_schedule as $val) {
|
|
|
+ $self_data = $val;
|
|
|
+ $self_data['organization_id'] = $org_id;
|
|
|
+ $self_data['docter_id'] = $docter_id;
|
|
|
+ foreach ($time_periods 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ dd($e->getMessage());
|
|
|
+ DB::rollBack();
|
|
|
+ }
|
|
|
for($i=1;$i<=$pmCount;$i++){
|
|
|
$pmdata = [
|
|
|
'docter_id'=>$docter_id,
|
| xqd
@@ -763,17 +834,81 @@ class ScheDuleController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(in_array(2,$is_new)) {
|
|
|
- for($i=1;$i<=$evCount;$i++){
|
|
|
+ if(in_array(3,$is_new)){
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $time_periods = TimePeriod::where(['org_id' => $org_id, 'docter_id' => $docter_id, 'type' => 3])->pluck('id')->toArray();
|
|
|
+ $week_schedule = WeekSchedule::where(['docter_id' => $docter_id, 'type' => 3])->distinct('type')->orderBy('week')->pluck('week')->toArray();
|
|
|
+ $self_schedule = SelfSchedule::where(['docter_id' => $docter_id, 'schedule_type' => $schedule_type, 'type' => 3])->distinct('type')
|
|
|
+ ->orderBy('schedule_date')->get(['schedule_date', 'type', 'week'])->toArray();
|
|
|
+ SchedulePeriod::where(['docter_id' => $docter_id])->where('schedule_date', '>', date('Y-m-d', time()))->delete();
|
|
|
+ if (empty($week_schedule)) {
|
|
|
+ Schedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ SelfSchedule::where(['docter_id' => $docter_id])->delete();
|
|
|
+ } else {
|
|
|
+ $schedule = Schedule::where(['docter_id'=>$docter_id,'organization_id'=>$org_id])
|
|
|
+ ->where('schedule_date','>',date('Y-m-d',time()))->pluck('schedule_date','id')->toArray();
|
|
|
+// $schedule = Schedule::where(['docter_id' => $docter_id, 'organization_id' => $org_id])->pluck('schedule_date', 'id')->toArray();
|
|
|
+ foreach ($schedule as $id => $date) {
|
|
|
+ $week = intval(date('N', strtotime($date)));
|
|
|
+ foreach ($week_schedule as $w) {
|
|
|
+ if ($week == $w) {
|
|
|
+ foreach ($time_periods as $idt) {
|
|
|
+ $s_t = [
|
|
|
+ 'organization_id' => $org_id,
|
|
|
+ 'docter_id' => $docter_id,
|
|
|
+ 'type' => $type,
|
|
|
+ 'schedule_date' => $date,
|
|
|
+ 'schedule_id' => $id,
|
|
|
+ 'time_period_id' => $idt
|
|
|
+ ];
|
|
|
+ $schedule_is_have = SchedulePeriod::where($s_t)->count();
|
|
|
+ if ($schedule_is_have) continue;
|
|
|
+ $s_t['created_at'] = Carbon::now();
|
|
|
+ $s_t['updated_at'] = Carbon::now();
|
|
|
+ if ($self_schedule == 1) $s_t['me_sure'] = 1;
|
|
|
+ SchedulePeriod::insert($s_t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SelfSchedule::where(['type'=>3,'docter_id'=>$docter_id,'organization_id'=>$org_id])->whereIn('time_period_id',$time_periods)->delete();
|
|
|
+ foreach ($self_schedule as $val) {
|
|
|
+ $self_data = $val;
|
|
|
+ $self_data['organization_id'] = $org_id;
|
|
|
+ $self_data['docter_id'] = $docter_id;
|
|
|
+ foreach ($time_periods 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ dd($e->getMessage());
|
|
|
+ DB::rollBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ foreach ($is_new as $c){
|
|
|
+ for($i=1;$i<=$c_r[$c];$i++){
|
|
|
$evdata = [
|
|
|
'docter_id'=>$docter_id,
|
|
|
'start_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + ($i-1)*$configData['timeSpan']*60),
|
|
|
'end_time_period'=> date('H:i',strtotime($configData['nightStartTime']) + $i*$configData['timeSpan']*60),
|
|
|
];
|
|
|
+ $is_have = TimePeriod::where($evdata);
|
|
|
+ if($is_have) continue;
|
|
|
TimePeriod::insert($evdata);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
// {"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 = [
|
| xqd
@@ -1049,7 +1184,7 @@ class ScheDuleController extends Controller
|
|
|
{
|
|
|
$docter_id = request('docter_id',1);
|
|
|
$org_id = request('org_id',1);
|
|
|
- $type = request('type',2);
|
|
|
+ $type = request('type',1);
|
|
|
if(empty($docter_id) || empty($org_id) || empty($type)){
|
|
|
return apiReturn(601,'缺少必要参数');
|
|
|
}
|
| xqd
@@ -1099,6 +1234,7 @@ class ScheDuleController extends Controller
|
|
|
'organization_id'=>$org_id,
|
|
|
'docter_id'=>$docter_id
|
|
|
];
|
|
|
+
|
|
|
$k = 0;
|
|
|
DB::beginTransaction();
|
|
|
// $data[0] = array_values(object_array(json_decode($data[0])));
|
| xqd
@@ -1141,4 +1277,14 @@ class ScheDuleController extends Controller
|
|
|
}
|
|
|
return apiReturn(200,'ok',$k);
|
|
|
}
|
|
|
+
|
|
|
+ public static function get_cloumn_value($arr,$cloumn,$index=''){
|
|
|
+ if(!is_array($arr) || count($arr) == 0) return [];
|
|
|
+ foreach ($arr as $key => $val){
|
|
|
+ $arr[$key] = array_column($val,$cloumn,$index);
|
|
|
+ }
|
|
|
+ return $arr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|