From 6ad6980234bf8a8d1398cc2230308966dcb70909 Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Mon, 2 Nov 2026 10:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC66=E6=89=B9-PHP=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=88=B3=E5=BD=92=E4=B8=80=E5=8C=96+=E5=8E=BB=E9=87=8D?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20-=20=E6=96=B0=E5=A2=9E=20creditNormalizeTi?= =?UTF-8?q?mestamps:=20=E8=BF=94=E5=9B=9E=E8=B7=AF=E5=BE=84=E5=BD=92?= =?UTF-8?q?=E4=B8=80=E5=8C=96=EF=BC=8C>9999999999=20=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E6=AF=AB=E7=A7=92=E8=87=AA=E5=8A=A8=20/1000=20=E6=8A=98?= =?UTF-8?q?=E7=A7=92=20-=20=E8=A6=86=E7=9B=96=20my=5Frecords/my=5Freports/?= =?UTF-8?q?pending=5Flist/approved=5Flist/sync=5Fpull=205=E6=9D=A1?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=20-=20=E4=BF=AE=E5=A4=8D=E6=97=A7=E8=AE=B0?= =?UTF-8?q?=E5=BD=95(=E6=AF=AB=E7=A7=92)=E4=B8=8E=E6=96=B0=E8=AE=B0?= =?UTF-8?q?=E5=BD=95(=E7=A7=92)=E5=85=B1=E5=AD=98=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E6=BC=8F=E5=88=A4=EF=BC=9Acreated=5Fat=20?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=8C=B9=E9=85=8D=E7=A7=92=E5=80=BC=E5=92=8C?= =?UTF-8?q?=E6=AF=AB=E7=A7=92=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/credit.php | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/api/credit.php b/api/credit.php index 96d3235..c3eb7b3 100644 --- a/api/credit.php +++ b/api/credit.php @@ -127,6 +127,27 @@ function creditRequireAdmin() { } } +/** + * ★ 第66批修复(#346):时间戳归一化 + * Java 推送的历史记录 created_at/approved_at 存的是毫秒(System.currentTimeMillis) + * 前端统一按 `new Date(ts * 1000)` 渲染(秒语义) + * → 大于 9999999999 的数值判定为毫秒,除以 1000 折成秒 + * 对新记录(已是秒)无影响,对旧记录(毫秒)自动修复 + */ +function creditNormalizeTimestamps($records) { + if (!is_array($records)) return $records; + foreach ($records as &$r) { + if (isset($r['created_at']) && $r['created_at'] > 9999999999) { + $r['created_at'] = (int)($r['created_at'] / 1000); + } + if (isset($r['approved_at']) && $r['approved_at'] > 9999999999) { + $r['approved_at'] = (int)($r['approved_at'] / 1000); + } + } + unset($r); + return $records; +} + /** * ★ 第58批续29-问题2:审批/调整积分后通知 Java 立即拉取信誉积分数据 * 写入 sync_requests 标记,Java 的 doActiveSyncBatch 检测到后会执行 pullCreditFromPhp @@ -207,7 +228,7 @@ switch ($action) { $res = $stmt->execute(); $records = []; while ($row = $res->fetchArray(SQLITE3_ASSOC)) $records[] = $row; - success(['records' => $records]); + success(['records' => creditNormalizeTimestamps($records)]); break; // ====== 用户端:查看自己提交的上报(我的上报) ====== @@ -219,7 +240,7 @@ switch ($action) { $res = $stmt->execute(); $records = []; while ($row = $res->fetchArray(SQLITE3_ASSOC)) $records[] = $row; - success(['records' => $records]); + success(['records' => creditNormalizeTimestamps($records)]); break; // ====== 用户端:撤回自己提交的未批准/驳回的上报 ====== @@ -262,7 +283,7 @@ switch ($action) { $res = $stmt->execute(); $records = []; while ($row = $res->fetchArray(SQLITE3_ASSOC)) $records[] = $row; - success(['records' => $records]); + success(['records' => creditNormalizeTimestamps($records)]); break; // ====== 管理员:审批通过 ====== @@ -327,7 +348,7 @@ switch ($action) { $res = $stmt->execute(); $records = []; while ($row = $res->fetchArray(SQLITE3_ASSOC)) $records[] = $row; - success(['records' => $records]); + success(['records' => creditNormalizeTimestamps($records)]); break; // ====== 管理员:查看所有规则 ====== @@ -496,11 +517,15 @@ switch ($action) { if (!$target || !$createdAt) continue; // 去重检查 - $stmt = $db->prepare("SELECT 1 FROM credit_records WHERE target_player = ? AND source = ? AND created_at = ? AND type = ?"); + // ★ 第66批修复(#346):旧记录 created_at 是毫秒,新记录存秒 + // 去重时需同时匹配秒值和毫秒值,否则旧记录会被重复插入 + $createdAtMs = $createdAt * 1000; + $stmt = $db->prepare("SELECT 1 FROM credit_records WHERE target_player = ? AND source = ? AND type = ? AND (created_at = ? OR created_at = ?)"); $stmt->bindValue(1, $target, SQLITE3_TEXT); $stmt->bindValue(2, $source, SQLITE3_TEXT); - $stmt->bindValue(3, $createdAt, SQLITE3_INTEGER); - $stmt->bindValue(4, $type, SQLITE3_TEXT); + $stmt->bindValue(3, $type, SQLITE3_TEXT); + $stmt->bindValue(4, $createdAt, SQLITE3_INTEGER); + $stmt->bindValue(5, $createdAtMs, SQLITE3_INTEGER); $res = $stmt->execute(); if ($row = $res->fetchArray()) continue; // 已存在,跳过 @@ -595,6 +620,7 @@ switch ($action) { while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $records[] = $row; } + $records = creditNormalizeTimestamps($records); // ★ 第64批:返回所有规则(Java 端同步用) $stmt = $db->prepare("SELECT id, rule_name, min_score, max_score, restriction_type, restriction_duration, enabled, description, limit_amount, multiplier, amount FROM credit_rules ORDER BY id");