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) {