You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP预订系统跨年度季节日期匹配时第3季判定失效排查

问题根因

季节3判定失效的核心原因有2个:

  • 起止日期年份拼接逻辑不适用于跨自然年场景
    你现在直接用预订开始年份$BSyear拼接季节3开始日期、预订结束年份$BEyear拼接季节3结束日期,对于12月到次年3月的跨年度季节来说,会出现结束日期时间戳小于开始日期的异常:
    举个例子,预订时间为2023-12-10到2023-12-20,你拼接出来的季节3起止为2023-12-01到2023-03-31,后者时间戳远小于前者,时间比较逻辑直接失效。
  • 判定逻辑未适配跨年度特性
    你当前的季节3判定逻辑$booking_start >= $season3_start && $booking_end <= $season3_end只适用于起止日期在同一年的场景,完全覆盖不了季节3跨年度的正常情况。
修复方案

1. 修正季节3起止日期拼接逻辑

替换你原代码中季节3的起止拼接部分:

//Season 3 start    
list($SS3year, $SS3month, $SS3day) = explode("-", $SS3);
list($SE3year, $SE3month, $SE3day) = explode("-", $SE3);
// 根据预订开始月份判断所属季节3的年份
if ($BSmonth >= 12) {
    // 12月预订,属于当年12月到次年3月的季节3
    $season3_start = strtotime($BSyear.'-'.$SS3month.'-'.$SS3day);
    $season3_end = strtotime(($BSyear + 1).'-'.$SE3month.'-'.$SE3day);
} elseif ($BSmonth <=3) {
    // 1-3月预订,属于上一年12月到当年3月的季节3
    $season3_start = strtotime(($BSyear - 1).'-'.$SS3month.'-'.$SS3day);
    $season3_end = strtotime($BSyear.'-'.$SE3month.'-'.$SE3day);
} else {
    // 非季节3时段,赋值不影响判定
    $season3_start = 0;
    $season3_end = 0;
}

2. 修正季节3判定逻辑

替换原季节3判定代码即可:

//compleatly season 3
if($season3_start >0 && $booking_start >= $season3_start && $booking_end <= $season3_end) {
    $low_mid_peak_switch = 3;
    echo '<span style="color:red;">'.'Booking is compleatly in SEASON 3'.'</span>';
    echo '<BR>';
    $datediff = $booking_end - $booking_start;
    echo '<span style="color:LightSeaGreen;">'.round($datediff / (60 * 60 * 24)).' days @ Season 3 price $'.'</span>';
    echo '<BR>';
    exit;
}
可选优化

三个季节的数据库查询、日期拼接逻辑高度重复,可封装为公共函数减少冗余代码,降低后续维护成本。

内容的提问来源于stack exchange,提问作者Timespider

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 03:45:05