| <?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">  | 
|           <input type="button" value="添加服务器ID条件" onclick="AddServerIDCondition('', '', '')" />  | 
|           <input type="button" value="重置条件" onclick="ResetServerIDCondition()" />  | 
|             | 
|         <input type="checkbox" name="showByServerID" id="showByServerID" <?php echo $showByServerID == "on" ? "checked" : ""; ?> />区服独立显示  | 
|           <input type="submit" value="<?php echo \Lang\gettext("查询"); ?>" />  | 
|           <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> |