<?php
class CheckTheTime{
private $arrHoliday;
private $arrWeekend;
private $arrWorkTime;
private function __construct(){
$this->arrHoliday = [
'2017-05-01',
'2017-05-02',
'2017-05-03'
];
$this->arrWeekend = [
0,6
];
$this->arrWorkTime = [
'on' => 9,
'off' => 18,
];
}
public function judge(){
$intTime = time();
$boolHoliday = in_array(date('Y-m-d', $intTime), $this->arrHoliday);
$boolWeekend = in_array(date('w', $intTime), $this->arrWeekend);
$boolWorkTime = !$boolHoliday && !$boolWeekend && (date("H", $intTime) < $this->arrWorkTime['on']) && (date('H', $intTime) > $this->arrWorkTime['off']);
if($boolHoliday) {
echo "现在是假期时间,还让不让人好好休假了?!";
} else if($boolWeekend) {
echo "现在是周末哟,不上班的哟";
} else if($boolWorkTime) {
echo "抱歉,现在不是上班时间.";
} else {
echo "您好,请问有什么可以帮到您?";
}
}
?>
大致写了一个类,你看看能不能用,我没太仔细测,建议吧假期什么的写成配置;