From ffa8b4cce0fe1bdc49ac58a21bcf15d2078c9a3a Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Mon, 13 Jul 2026 20:35:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D(today=5Fbonds):=20=E6=B6=88?= =?UTF-8?q?=E8=B4=B9=E6=94=B6=E5=85=A5=E9=9C=80=E5=90=8C=E6=97=B6=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1web=5Ftransactions=E5=92=8Cgame=5Ftransactions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户截图中的 shop_buy 等支出记录在 game_transactions 表而非 web_transactions 表,之前的查询只覆盖 web_transactions 导致消费为0。 现在合并两个表的数据:game_transactions.amount < 0 也计入消费, amount > 0 也计入收入。 --- today_bonds.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/today_bonds.php b/today_bonds.php index 0d5d79b..bb813b6 100644 --- a/today_bonds.php +++ b/today_bonds.php @@ -17,27 +17,45 @@ function getTodayBondData() { global $todayStart, $todayEnd; $spendData = []; $incomeData = []; - // web.db 今日债券变动:amount > 0 为收入,amount < 0 为消费(取绝对值) try { $db = getDB(); - // 收入 - $stmt = $db->prepare("SELECT player_name, SUM(amount) AS total_income FROM web_transactions WHERE amount > 0 AND created_at >= :start AND created_at < :end GROUP BY player_name ORDER BY total_income DESC"); + // ===== web_transactions(Web端交易) ===== + // 收入(amount > 0) + $stmt = $db->prepare("SELECT player_name, SUM(amount) AS total_income FROM web_transactions WHERE amount > 0 AND created_at >= :start AND created_at < :end GROUP BY player_name"); $stmt->bindValue(':start', $todayStart, SQLITE3_INTEGER); $stmt->bindValue(':end', $todayEnd, SQLITE3_INTEGER); $res = $stmt->execute(); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { - $incomeData[$row['player_name']] = (int)$row['total_income']; + $incomeData[$row['player_name']] = ($incomeData[$row['player_name']] ?? 0) + (int)$row['total_income']; } - // 消费(负金额绝对值) - $stmt2 = $db->prepare("SELECT player_name, SUM(ABS(amount)) AS total_spend FROM web_transactions WHERE amount < 0 AND created_at >= :start AND created_at < :end GROUP BY player_name ORDER BY total_spend DESC"); + // 消费(amount < 0 取绝对值) + $stmt2 = $db->prepare("SELECT player_name, SUM(ABS(amount)) AS total_spend FROM web_transactions WHERE amount < 0 AND created_at >= :start AND created_at < :end GROUP BY player_name"); $stmt2->bindValue(':start', $todayStart, SQLITE3_INTEGER); $stmt2->bindValue(':end', $todayEnd, SQLITE3_INTEGER); $res2 = $stmt2->execute(); while ($row = $res2->fetchArray(SQLITE3_ASSOC)) { - $spendData[$row['player_name']] = (int)$row['total_spend']; + $spendData[$row['player_name']] = ($spendData[$row['player_name']] ?? 0) + (int)$row['total_spend']; + } + + // ===== game_transactions(游戏内交易) ===== + // 收入(amount > 0) + $stmt3 = $db->prepare("SELECT player_name, SUM(amount) AS total_income FROM game_transactions WHERE amount > 0 AND tx_time >= :start2 AND tx_time < :end2 GROUP BY player_name"); + $stmt3->bindValue(':start2', $todayStart, SQLITE3_INTEGER); + $stmt3->bindValue(':end2', $todayEnd, SQLITE3_INTEGER); + $res3 = $stmt3->execute(); + while ($row = $res3->fetchArray(SQLITE3_ASSOC)) { + $incomeData[$row['player_name']] = ($incomeData[$row['player_name']] ?? 0) + (int)$row['total_income']; + } + // 消费(amount < 0 取绝对值) + $stmt4 = $db->prepare("SELECT player_name, SUM(ABS(amount)) AS total_spend FROM game_transactions WHERE amount < 0 AND tx_time >= :start3 AND tx_time < :end3 GROUP BY player_name"); + $stmt4->bindValue(':start3', $todayStart, SQLITE3_INTEGER); + $stmt4->bindValue(':end3', $todayEnd, SQLITE3_INTEGER); + $res4 = $stmt4->execute(); + while ($row = $res4->fetchArray(SQLITE3_ASSOC)) { + $spendData[$row['player_name']] = ($spendData[$row['player_name']] ?? 0) + (int)$row['total_spend']; } } catch (\Throwable $e) { - debugLog('[today_bonds] 查询 web_transactions 异常: ' . $e->getMessage()); + debugLog('[today_bonds] 查询异常: ' . $e->getMessage()); } $allPlayers = array_unique(array_merge(array_keys($spendData), array_keys($incomeData))); $rows = [];