From 3bc897685e16d0855fec1aebaee3c90466fa851b Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 16 十二月 2024 10:35:01 +0800
Subject: [PATCH] 10162 后台优化(增加全服等级分布查询)

---
 js/common.js              |   61 +++++++++++
 Common/CommFunc.php       |   47 +++++++++
 index.php                 |    3 
 serverrep/allplayerlv.php |  168 +++++++++++++++++++++++++++++++++
 Account/User.php          |    4 
 5 files changed, 279 insertions(+), 4 deletions(-)

diff --git a/Account/User.php b/Account/User.php
index d037cd7..6603426 100644
--- a/Account/User.php
+++ b/Account/User.php
@@ -27,7 +27,8 @@
 					Permission::P_REP_KeepLogin => array("Name" => \Lang\gettext("鍏ㄦ湇鐣欏瓨")),
 					Permission::P_REP_LTV => array("Name" => \Lang\gettext("鍏ㄦ湇LTV")),
 					Permission::P_REP_FirstLoginFirstPayCnt => array("Name" => \Lang\gettext("棣栫櫥棣栧厖浜烘暟")),
-					Permission::P_REP_XPayPaycnt => array("Name" => \Lang\gettext("璐拱X绀煎寘鍐嶄粯浜烘暟")),
+					Permission::P_REP_XPayPaycnt => array("Name" => \Lang\gettext("璐拱X绀煎寘鍐嶆浠樿垂浜烘暟")),
+					Permission::P_All_PlayerLV => array("Name" => \Lang\gettext("鍏ㄦ湇绛夌骇鍒嗗竷")),
 				)
 			),
 			array(
@@ -219,6 +220,7 @@
 	const P_REP_LTV = "P_REP_LTV";
 	const P_REP_FirstLoginFirstPayCnt = "P_REP_FirstLoginFirstPayCnt";
 	const P_REP_XPayPaycnt = "P_REP_XPayPaycnt";
+	const P_All_PlayerLV = "P_All_PlayerLV";
 
 	//鏈嶅姟鍣�
 	const P_Online = "P_Online";
diff --git a/Common/CommFunc.php b/Common/CommFunc.php
index e2fac9b..cca777b 100644
--- a/Common/CommFunc.php
+++ b/Common/CommFunc.php
@@ -1447,3 +1447,50 @@
 {
 	return json_decode(GetFileContents(dirname(__FILE__) . "/mailtypes.json", "[]"), true);
 }
+
+// 缁勫悎鏈嶅姟鍣↖D鏌ヨ鏉′欢锛屾惌閰� common.js AddServerIDCondition 浣跨敤
+function MatchServerIDCond(&$find, &$serverIDCondArray)
+{
+	if (!isset($serverIDCondArray)) {
+		$serverIDCondArray = array();
+	}
+	$serverIDCondNumMax = 20;
+	$serverIDCondIn = array();
+	$serverIDCondFind = array();
+	for ($i = 1; $i < $serverIDCondNumMax + 1; $i++) {
+		if (!array_key_exists("ServerIDGTE" . $i, $_POST)) {
+			continue;
+		}
+		$eValue = intval($_POST["ServerIDE" . $i]);
+		$gteValue = intval($_POST["ServerIDGTE" . $i]);
+		$lteValue = intval($_POST["ServerIDLTE" . $i]);
+		// \Logging\LogInfo("serverIDCond." . $i . " : eValue:" . $eValue . " gteValue:" . $gteValue . " lteValue:" . $lteValue);
+		if ($eValue <= 0 && $gteValue <= 0 && $lteValue <= 0) {
+			continue;
+		}
+		if ($gteValue > 0 && $lteValue > 0 && $gteValue > $lteValue) {
+			continue;
+		}
+		if ($eValue > 0) {
+			array_push($serverIDCondIn, $eValue);
+		}
+		$cond = array();
+		if ($gteValue > 0) {
+			$cond['$gte'] = $gteValue;
+		}
+		if ($lteValue > 0) {
+			$cond['$lte'] = $lteValue;
+		}
+		if (count($cond)) {
+			array_push($serverIDCondFind, array("ServerID" => $cond));
+		}
+		array_push($serverIDCondArray, array($eValue, $gteValue, $lteValue));
+	}
+	if (count($serverIDCondIn) > 0) {
+		array_push($serverIDCondFind, array("ServerID" => array('$in' => $serverIDCondIn)));
+	}
+	if (count($serverIDCondFind) > 0) {
+		$find['$or'] = $serverIDCondFind;
+	}
+	// \Logging\LogInfo("find:" . json_encode($find));
+}
diff --git a/index.php b/index.php
index 5b587f8..f36bd20 100644
--- a/index.php
+++ b/index.php
@@ -44,7 +44,8 @@
 		array(\User\Permission::P_REP_KeepLogin, "serverrep/keeplogin.php", \Lang\gettext("鍏ㄦ湇鐣欏瓨")),
 		array(\User\Permission::P_REP_LTV, "serverrep/ltv.php", \Lang\gettext("鍏ㄦ湇LTV")),
 		array(\User\Permission::P_REP_FirstLoginFirstPayCnt, "serverrep/firstLoginFirstPayCnt.php", \Lang\gettext("棣栫櫥棣栧厖浜烘暟")),
-		array(\User\Permission::P_REP_FirstLoginFirstPayCnt, "serverrep/xpaypaycnt.php", \Lang\gettext("璐拱X绀煎寘鍐嶄粯浜烘暟")),
+		array(\User\Permission::P_REP_FirstLoginFirstPayCnt, "serverrep/xpaypaycnt.php", \Lang\gettext("璐拱X绀煎寘鍐嶆浠樿垂浜烘暟")),
+		array(\User\Permission::P_All_PlayerLV, "serverrep/allplayerlv.php", \Lang\gettext("鍏ㄦ湇绛夌骇鍒嗗竷")),
 	),
 
 	\Lang\gettext("鏈嶅姟鍣�") => array(
diff --git a/js/common.js b/js/common.js
index 60f15c9..a42f5cd 100644
--- a/js/common.js
+++ b/js/common.js
@@ -122,7 +122,7 @@
 	}
 }
 
-function doSubmit(to, p, method='GET') { // to:鎻愪氦鍔ㄤ綔锛坅ction锛�,p:鍙傛暟 
+function doSubmit(to, p, method = 'GET') { // to:鎻愪氦鍔ㄤ綔锛坅ction锛�,p:鍙傛暟 
 	var myForm = document.createElement("form");
 	myForm.method = method;
 	myForm.action = to;
@@ -152,6 +152,63 @@
 	return true;
 }
 
+// 鏈嶅姟鍣↖D鏉′欢锛屾惌閰� \CommFunc\MatchServerIDCond 浣跨敤
+var serverIDCondNum = 0; // 鏈嶅姟鍣↖D鏉′欢缂栧彿
+function LoadServerIDCondition(serverIDCondArray) {
+	var serverIDCondList = JSON.parse(serverIDCondArray);
+	if (!serverIDCondList) {
+		return;
+	}
+	for (let index = 0; index < serverIDCondList.length; index++) {
+		const cond = serverIDCondList[index];
+		const eValue = cond[0] > 0 ? cond[0] : "";
+		const gteValue = cond[1] > 0 ? cond[1] : "";
+		const lteValue = cond[2] > 0 ? cond[2] : "";
+		AddServerIDCondition(eValue, gteValue, lteValue);
+	}
+}
+
+function AddServerIDCondition(eValue, gteValue, lteValue) {
+	var serverIDCondNumMax = 20; // 鏈�澶ф潯浠舵暟
+	if (serverIDCondNum >= serverIDCondNumMax) {
+		alert("鏈嶅姟鍣↖D鏉′欢瓒呰繃鏈�澶т釜鏁�: " + serverIDCondNumMax);
+		return;
+	}
+	serverIDCondNum += 1;
+	var serverIDCondition = "<div id=\"ServerIDCond" + serverIDCondNum + "\">" +
+		"鏈嶅姟鍣↖D鏉′欢" + (serverIDCondNum < 10 ? "&nbsp;&nbsp;" + serverIDCondNum : serverIDCondNum) + " => " +
+		"&nbsp;&nbsp;绛変簬: " + "<input type=\"number\" name=\"ServerIDE" + serverIDCondNum + "\"" +
+		" id=\"ServerIDE" + serverIDCondNum + "\" value=\"" + eValue + "\" min=\"0\" style=\"width: 60px\" />" +
+		"&nbsp;&nbsp;澶т簬绛変簬: " + "<input type=\"number\" name=\"ServerIDGTE" + serverIDCondNum + "\"" +
+		" id=\"ServerIDGTE" + serverIDCondNum + "\" value=\"" + gteValue + "\" min=\"0\" style=\"width: 60px\" />" +
+		"&nbsp;&nbsp;灏忎簬绛変簬: " + "<input type=\"number\" name=\"ServerIDLTE" + serverIDCondNum + "\"" +
+		" id=\"ServerIDLTE" + serverIDCondNum + "\" value=\"" + lteValue + "\" min=\"0\" style=\"width: 60px\" />" +
+		"&nbsp;&nbsp;<a href=\"javascript:DelServerIDCondition(" + serverIDCondNum + ")\">鍒犻櫎</a>";
+	"</div>";
+	document.getElementById("ServerIDCondition").insertAdjacentHTML("beforeEnd", serverIDCondition);
+}
+
+function DelServerIDCondition(delNum) {
+	document.getElementById("ServerIDCondition").removeChild(document.getElementById("ServerIDCond" + delNum));
+}
+
+function ResetServerIDCondition() {
+	document.getElementById("ServerIDCondition").innerHTML = "";
+	serverIDCondNum = 0;
+}
+
+/**澶嶅埗 */
+function copyToClipboard(text) {
+	var textarea = document.createElement('textarea');
+	textarea.style.position = 'fixed';
+	textarea.style.opacity = 0;
+	textarea.value = text;
+	document.body.appendChild(textarea);
+	textarea.select();
+	document.execCommand('copy');
+	document.body.removeChild(textarea);
+}
+
 /**
  * 缁樺埗鏇茬嚎鍥�
  * @param {*} chartID 鍥捐〃ID锛屽叧鑱攈tml涓殑鍏冪礌ID
@@ -162,7 +219,7 @@
  * @param {*} datasetDataList 鏁版嵁琛ㄦ暟鎹垪琛紝鍗虫瘡鏉$嚎鐨勬暟鎹紝绾跨殑鏁版嵁闀垮害蹇呴』涓巟杞村埢搴︽枃鏈垪琛ㄩ暱搴︿竴鑷�
  * @param {*} datasetLabList 鏁版嵁琛ㄦ爣棰樺垪琛紝鍗虫瘡鏉$嚎鐨勬爣棰橈紝鏈夊嚑鏉$嚎鐨勬暟鎹嵆鏈夊嚑涓爣棰�
  */
- function drawChart_Line(chartID, chartText, xText, yText, labels, datasetDataList, datasetLabList = []) {
+function drawChart_Line(chartID, chartText, xText, yText, labels, datasetDataList, datasetLabList = []) {
 	var backgroundColors = [
 		'rgba(79, 66, 255, 0.2)',
 		'rgba(255, 99, 132, 0.2)',
diff --git a/serverrep/allplayerlv.php b/serverrep/allplayerlv.php
new file mode 100644
index 0000000..6d5b606
--- /dev/null
+++ b/serverrep/allplayerlv.php
@@ -0,0 +1,168 @@
+<?php
+include_once "/Common/Logging.php";
+include_once "/Account/User.php";
+include_once "/language/lang.php";
+include_once "/serverrep/report.php";
+
+\Logging\CreateLogging("rep.allplayerlv.php");
+$Permission = \User\Permission::P_All_PlayerLV;
+
+$alertMsg = "";
+$channel = $_SESSION['spid'];
+$UserAccount = $_SESSION['UserAccount'];
+$user = new \User\User($UserAccount);
+if (!$user->HavePermission($Permission)) {
+    exit;
+}
+
+// $startDate = array_key_exists("startDate", $_POST) ? $_POST["startDate"] : date("Y-m-d", strtotime("-7 days"));
+// $endDate = array_key_exists("endDate", $_POST) ? $_POST["endDate"] : date("Y-m-d");
+
+$match = array("Channel" => $channel);
+\CommFunc\MatchServerIDCond($match, $serverIDCondArray);
+\Logging\LogInfo("match:" . print_r($match, true));
+
+$showByServerID = $_POST["showByServerID"];
+$_id = array('LV' => '$LV');
+if ($showByServerID) {
+    $_id = array('ServerID' => '$ServerID', 'LV' => '$LV');
+}
+
+$ret = \DBOper\Aggregate("ServerRoles", array(
+    array(
+        '$match' => $match,
+    ),
+    array(
+        '$group' => array(
+            '_id' => $_id,
+            'count' => array('$sum' => 1),
+        )
+    )
+), $retInfo);
+
+// \Logging\LogInfo("retInfo:" . print_r($retInfo, true));
+
+$serverLVCountInfo = array();
+foreach ($retInfo as $info) {
+    $_idInfo = $info["_id"];
+    $key = $showByServerID ? $_idInfo["ServerID"] . "" : "0";
+    $LV = $_idInfo["LV"];
+    $count = $info["count"];
+    if (!$serverLVCountInfo[$key]) {
+        $serverLVCountInfo[$key] = array();
+    }
+    $lvCountInfo = $serverLVCountInfo[$key];
+    $lvCountInfo[$LV . ""] = $count;
+    $serverLVCountInfo[$key] = $lvCountInfo;
+}
+// \Logging\LogInfo("serverLVCountInfo:" . print_r($serverLVCountInfo, true));
+
+?>
+
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <title><?php echo \Lang\gettext("鍏ㄦ湇绛夌骇鍒嗗竷"); ?></title>
+    <link rel="gettext" type="application/x-po" href="../language/<?php echo \Lang\getLang(); ?>/LC_MESSAGES/<?php echo \Lang\getjspodomain(); ?>.po" />
+</head>
+
+<body>
+    <center>
+        <p><b><?php echo \Lang\gettext("鍏ㄦ湇绛夌骇鍒嗗竷"); ?></b></P>
+    </center>
+    <form method="post">
+        &nbsp;&nbsp;<input type="button" value="娣诲姞鏈嶅姟鍣↖D鏉′欢" onclick="AddServerIDCondition('', '', '')" />
+        &nbsp;&nbsp;<input type="button" value="閲嶇疆鏉′欢" onclick="ResetServerIDCondition()" />
+        &nbsp;&nbsp;
+        <input type="checkbox" name="showByServerID" id="showByServerID" <?php echo $showByServerID == "on" ? "checked" : ""; ?> />鍖烘湇鐙珛鏄剧ず
+        &nbsp;&nbsp;<input type="submit" value="<?php echo \Lang\gettext("鏌ヨ"); ?>" />
+        &nbsp;&nbsp;<input type="button" value="<?php echo \Lang\gettext("澶嶅埗鏁版嵁"); ?>" onclick="onCopyData()" />
+        <div id="ServerIDCondition"></div>
+        <hr />
+        <div id="MyChart"></div>
+    </form>
+</body>
+<script type='text/javascript' src='/language/gettext.js'></script>
+<script type='text/javascript' src="/js/calendar.js"></script>
+<script type='text/javascript' src="/js/common.js"></script>
+<script type='text/javascript' src="/js/chart.min.js"></script>
+<script type="text/javascript">
+    var copydata = "";
+
+    window.onload = function() {
+        LoadServerIDCondition('<?php echo json_encode($serverIDCondArray); ?>');
+
+        var showByServerID = <?php echo json_encode($showByServerID); ?>;
+        var serverLVCountInfo = JSON.parse('<?php echo json_encode($serverLVCountInfo); ?>');
+        // console.log("showByServerID", showByServerID);
+        // console.log("serverLVCountInfo", serverLVCountInfo);
+
+        var serverIDList = [];
+        for (const serverID in serverLVCountInfo) {
+            serverIDList.push(parseInt(serverID));
+        }
+        serverIDList.sort((a, b) => a - b); // 鎸夊尯鏈嶉『搴忓睍绀�
+        // console.log("serverIDList", serverIDList);
+
+        copydata += "<table><tr>";
+        for (let index = 0; index < serverIDList.length; index++) {
+            const serverID = serverIDList[index];
+            const lvCountInfo = serverLVCountInfo[serverID + ""];
+            // console.log("serverID", serverID, lvCountInfo);
+
+            let xLabels = [];
+            let yDatas = [];
+            let totalCnt = 0;
+            for (const lv in lvCountInfo) {
+                const lvCnt = lvCountInfo[lv];
+                xLabels.push(lv);
+                yDatas.push(lvCnt);
+                totalCnt += lvCnt;
+            }
+            let datas = {
+                "浜烘暟": yDatas
+            };
+
+            let chartID = "myChart" + serverID; // 鍥捐〃ID锛屽叧鑱攈tml涓殑鍏冪礌ID
+            let insHtml = "";
+            insHtml += "<canvas id=\"" + chartID + "\" ></canvas>"; // 鎻掑叆鐢诲竷
+            insHtml += "<hr />";
+            document.getElementById("MyChart").insertAdjacentHTML("beforeEnd", insHtml);
+
+            let chartText = serverID == 0 ? "鍏ㄦ湇" : "s" + serverID; // 鍥捐〃鎬绘爣棰�
+            chartText += " 鎬讳汉鏁�: " + totalCnt;
+            let xText = "绛夌骇"; // x杞存枃鏈紝 濡傜瓑绾�
+            let yText = "浜烘暟"; // y杞存枃鏈紝 濡備汉鏁�
+            // (鍥炬爣ID, 鍥炬爣鏍囬, x杞存枃鏈�, y杞存枃鏈�, x杞村埢搴︽枃鏈垪琛�, y杞存暟鎹垪琛�, y杞存暟鎹爣棰樺垪琛�)
+            drawChart_Line(chartID, chartText, xText, yText, xLabels, Object.values(datas), Object.keys(datas));
+
+            // 澶嶅埗鏁版嵁
+            copydata += "<td>";
+            copydata += "<table>";
+            copydata += "<tr><td>鏈嶅姟鍣�: " + chartText + "</td></tr>";
+            copydata += "<tr><td>绛夌骇</td><td>浜烘暟</td></tr>";
+            for (let index = 0; index < xLabels.length; index++) {
+                const lv = xLabels[index];
+                const playerCount = yDatas[index];
+                copydata += "<tr><td>" + lv + "</td><td>" + playerCount + "</td></tr>";
+            }
+            copydata += "<tr></tr>";
+            copydata += "</table>";
+            copydata += "</td>";
+        }
+        copydata += "</tr></table>";
+    }
+
+    function onCopyData() {
+        if (!copydata) {
+            alert("娌℃湁鏁版嵁");
+            return
+        }
+        copyToClipboard(copydata);
+        alert("琛ㄦ牸澶嶅埗鎴愬姛锛屽彲鐩存帴绮樿创鍒癊xcel宸ヤ綔琛�!");
+    }
+</script>
+
+</html>
\ No newline at end of file

--
Gitblit v1.8.0