isset($Info['model_id']) ? $Info['model_id'] : null, 'dateRange' => isset($Info['dateRange']) ? $Info['dateRange'] : null, 'week' => isset($Info['week']) ? $Info['week'] : null, 'workday_create' => isset($Info['workday_create']) ? $Info['workday_create'] : null, 'holiday_create' => isset($Info['holiday_create']) ? $Info['holiday_create'] : null, ]; $requiredFields = ['model_id' => '模板id', 'dateRange' => '日期', 'week' => '星期', 'workday_create' => '工作日是否生成', 'holiday_create' => '节假日是否生成']; // 判断是否为空 foreach ($requiredFields as $key => $field) { if (!isset($params[$key]) || $params[$key] === null) { return \Yz::echoError1('参数 ' . $field . ' 不能为空'); } } if (!isset($Info['dateRange']) or count($Info['dateRange']) <> 2) { return \Yz::echoError1('起止时间格式错误'); } $model = DB::table('plan_model as a')->where(['a.id' => $params['model_id'], 'a.is_del' => 0, 'a.status' => 1])->first(); if (!$model) return \Yz::echoError1('模板不可用'); $planType = DB::table('plan_type as a')->where(['a.id' => $model->plan_type, 'a.is_del' => 0, 'a.status' => 1])->first(); if (!$planType) return \Yz::echoError1('号源类型不可用'); //查询此时间段内是否有已经生成的号源 $cha=DB::table('plans')->whereBetween('date',$Info['dateRange'])->get(); if(count($cha)>0){ return \Yz::return(false,'号源重复',['list'=>$cha]); } //获取模板的全部时间点 $s=new TimeService(); $timelist=$s->TimePointsArr($model->start_time,$model->end_time,$model->interval_time); if(count($timelist)<1) return \Yz::echoError1('模板时间点不能为空'); $startDate = new DateTime($Info['dateRange'][0]); $endDate = new DateTime($Info['dateRange'][1]); $currentDate = $startDate; $success_count=0; while ($currentDate <= $endDate) { //循环生成 $date_ymd=$currentDate->format('Y-m-d'); //判断节假日是否生成 $s_day=DB::table('plan_holiday')->select('*','type as tp')->where(['date'=>$date_ymd])->first(); if(!!$s_day){ if($s_day->tp==1 and $params['workday_create']===0){ $currentDate->modify('+1 day'); continue; } if($s_day->tp==2 and $params['holiday_create']===0){ $currentDate->modify('+1 day'); continue; } } //获取星期几 星期1=1 星期日=7 $dayOfWeek = $currentDate->format('N'); //如果星期匹配上了 if(in_array($dayOfWeek, $params['week'])) { foreach ($timelist as $key=>$time){ $type=1; //正常 if(in_array($key,json_decode($model->y_number,true))){ $type=0;//预留 } $data=[ 'model_id'=>$model->id, 'date'=>$date_ymd, 'week'=>$dayOfWeek, 'time'=>$time, 'type'=>$type, 'plan_number'=>implode('', explode(':', $time)), 'is_vip'=>$planType->is_vip, 'use_type'=>$planType->use_type, 'sex'=>$planType->sex, 'checkup_type_id'=>$planType->checkup_type_id, 'amount_limit1'=>$planType->amount_limit1, 'amount_limit2'=>$planType->amount_limit2, 'hospital_id'=>$model->hospital_id, 'status'=>1, 'is_del'=>0 ]; $i=DB::table('plans')->insert($data); if($i){ $success_count++; } } } // 日期加一天 $currentDate->modify('+1 day'); } if($success_count>0){ return \Yz::Return(true,'',['success_count'=>$success_count]); }else{ return \Yz::echoError1('没有计划被创建'); } } }