/** * 获取日期 * @param $day * @param $rule * @return $arrivalData */ private function getDay($day, $rule){ $arrivalData = '0000-00-00'; $arrivalDayNum = array(0=>0,1=>1,2=>2,3=>3,4=>0,5=>1,6=>2,7=>3); $arrivalDay = isset($arrivalDayNum[$rule]) ? $arrivalDayNum[$rule] : 0; if (in_array($rule, array(4,5,6,7))) { $arrivalData = date("Y-m-d",strtotime("$day +$arrivalDay day")); }elseif (in_array($rule, array(0,1,2,3))) { $already_add_day = 0; $arrivalData = $day; while($already_add_day<$rule){ $arrivalData = date('Y-m-d', strtotime($arrivalData) + 86400); $day_s = strtotime($arrivalData); $y = date('Y', $day_s); $m = date('m', $day_s); $d = date('d', $day_s); $this->query->clear() ->select('count(1) as `cnt`') ->from('#__holiday_dates') ->where("F_year={$y} and F_month={$m} and F_day={$d} and F_enable=1"); $this->db->sql = $this->query; $cnt = (int) ($this->db->fetch_column('cnt')); if($cnt > 0){ continue; }else{ $already_add_day++; } } } return $arrivalData; }
节假日表结构
CREATE TABLE `t_holiday_dates` ( `F_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `F_year` char(4) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL COMMENT '年', `F_month` char(2) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL COMMENT '月', `F_day` char(2) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL COMMENT '日', `F_create_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间', `F_modify_time` datetime DEFAULT '0000-00-00 00:00:00' COMMENT '修改时间', `F_operator_uid` varchar(64) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL COMMENT '操作人员', `F_enable` tinyint(2) unsigned DEFAULT '1' COMMENT '逻辑状态', PRIMARY KEY (`F_id`) KEY_BLOCK_SIZE=1024, UNIQUE KEY `I_year_month_day` (`F_year`,`F_month`,`F_day`) KEY_BLOCK_SIZE=1024 ) ENGINE=InnoDB AUTO_INCREMENT=589 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 COMMENT='节假日管理表'