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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/language/lang.php";
 
\Logging\CreateLogging("online.php");
$Permission = \User\Permission::P_Online;
 
$alertMsg = "";
$channel = $_SESSION['spid'];
$UserAccount = $_SESSION['UserAccount'];
$user = new \User\User($UserAccount);
if (!$user->HavePermission($Permission)) {
    exit;
}
 
$serversArray = $user->GetServers();
 
// 默认当天
$startDate = array_key_exists("startDate", $_POST) ? $_POST["startDate"] : date("Y-m-d");
$endDate = array_key_exists("endDate", $_POST) ? $_POST["endDate"] : date("Y-m-d");
$onlyServerIDHis  =  $_POST["onlyServerIDHis"];
$OnlyServerID = null;
if ($onlyServerIDHis == "on") {
    $OnlyServerID = 1; // 默认只查指定服
}
 
// 设置默认数据,开界面默认查选中服
$_POST["startDate"] = $startDate;
$_POST["endDate"] = $endDate;
$_POST["eventType"] = "OnlinePlayer";
$_POST["queryAllData"] = "on"; // 设置可查询备份数据
// echo "_POST:", print_r($_POST, true), "<br/>";
\CommFunc\QueryEventData($user, $retInfo);
 
$showTime = \CommFunc\StrDateTimeToTime(date("Y-m-d"));
$endTime = strtotime("+1 days", $showTime);
$labels = array(); // x轴为一天的时间
$doCount = 0;
while ($showTime < $endTime && $doCount < 1440) {
    $doCount += 1;
    $label = date("Y-m-d H:i:s", $showTime);
    array_push($labels, substr($label, 11, 5));
    $showTime = strtotime("+5 minutes", $showTime); // 时间间隔5分钟
}
 
?>
 
<!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 id="online" action="online.php" method="post">
        <?php echo \Lang\gettext("查询时间"); ?>:
        <input type="text" name="startDate" id="startDate" onclick="new Calendar().show(this);" readonly value="<?php echo $startDate; ?>" size="8" />
        ~
        <input type="text" name="endDate" id="endDate" onclick="new Calendar().show(this);" readonly value="<?php echo $endDate; ?>" size="8" />
        <input type="submit" value="<?php echo \Lang\gettext("查询本服"); ?>" onclick="onCurSubmit()" />
        <?php
        echo "&nbsp;&nbsp;";
        echo '<input type="checkbox" name="onlyServerIDHis" id="onlyServerIDHis" ' . ($onlyServerIDHis == "on" ? "checked" : "") . ' onchange="onOnlyServerIDHisChange()" />' . \Lang\gettext("查询单服历史");
        ?>
        <div id="OnlinePlayerInfo"></div>
        <hr />
        <?php
        include_once "/Common/SelectServer.php";
        ?>
        <input type="submit" name="submit" id="submit" value="<?php echo \Lang\gettext("查询多服"); ?>" onclick="return checkMultiSubmit()" />
        <br />
        <br />
    </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="/Common/selectserver.js"></script>
<script type='text/javascript' src="/js/chart.min.js"></script>
<script type="text/javascript">
    window.onload = function() {
        var retInfo = '<?php echo json_encode($retInfo); ?>';
        if (retInfo == 'null') {
            return;
        }
        retInfo = JSON.parse(retInfo);
 
        let chartNum = 0;
        let insHtml, info;
        for (const serverName in retInfo) {
            let chartID;
            insHtml = "";
            insHtml += "<hr />";
            info = retInfo[serverName];
            console.log(serverName, info);
            if (info && info["OK"]) {
                chartID = "myChart" + chartNum;
                chartNum += 1;
                // insHtml += "<center>" + serverName + "</center>" + "<br/>";
                insHtml += "<canvas id=\"" + chartID + "\" ></canvas>"; // 插入画布
            } else {
                insHtml += serverName + " : " + info + "<br/>";
            }
            document.getElementById("OnlinePlayerInfo").insertAdjacentHTML("beforeEnd", insHtml);
            if (chartID) {
                drawChartLine(chartID, serverName, info["DRData"]);
            }
        }
    }
 
    function onOnlyServerIDHisChange() {
        if (document.getElementById("onlyServerIDHis").checked) {
            document.getElementById("OnlyServerID").selectedIndex = 1;
        } else {
            document.getElementById("OnlyServerID").selectedIndex = 0;
        }
    }
 
    function drawChartLine(chartID, serverName, drData) {
 
        var backgroundColors = [
            'rgba(79, 66, 255, 0.2)',
            'rgba(255, 99, 132, 0.2)',
            'rgba(255, 206, 86, 0.2)',
            'rgba(54, 162, 235, 0.2)',
            'rgba(75, 192, 192, 0.2)',
            'rgba(153, 102, 255, 0.2)',
            'rgba(255, 159, 64, 0.2)'
        ];
 
        var borderColors = [
            'rgba(79, 66, 255, 1)',
            'rgba(255, 99, 132, 1)',
            'rgba(255, 206, 86, 1)',
            'rgba(54, 162, 235, 1)',
            'rgba(75, 192, 192, 1)',
            'rgba(153, 102, 255, 1)',
            'rgba(255, 159, 64, 1)'
        ];
 
        var colorIndex = 0;
        var labels = JSON.parse('<?php echo json_encode($labels); ?>');
        // console.log("labels", labels);
        var datasets = [];
        var dateStrList = Object.keys(drData);
        dateStrList.sort();
        // console.log("dateStrList", dateStrList);
        for (let i = 0; i < dateStrList.length; i++) {
            let dateStr = dateStrList[i];
            const hmInfo = drData[dateStr];
            // console.log(dateStr, "hmInfo", hmInfo);
 
            let hmCount = 0;
            let playerCountList = []
            for (let j = 0; j < labels.length; j++) {
                const hm = labels[j];
                if (hmInfo[hm] >= 0) {
                    playerCountList.push(hmInfo[hm]);
                    // playerCountList.push(random(100, 200));
                    hmCount += 1;
                    if (hmCount >= Object.keys(hmInfo).length) {
                        // 已达到记录
                        break;
                    }
                } else {
                    playerCountList.push(0);
                }
            }
 
            // console.log(dateStr, "playerCountList", playerCountList.length, playerCountList);
            datasets.push({
                label: dateStr,
                data: playerCountList,
                backgroundColor: backgroundColors[colorIndex % backgroundColors.length],
                borderColor: borderColors[colorIndex % borderColors.length],
                borderWidth: 1,
                lineTension: 0.5,
                pointRadius: 1
            });
            colorIndex += 1;
        }
 
        var ctx = document.getElementById(chartID);
        ctx.width = 400;
        ctx.height = 100;
        var myLineChart = new Chart(ctx, {
            type: "line",
            data: {
                labels: labels,
                datasets: datasets
            },
            options: {
                plugins: {
                    title: {
                        display: true,
                        text: serverName
                    }
                },
                scales: {
                    x: {
                        title: {
                            display: true,
                            text: "时间"
                        }
                    },
                    y: {
                        title: {
                            display: true,
                            text: "人数"
                        },
                        beginAtZero: true,
                        ticks: {
                            stepSize: 1, // 刻度间隔1
                        }
                    }
                }
            }
        });
    }
 
    function onCurSubmit() {
        document.getElementById("MultiServer").value = 0;
        return true;
    }
 
    function checkMultiSubmit() {
 
        if (!checkHaveServerSelected()) {
            return false;
        }
 
        if (!setSubmitQuerying("submit")) {
            return false;
        }
 
        return true;
    }
</script>
 
</html>