hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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="添加服务器ID条件" 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,关联html中的元素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("表格复制成功,可直接粘贴到Excel工作表!");
    }
</script>
 
</html>