数据由展示每天的改为累计的

This commit is contained in:
LL
2025-11-19 09:31:41 +08:00
parent 2c9c06bf45
commit 0c5ecababa
2 changed files with 65 additions and 4 deletions

View File

@@ -24,7 +24,32 @@ if ($method === 'GET') {
$out = [];
foreach ($last7 as $k) { $out[$k] = $daily[$k]; }
$todayData = $daily[$today] ?? ['visits' => 0, 'video_plays' => 0, 'picture_shows' => 0, 'uv' => 0, 'bandwidth_in' => 0, 'bandwidth_out' => 0];
echo json_encode(['success' => true, 'today' => $todayData, 'daily' => $out], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$total = ['visits' => 0, 'video_plays' => 0, 'picture_shows' => 0, 'uv' => 0, 'bandwidth_in' => 0, 'bandwidth_out' => 0];
foreach ($daily as $d) {
if (!is_array($d)) continue;
$total['visits'] += intval($d['visits'] ?? 0);
$total['video_plays'] += intval($d['video_plays'] ?? 0);
$total['picture_shows'] += intval($d['picture_shows'] ?? 0);
$total['bandwidth_in'] += intval($d['bandwidth_in'] ?? 0);
$total['bandwidth_out'] += intval($d['bandwidth_out'] ?? 0);
}
// 累计唯一访客:合并所有 uv/<date>.json 的 IP
$ips = [];
if (is_dir($uvRoot)) {
$list = @scandir($uvRoot) ?: [];
foreach ($list as $f) {
if ($f === '.' || $f === '..') continue;
$p = $uvRoot . DIRECTORY_SEPARATOR . $f;
if (!is_file($p)) continue;
$rawIps = @file_get_contents($p);
$decodedIps = json_decode($rawIps, true);
if (is_array($decodedIps)) {
foreach ($decodedIps as $ip) { if (is_string($ip)) { $ips[$ip] = true; } }
}
}
}
$total['uv'] = count($ips);
echo json_encode(['success' => true, 'today' => $todayData, 'total' => $total, 'daily' => $out], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
@@ -90,7 +115,40 @@ $events[] = [
];
@file_put_contents($eventsPath, json_encode($events, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX);
echo json_encode(['success' => true, 'today' => $daily[$today]], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
// 计算累计总数并返回
$total = ['visits' => 0, 'video_plays' => 0, 'picture_shows' => 0, 'uv' => 0, 'bandwidth_in' => 0, 'bandwidth_out' => 0];
if (file_exists($dailyPath)) {
$rawDaily = @file_get_contents($dailyPath);
$decoded = json_decode($rawDaily, true);
if (is_array($decoded)) {
foreach ($decoded as $d) {
if (!is_array($d)) continue;
$total['visits'] += intval($d['visits'] ?? 0);
$total['video_plays'] += intval($d['video_plays'] ?? 0);
$total['picture_shows'] += intval($d['picture_shows'] ?? 0);
$total['bandwidth_in'] += intval($d['bandwidth_in'] ?? 0);
$total['bandwidth_out'] += intval($d['bandwidth_out'] ?? 0);
}
}
}
// 累计 UV
$ips = [];
if (is_dir($uvRoot)) {
$list = @scandir($uvRoot) ?: [];
foreach ($list as $f) {
if ($f === '.' || $f === '..') continue;
$p = $uvRoot . DIRECTORY_SEPARATOR . $f;
if (!is_file($p)) continue;
$rawIps = @file_get_contents($p);
$decodedIps = json_decode($rawIps, true);
if (is_array($decodedIps)) {
foreach ($decodedIps as $ip) { if (is_string($ip)) { $ips[$ip] = true; } }
}
}
}
$total['uv'] = count($ips);
echo json_encode(['success' => true, 'today' => $daily[$today], 'total' => $total], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$direction = isset($data['direction']) ? (string)$data['direction'] : '';
$bytes = isset($data['bytes']) ? intval($data['bytes']) : 0;
if ($event === 'bandwidth' && $bytes > 0) {