Merge branch 'master' into develop

# Conflicts:
#	app/inquiry/service/FbFileImportService.php
This commit is contained in:
mzl
2025-12-22 16:23:05 +08:00
parent 4acb89e56a
commit ebcabb23df
+44 -26
View File
@@ -209,55 +209,73 @@ class FbFileImportService
}
/**
* ✅ 方案B:把 FB 创建时间统一转成 MySQL DATETIME(Y-m-d H:i:s)
*
* 支持:
* - "10/13/25" / "12/8/25"
* - "2025-12-08 13:22:11"
* - Excel 日期序列(数字)
*
* 解析失败:返回 null(让 DB 用默认值/允许为空)
* 注意:如果你的 fb_created_time 列是 NOT NULL 且无默认值,请把 null 改成 '1970-01-01 00:00:00'
* 方案B:写 DATETIME,且永不为 null(因为 fb_created_time NOT NULL)
* 兼容:
* - Excel 数字日期
* - 10/13/25
* - 2025-12-10 04:25:09
* - 25年12月21日 / 2025年12月21日
* - 25年12月21日 13:05 / 25年12月21日13:05:09
* 为空/解析失败:用当前时间兜底
*/
protected function normalizeCreatedTime($raw): ?string
protected function normalizeCreatedTime($raw): string
{
if ($raw === null || $raw === '') {
return null;
}
$fallback = date('Y-m-d H:i:s');
if ($raw === null) return $fallback;
// Excel 日期序列:数字
if (is_numeric($raw)) {
$n = (float)$raw;
// Excel serial date -> unix timestamp
$ts = (int)round(($n - 25569) * 86400);
if ($ts > 0) {
return date('Y-m-d H:i:s', $ts);
}
return null;
if ($ts > 0) return date('Y-m-d H:i:s', $ts);
return $fallback;
}
$s = trim((string)$raw);
if ($s === '') {
return null;
}
if ($s === '') return $fallback;
// 1) strtotime 能解析很多格式
// 先尝试 strtotime(能覆盖很多格式:2025-12-10 04:25:09 / 2025/12/10 等)
$ts = strtotime($s);
if ($ts !== false) {
return date('Y-m-d H:i:s', $ts);
}
// 2) 兼容 m/d/yy(如 10/13/25)
// m/d/yy:10/13/25
if (preg_match('#^(\d{1,2})/(\d{1,2})/(\d{2})$#', $s, $m)) {
$mm = (int)$m[1];
$dd = (int)$m[2];
$yy = (int)$m[3];
$year = 2000 + $yy; // FB 导出通常是 20xx
$year = 2000 + $yy;
$ts2 = mktime(0, 0, 0, $mm, $dd, $year);
return date('Y-m-d H:i:s', $ts2);
}
// 3) 兜底:无法解析
return null;
// ✅ 中文日期:25年12月21日 / 2025年12月21日(可带时间)
// 支持:
// - 25年12月21日
// - 2025年12月21日
// - 25年12月21日 13:05
// - 25年12月21日13:05:09
$cn = preg_replace('/\s+/', '', $s); // 去空格方便匹配
if (preg_match('/^(\d{2,4})年(\d{1,2})月(\d{1,2})日(?:(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/u', $cn, $m)) {
$y = (int)$m[1];
$month = (int)$m[2];
$day = (int)$m[3];
// 2位年 -> 2000+(你这里是 25年 = 2025)
if ($y < 100) $y += 2000;
$hh = isset($m[4]) && $m[4] !== '' ? (int)$m[4] : 0;
$ii = isset($m[5]) && $m[5] !== '' ? (int)$m[5] : 0;
$ss = isset($m[6]) && $m[6] !== '' ? (int)$m[6] : 0;
$ts3 = mktime($hh, $ii, $ss, $month, $day, $y);
return date('Y-m-d H:i:s', $ts3);
}
// 解析失败兜底:当前时间
return $fallback;
}
}