fix: 超大 duration_days 导致卡密误标已使用

- 新增 calcExpireTime(): >36500天视为永久(null), 避免超出 MySQL DATETIME
- publicActivate 事务包裹, 失败回滚不残留 used 状态
- verify/订单发卡/自动发卡 统一使用安全过期时间
This commit is contained in:
root committed 2026-10-11 12:40:37 +08:00
1 parent f838f1a3d1
commit b317c1f1d8
4 files changed
+135 -106

No files matched your search

+30
View File
@@ -197,4 +197,34 @@ function beijingTimeFields(array $row, array $fields): array
}
}
return $row;
}
/**
* 根据有效天数计算过期时间
* - days <= 0:永久,返回 null
* - 超大天数(超出 MySQL DATETIME 或 100 年):视为永久 null,避免插入失败导致卡被标已用但无授权
* @return string|null
*/
function calcExpireTime(int $days, ?string $baseTime = null): ?string
{
if ($days <= 0) {
return null;
}
$base = $baseTime ? strtotime($baseTime) : time();
if ($base === false) {
$base = time();
}
// 超过约 100 年视为永久(避免 strtotime 溢出 / 超出 DATETIME 9999-12-31)
if ($days > 36500) {
return null;
}
$ts = strtotime("+{$days} days", $base);
if ($ts === false) {
return null;
}
$max = strtotime('9999-12-31 23:59:59');
if ($ts === false || $ts > $max) {
return '9999-12-31 23:59:59';
}
return date('Y-m-d H:i:s', $ts);
}