🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
根据下单日期,获得最早可预约时间(可预约时间可以根据需求调整) ``` //测试 public function jisuan_riqi(){ $create_time = '2020-04-09';//下单时间 $jiejia_date = ['2019-12-31'=>2,'2020-01-23'=>8,'2020-04-03'=>4,'2020-04-30'=>6,'2020-06-24'=>4,'2020-09-31'=>9];//国家法定假 $work_date = 3;//下单时间距预约的时间(相当于三个工作日才能约) $yuyue_time = $this->yuyue_date($create_time,$jiejia_date,$work_date); var_dump($yuyue_time);die; } //获得当前月的周末集合 public function dangyue($create_time){ $strtotime = strtotime($create_time); $month = date('m',$strtotime); $year = date('Y',$strtotime); $days = date("t", mktime(0,0,0, $month, 1, $year));//当年当月的天数 $startweek = date("w", mktime(0,0,0, $month, 1, $year)); $nums = $startweek; $datea = []; for($i=0;$i<$days;$i++){ $str = ($i+1 > 9)?$i+1:'0'.($i+1); if($nums == 6){ $datea[] = "$year-$month-".$str; }elseif($nums == 7){ $datea[] = "$year-$month-".$str; $nums = 0; } $nums++; } return $datea; } /** *计算可预约时间函数 *@param $create_time 创建时间 *@param $jiejia_date 节假日集合 *@param $work_date 下单时间距预约的时间(相当于三个工作日才能约) **/ public function yuyue_date($create_time,$jiejia_date,$work_date,$nums=2){ $time = $create_time; for($s=0;$s<$nums;$s++){ $time = date('Y-m-d',strtotime("{$time}+$s month")); $array = $this->dangyue($time); foreach($array as $k=>$v){ $datea[] = $v; } } //筛选国家法定假 foreach($jiejia_date as $key=>$val){ for($v=0;$v<$val;$v++){ $dateb[] = date('Y-m-d',strtotime("{$key}+1+$v day")); } } $date = array_merge($datea,$dateb); $n = 0; do { $create_time = date('Y-m-d',strtotime("{$create_time}+1 day")); if(!in_array($create_time,$date)){ $n++; } } while ($work_date != $n); return $create_time; } ```