Bläddra i källkod

减少统计请求次数

tags/6.1.9
tianya 1 år sedan
förälder
incheckning
5cf11e0004
3 ändrade filer med 34 tillägg och 8 borttagningar
  1. +12
    -0
      src/admin/index_body.php
  2. +12
    -8
      src/admin/js/indexbody.js
  3. +10
    -0
      src/system/libraries/statistics.class.php

+ 12
- 0
src/admin/index_body.php Visa fil

@@ -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;
}
?>

+ 12
- 8
src/admin/js/indexbody.js Visa fil

@@ -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',


+ 10
- 0
src/system/libraries/statistics.class.php Visa fil

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


Laddar…
Avbryt
Spara