setTime(0, 0, 0)->getTimestamp(); $todayEnd = $todayStart + 86400; $todayLabel = $now->format('Y-m-d'); // JSON API 模式:?action=data $isApi = (getParam('action') === 'data'); function getTodayBondData() { global $todayStart, $todayEnd; $spendData = []; $incomeData = []; // orders.db 今日消费 try { $odb = getOrdersDB(); $stmt = $odb->prepare("SELECT player_name, SUM(total_price) AS total_spend FROM cashier_orders WHERE status='completed' AND created_at >= :start AND created_at < :end GROUP BY player_name ORDER BY total_spend DESC"); $stmt->bindValue(':start', $todayStart, SQLITE3_INTEGER); $stmt->bindValue(':end', $todayEnd, SQLITE3_INTEGER); $res = $stmt->execute(); while ($row = $res->fetchArray(SQLITE3_ASSOC)) { $spendData[$row['player_name']] = (int)$row['total_spend']; } } catch (\Throwable $e) { debugLog('[today_bonds] 查询消费异常: ' . $e->getMessage()); } // web.db 今日收入(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"); $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']; } } catch (\Throwable $e) { debugLog('[today_bonds] 查询收入异常: ' . $e->getMessage()); } $allPlayers = array_unique(array_merge(array_keys($spendData), array_keys($incomeData))); $rows = []; $totalSpend = 0; $totalIncome = 0; foreach ($allPlayers as $p) { $spend = $spendData[$p] ?? 0; $income = $incomeData[$p] ?? 0; $net = $income - $spend; $totalSpend += $spend; $totalIncome += $income; $rows[] = ['name' => $p, 'spend' => $spend, 'income' => $income, 'net' => $net]; } usort($rows, fn($a,$b) => $b['net'] - $a['net']); return [ 'rows' => $rows, 'total_spend' => $totalSpend, 'total_income' => $totalIncome, 'net_total' => $totalIncome - $totalSpend, 'player_count' => count($rows), 'date_label' => $GLOBALS['todayLabel'], ]; } if ($isApi) { success(getTodayBondData()); exit; } $initialState = json_encode(getTodayBondData(), JSON_UNESCAPED_UNICODE); ?> SDF1 - 今日债券变动

📊 今日债券变动

· 每30秒刷新
加载中...