hxp
2024-12-04 cd9c1c146e264982ddcc3521abbcc1285562770b
10162 后台优化(增加本服总览)
4个文件已修改
1个文件已添加
318 ■■■■■ 已修改文件
Account/User.php 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/struct.php 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
eventreport/eventreport.php 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
index.php 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
serverinfo/serverview.php 281 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Account/User.php
@@ -36,6 +36,7 @@
                    Permission::P_PlayerLV => array("Name" => \Lang\gettext("等级分布")),
                    Permission::P_Chatmonitor => array("Name" => \Lang\gettext("聊天监控")),
                    Permission::P_BugReport => array("Name" => \Lang\gettext("Bug反馈")),
                    Permission::P_Serverview => array("Name" => \Lang\gettext("本服总览")),
                    Permission::P_PayOverview => array("Name" => \Lang\gettext("充值总览")),
                    Permission::P_PayOrder => array("Name" => \Lang\gettext("充值订单")),
                    Permission::P_PayRank => array("Name" => \Lang\gettext("充值排行")),
@@ -220,6 +221,7 @@
    const P_PlayerLV = "P_PlayerLV";
    const P_Chatmonitor = "P_Chatmonitor";
    const P_BugReport = "P_BugReport";
    const P_Serverview = "P_Serverview";
    const P_PayOverview = "P_PayOverview";
    const P_PayOrder = "P_PayOrder";
    const P_PayRank = "P_PayRank";
db/struct.php
@@ -24,6 +24,21 @@
        )
    ),
    "ServerRoles" => array(
        array(
            array("Channel" => 1, "AccountID" => 1),
            array(),
        ),
        array(
            array("Channel" => 1, "ServerID" => 1),
            array(),
        ),
        array(
            array("Channel" => 1, "AccountID" => 1, "ServerID" => 1),
            array("unique" => true),
        )
    ),
    "GameServerInfo" => array(
        array(
            array("Channel" => 1, "ServerID" => 1),
eventreport/eventreport.php
@@ -160,6 +160,25 @@
    $ServerID = \CommFunc\GetServerIDBySid($RegionName);
    AddAccountFirstLogin($ServerID, $roleInfo);
    AddAccountDayActive($ServerID, $roleInfo);
    // 附带更新服务器角色表,之后会替换 GameRoles 表
    $find = array("Channel" => $Channel, "AccountID" => $AccountID, "ServerID" => $ServerID);
    if (\DBOper\Count("ServerRoles", $find) <= 0) {
        $insArray = array(
            "Channel" => $Channel,
            "AccountID" => $AccountID,
            "ServerID" => $ServerID,
            "CreateYMD" => date("Y-m-d"),
        );
        if ($roleInfo["CreateRoleTime"]) {
            $insArray["CreateYMD"] = substr($roleInfo["CreateRoleTime"], 0, 10);
        }
        $insArray["RollCount"] = \DBOper\Count("ServerRoles", array("Channel" => $Channel, "AccountID" => $AccountID));
        $insArray = array_merge($insArray, $roleInfo);
        \DBOper\Insert("ServerRoles", $insArray, $find);
    } else {
        \DBOper\Update("ServerRoles", $find, $roleInfo, true);
    }
    return true;
}
index.php
@@ -50,6 +50,7 @@
        array(\User\Permission::P_PlayerLV, "serverinfo/playerlv.php", \Lang\gettext("等级分布")),
        array(\User\Permission::P_Chatmonitor, "serverinfo/chatmonitor.php", \Lang\gettext("聊天监控"), "_blank"),
        array(\User\Permission::P_BugReport, "serverinfo/BugReportMain.php", \Lang\gettext("Bug反馈")),
        array(\User\Permission::P_Serverview, "serverinfo/serverview.php", \Lang\gettext("本服总览")),
        array(\User\Permission::P_PayOverview, "serverinfo/payoverview.php", \Lang\gettext("充值总览")),
        array(\User\Permission::P_PayOrder, "serverinfo/payorderlist.php", \Lang\gettext("充值订单")),
        array(\User\Permission::P_PayRank, "serverinfo/payrank.php", \Lang\gettext("充值排行")),
serverinfo/serverview.php
New file
@@ -0,0 +1,281 @@
<?php
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/db/DBOper.php";
include_once "/language/lang.php";
function logweb($msg, $showWeb = True)
{
    \Logging\LogInfo($msg);
    if ($showWeb) {
        echo date('Y-m-d H:i:s'), $msg, "<br/>";
    }
}
function ImportServerRoles()
{
    set_time_limit(1800); //暂时设置本脚本执行时间x秒,0不限制
    ini_set('memory_limit', '2048M'); // 将内存限制设置为256MB
    header("Content-type: text/html; charset=utf-8");
    logweb("开始导入区服角色");
    \DBOper\Find("GameRoles", array(), $findDataList);
    $batchInsRoles = array();
    $totalRoleCount = 0;
    logweb("总账号数:" . count($findDataList));
    foreach ($findDataList as $findData) {
        $Channel = $findData["Channel"];
        $AccountID = $findData["AccountID"];
        // 计算滚服次数
        $rollInfo = array();
        foreach ($findData as $field => $value) {
            $ServerID = \CommFunc\GetServerIDBySid($field);
            if ($ServerID <= 0) {
                continue;
            }
            $rollInfo[$field] = array("CreateRoleTime" => $value["CreateRoleTime"]);
        }
        //排序 根据 CreateRoleTime 升序排序  SORT_ASC 和 SORT_DESC
        array_multisort(array_column($rollInfo, 'CreateRoleTime'), SORT_ASC, $rollInfo);
        $rollCount = 0;
        foreach ($rollInfo as $field => $info) {
            $info["RollCount"] = $rollCount;
            $rollInfo[$field] = $info;
            $rollCount += 1;
        }
        // \Logging\LogInfo("AccountID:" . $AccountID . " rollInfo:" . print_r($rollInfo, true));
        foreach ($findData as $field => $value) {
            $ServerID = \CommFunc\GetServerIDBySid($field);
            if ($ServerID <= 0) {
                continue;
            }
            $roleInfo = array("Channel" => $Channel, "AccountID" => $AccountID, "ServerID" => $ServerID);
            if ($value["CreateRoleTime"]) {
                $roleInfo["CreateYMD"] = substr($value["CreateRoleTime"], 0, 10);
            }
            if ($rollInfo[$field]) {
                $roleInfo["RollCount"] = $rollInfo[$field]["RollCount"];
            } else {
                $roleInfo["RollCount"] = 0;
            }
            $roleInfo = array_merge($roleInfo, $value);
            $key = $Channel . "_s" . $ServerID;
            if (!array_key_exists($key, $batchInsRoles)) {
                $batchInsRoles[$key] = array();
            }
            $insArray = $batchInsRoles[$key];
            array_push($insArray, $roleInfo);
            $batchInsRoles[$key] = $insArray;
            $totalRoleCount += 1;
            if ($totalRoleCount % 1000 == 0) {
                logweb("totalRoleCount:" . $totalRoleCount);
            }
        }
    }
    logweb("总角色数 totalRoleCount:" . $totalRoleCount);
    if (count($batchInsRoles)) {
        ksort($batchInsRoles);
        \DBOper\Remove("ServerRoles", array(), false);
        $succCount = 0;
        foreach ($batchInsRoles as $key => $insArray) {
            if (DBOper\BatchInsert("ServerRoles", $insArray)) {
                logweb("批量导入区服角色数: " . $key . " count:" . count($insArray));
                $succCount += count($insArray);
            } else {
                logweb("###批量导入区服角色数: " . $key . " count:" . count($insArray));
            }
        }
        logweb("批量导入角色总数: " . $succCount);
    }
    logweb("导入区服角色完毕");
}
\Logging\CreateLogging("serverview.php");
$Permission = \User\Permission::P_Serverview;
$spid = $_SESSION['spid'];
$UserAccount = $_SESSION['UserAccount'];
$user = new \User\User($UserAccount);
if (!$user->HavePermission($Permission)) {
    exit;
}
// 从GameRoles表导入
if ($_GET["import"] == 1) {
    ImportServerRoles();
    exit;
};
$server_id = \CommFunc\GetServerIDBySid($_SESSION['server_id']);
$startDate = array_key_exists("startDate", $_POST) ? $_POST["startDate"] : \CommFunc\CalcToStrDateTime("-7 days", "Y-m-d");
$endDate = array_key_exists("endDate", $_POST) ? $_POST["endDate"] : date("Y-m-d");
\DBOper\Find("ServerRoles", array(
    "Channel" => $spid, "ServerID" => $server_id,
    "CreateYMD" => array('$lte' => $endDate)
), $roleList, array("AccountID" => 1, "CreateYMD" => 1, "RollCount" => 1));
$roleTotal = count($roleList); // 截止日期总角色数
$roleCountInYMD = 0;    // 日期内总角色数
$rollCountTotal = 0;    // 截止日期总滚服数
$rollCountInYMD = 0;    // 日期内总滚服数
$rollAccountIDInfo = array(); // 滚服账号信息 {accountID:滚服次数, ...}
$rollCountInfo = array();   // 滚服次数信息 {滚服次数:滚服角色数, ...}
foreach ($roleList as $roleInfo) {
    $AccountID = $roleInfo["AccountID"];
    $CreateYMD = $roleInfo["CreateYMD"];
    $RollCount = $roleInfo["RollCount"];
    if ($CreateYMD >= $startDate) {
        $roleCountInYMD += 1;
    }
    if ($RollCount > 0) {
        $rollCountTotal += 1;
        if ($CreateYMD >= $startDate) {
            $rollCountInYMD += 1;
        }
        $rollAccountIDInfo[$AccountID] = $RollCount;
        $rollCountInfo["" . $RollCount] = $rollCountInfo["" . $RollCount] ? ($rollCountInfo["" . $RollCount] + 1) : 1;
    }
}
// 只显示成功的订单; 1-成功;2-失败
$match = array(
    "Channel" => $spid, "ServerID" => $server_id, "State" => 1,
    "PayTime" => array('$gte' => $startDate . " 00:00:00", '$lte' => $endDate . " 23:59:59")
);
$ret = \DBOper\Aggregate("PayOrder", array(
    array(
        '$match' => $match,
    ),
    array(
        '$group' => array(
            '_id' => array('AccountID' => '$AccountID'),
            'total' => array('$sum' => '$OrderAmount'),
        ),
    ),
), $retInfo);
$payCount = 0;  // 总充值条数
$payTotal = 0;  // 充值总额
$payUserCount = 0;  // 充值人数
$payTotalRoll = 0; // 滚服充值总额
$payUserCountRoll = 0; // 滚服充值人数
$ARPPU = 0;
if (isset($retInfo)) {
    $payUserCount = count($retInfo);
    foreach ($retInfo as $info) {
        $AccountID = $info["_id"]["AccountID"];
        $payTotal += floatval($info["total"]);
        if ($rollAccountIDInfo[$AccountID]) {
            $payTotalRoll += floatval($info["total"]);
            $payUserCountRoll += 1;
        }
    }
    if ($payTotal > 0 && $payUserCount > 0) {
        $ARPPU = round($payTotal / $payUserCount, 2);
    }
}
$payCount = \DBOper\Count("PayOrder", $match);
?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><?php echo \Lang\gettext("本服总览"); ?></title>
    <link rel="stylesheet" type="text/css" href="/css/table.css">
    <link rel="stylesheet" type="text/css" href="/css/button.css">
</head>
<body>
    <center>
        <p><b><?php echo \Lang\gettext("本服总览"); ?></b></P>
    </center>
    <hr />
    <form action="" 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" name="submit" value="<?php echo \Lang\gettext("查询"); ?>" class="button green medium" />
    </form>
    <hr />
    <table width="50%">
        <caption>【总数据】</caption>
        <thead>
            <tr>
                <th align='center' width='200'></th>
                <th align='center' width='300'></th>
                <th align='center' width='100'></th>
            </tr>
        </thead>
        <tr class='trc'>
            <td align='center'>本服总创角</td>
            <td align='center'><?php echo $roleTotal ?></td>
            <td align='center'></td>
        <tr>
        <tr class='trc'>
            <td align='center'>本服总滚服</td>
            <td align='center'><?php echo $rollCountTotal ?></td>
            <td align='center'><?php echo $roleTotal ? round($rollCountTotal / $roleTotal * 100, 2) . "%" : "" ?></td>
        <tr>
        <tr class='trc'>
            <td align='center'>滚服次数对应账号数</td>
            <td align='center'><?php echo json_encode($rollCountInfo) ?></td>
            <td align='center'></td>
        <tr>
    </table>
    <hr />
    <table width="50%">
        <caption>【统计日期内数据】</caption>
        <thead>
            <tr>
                <th align='center' width='200'></th>
                <th align='center' width='300'></th>
                <th align='center' width='100'></th>
            </tr>
        </thead>
        <tr class='trc'>
            <td align='center'>总创角</td>
            <td align='center'><?php echo $roleCountInYMD ?></td>
            <td align='center'></td>
        <tr>
        <tr class='trc'>
            <td align='center'>总滚服</td>
            <td align='center'><?php echo $rollCountInYMD ?></td>
            <td align='center'><?php echo $roleCountInYMD ? round($rollCountInYMD / $roleCountInYMD * 100, 2) . "%" : "" ?></td>
        <tr>
        <tr class='trc'>
            <td align='center'>充值总额</td>
            <td align='center'><?php echo $payTotal ?></td>
            <td align='center'></td>
        <tr>
        <tr class='trc'>
            <td align='center'>滚服充值总额</td>
            <td align='center'><?php echo $payTotalRoll ?></td>
            <td align='center'><?php echo $payTotal ? round($payTotalRoll / $payTotal * 100, 2) . "%" : "" ?></td>
        <tr>
        <tr class='trc'>
            <td align='center'>充值人数</td>
            <td align='center'><?php echo $payUserCount ?></td>
            <td align='center'></td>
        <tr>
        <tr class='trc'>
            <td align='center'>滚服充值人数</td>
            <td align='center'><?php echo $payUserCountRoll ?></td>
            <td align='center'><?php echo $payUserCount ? round($payUserCountRoll / $payUserCount * 100, 2) . "%" : "" ?></td>
        <tr>
    </table>
</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">
</script>
</html>