判断某天是否节假日


/**
* 判定某天是否是假期
* $date 格式“2018-8-8” 默认为当天
* return true 假日,false 上班
* Evin
* 2018.3.15
*/
function _today_is_holiday($date = false)
{
if (!$date) {
$date = date('Y-n-j', time());
}
//$date = '2018-3-17';
//第三方获取节假日
$map['jh_time'] = strtotime(date('Y-n', strtotime($date)));
$holiday = M('JuheHoliday')->where($map)->find();
if ($holiday) {
$holiday = json_decode($holiday['jh_content'], true);
} else {
$year_month = date('Y-n', strtotime($date));
$date_info = juhecurl('http://v.juhe.cn/calendar/month', 'year-month=' . $year_month . '&key=' . C('JUHEAPPKEY'));
$date_info = json_decode($date_info, true);
$date_info = json_decode($date_info['result']['data']['holiday'], true);
$list = array();
foreach ($date_info as $k => $v) {
if ($list) {
foreach ($v['list'] as $key => $val) {
array_push($list, $val);
}
} else {
$list = $v['list'];
}
}
$data['jh_content'] = json_encode($list);
$data['jh_time'] = strtotime($year_month);
M('JuheHoliday')->add($data);
$holiday = json_decode($data['jh_content'], true);
}
$ret = false;
$week = date('w', strtotime($date));
//周末
if ($week == 0 || $week == 6) {
$ret = true;
}
//法定节假日
foreach ($holiday as $k => $v) {
if ($date == $v['date']) {
if ($v['status'] == '1') {
$ret = true;
break;
} else {
$ret = false;
}
}
}
return $ret;
}

http://v.juhe.cn/calendar/month改地址是第三方
posted @ 2022-11-14 18:52  田宝宝  阅读(49)  评论(0编辑  收藏  举报