From 5cf11e00047c8c98cabd03da3973e7c400339c27 Mon Sep 17 00:00:00 2001 From: tianya <8445295+llgoer@user.noreply.gitee.com> Date: Sat, 30 Apr 2022 12:28:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E7=BB=9F=E8=AE=A1=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/index_body.php | 12 ++++++++++++ src/admin/js/indexbody.js | 20 ++++++++++++-------- src/system/libraries/statistics.class.php | 10 ++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/admin/index_body.php b/src/admin/index_body.php index d919db20..a3f9474e 100644 --- a/src/admin/index_body.php +++ b/src/admin/index_body.php @@ -119,5 +119,17 @@ else if ($dopost == 'setskin') { "result" => $rs, )); exit; +} elseif ($dopost == 'get_statistics_multi') { + require_once(DEDEINC."/libraries/statistics.class.php"); + //获取统计信息 + $sdates = empty($sdates) ? array() : explode(",",preg_replace("[^\d\,]","",$sdates)) ; + $stat = new DedeStatistics; + $rs = $stat->GetInfoByDateMulti($sdates); + echo json_encode(array( + "code" => 200, + "msg" => "", + "result" => $rs, + )); + exit; } ?> \ No newline at end of file diff --git a/src/admin/js/indexbody.js b/src/admin/js/indexbody.js index 1c94c37b..cb7c502c 100644 --- a/src/admin/js/indexbody.js +++ b/src/admin/js/indexbody.js @@ -204,6 +204,7 @@ function LoadStat() { async function LoadStatChart() { const ctx = document.getElementById('statChart').getContext('2d'); let labels = []; + let dates = []; let pvs = []; let ips = []; let uvs = []; @@ -214,14 +215,17 @@ async function LoadStatChart() { var s = d.Format("yyyy-MM-dd"); labels.push(d.Format("MM-dd")); s = s.replaceAll("-", ""); - let resp = await fetch("index_body.php?dopost=get_statistics&sdate=" + s); - let data = await resp.json(); - if (data.code == 200) { - pvs.push(typeof data.result.pv == "undefined" ? 0 : data.result.pv); - ips.push(typeof data.result.ip == "undefined" ? 0 : data.result.ip); - uvs.push(typeof data.result.uv == "undefined" ? 0 : data.result.uv); - vvs.push(typeof data.result.vv == "undefined" ? 0 : data.result.vv); - } + dates.push(s); + } + let resp = await fetch("index_body.php?dopost=get_statistics_multi&sdates=" + dates.join(",")); + let data = await resp.json(); + if (data.code == 200) { + data.result.forEach(e => { + pvs.push(typeof e.pv == "undefined" ? 0 : e.pv); + ips.push(typeof e.ip == "undefined" ? 0 : e.ip); + uvs.push(typeof e.uv == "undefined" ? 0 : e.uv); + vvs.push(typeof e.vv == "undefined" ? 0 : e.vv); + }); } const myChart = new Chart(ctx, { type: 'line', diff --git a/src/system/libraries/statistics.class.php b/src/system/libraries/statistics.class.php index 1bd6a29b..75bd1eeb 100644 --- a/src/system/libraries/statistics.class.php +++ b/src/system/libraries/statistics.class.php @@ -128,6 +128,16 @@ EOT; return substr(bin2hex($bytes), 0, $lenght); } + function GetInfoByDateMulti($ds = array()) + { + $results = array(); + foreach ($ds as $d) { + $vv = $this->GetInfoByDate($d); + $result[] = $vv; + } + return $result; + } + // 获取某天的统计信息 function GetInfoByDate($d=0) {