<?php
|
set_time_limit(600); //暂时设置本脚本执行时间x秒,0不限制
|
ini_set('memory_limit', '256M'); // 将内存限制设置为256MB
|
|
include_once '/Common/CommFunc.php';
|
include_once '/Common/Logging.php';
|
include_once "/db/DBOper.php";
|
include_once "/serverrep/report.php";
|
|
header("Content-type: text/html; charset=utf-8");
|
|
\Logging\CreateLogging("rep.ImportAccountLoginpay.php");
|
|
$Channel = $_GET["appID"];
|
$opt = $_GET["opt"];
|
if (!$Channel) {
|
echo "no appID";
|
exit();
|
}
|
logweb("开始导入:" . $Channel . " opt:" . $opt);
|
if (array_key_exists("reset", $_GET)) {
|
logweb("重置重新导出:" . $Channel);
|
$AccountFirstLoginOK = \DBOper\Remove("AccountFirstLogin", array("Channel" => $Channel));
|
$AccountFirstPayOK = \DBOper\Remove("AccountFirstPay", array("Channel" => $Channel));
|
$AccountDayActiveOK = \DBOper\Remove("AccountDayActive", array("Channel" => $Channel));
|
$DailyReportOK = \DBOper\Remove("DailyReport", array("Channel" => $Channel));
|
$AccountFirstLoginReportOK = \DBOper\Remove("AccountFirstLoginReport", array("Channel" => $Channel));
|
$AccountFirstPayReportOK = \DBOper\Remove("AccountFirstPayReport", array("Channel" => $Channel));
|
$eventYMDOK = \DBOper\Remove("ServerEvent", array("Key" => "FirstKeepReportYMD_" . $Channel));
|
logweb("AccountFirstLoginOK:" . $AccountFirstLoginOK);
|
logweb("AccountFirstPayOK:" . $AccountFirstPayOK);
|
logweb("AccountDayActiveOK:" . $AccountDayActiveOK);
|
logweb("DailyReportOK:" . $DailyReportOK);
|
logweb("AccountFirstLoginReportOK:" . $AccountFirstLoginReportOK);
|
logweb("AccountFirstPayReportOK:" . $AccountFirstPayReportOK);
|
logweb("eventYMDOK:" . $eventYMDOK);
|
}
|
if (!$opt || $opt == "first") {
|
logweb("firstfirstfirst:" . $Channel);
|
impAccountFirstLogin();
|
impAccountFirstPay();
|
}
|
if (!$opt || $opt == "day") {
|
logweb("daydaydaydayday:" . $Channel);
|
impAccountDayActive("rar");
|
// impAccountDayActiveTestData();
|
}
|
// 重导日活、重刷报表;前提是先试用 /Server/eventdata/ImportBakDailyActive.py 运行导出中心流向备档日活数据结果保存到json文件
|
if ($opt == "reDayActive") {
|
$AccountDayActiveOK = \DBOper\Remove("AccountDayActive", array("Channel" => $Channel));
|
logweb("AccountDayActiveOK:" . $AccountDayActiveOK);
|
impAccountDayActive("json");
|
}
|
if (!$opt || $opt == "rep" || $opt == "rerep" || $opt == "reDayActive") {
|
logweb("开始导出每日报表:" . $Channel);
|
if ($opt == "rerep" || $opt == "reDayActive") {
|
$DailyReportOK = \DBOper\Remove("DailyReport", array("Channel" => $Channel));
|
$AccountFirstLoginReportOK = \DBOper\Remove("AccountFirstLoginReport", array("Channel" => $Channel));
|
$AccountFirstPayReportOK = \DBOper\Remove("AccountFirstPayReport", array("Channel" => $Channel));
|
$eventYMDOK = \DBOper\Remove("ServerEvent", array("Key" => "FirstKeepReportYMD_" . $Channel));
|
logweb("DailyReportOK:" . $DailyReportOK);
|
logweb("AccountFirstLoginReportOK:" . $AccountFirstLoginReportOK);
|
logweb("AccountFirstPayReportOK:" . $AccountFirstPayReportOK);
|
logweb("eventYMDOK:" . $eventYMDOK);
|
}
|
\Report\CheckAndExportDailyReport($Channel);
|
logweb("开始导出留存报表:" . $Channel);
|
\Report\CheckAndExportFirstKeepReport($Channel);
|
}
|
logweb("处理完毕!");
|
exit();
|
|
function impAccountFirstLogin()
|
{
|
global $Channel;
|
logweb("开始导入首登账号");
|
\DBOper\Find("AccountFirstLogin", array("Channel" => $Channel), $findFirstLoginDataList, array("AccountID" => 1));
|
$firstLoginAccountIDList = array();
|
foreach ($findFirstLoginDataList as $findData) {
|
$firstLoginAccountIDList[$findData["AccountID"]] = 1;
|
}
|
logweb("已存在首登账号数:" . count($firstLoginAccountIDList));
|
|
$limit = 10000;
|
$skip = 0;
|
$succCountTotal = 0;
|
|
$gameRolesCount = \DBOper\Count("GameRoles", array("Channel" => $Channel));
|
logweb("GameRoles 总条数:" . $gameRolesCount);
|
|
while ($gameRolesCount > 0) {
|
$ret = \DBOper\Find("GameRoles", array("Channel" => $Channel), $rolesDataList, null, null, $limit, $skip);
|
logweb("查询GameRoles: limit:" . $limit . " skip:" . $skip . " ret:" . $ret . " findCount:" . count($rolesDataList));
|
|
$batchInsFirstLogin = array();
|
foreach ($rolesDataList as $findData) {
|
$AccountID = $findData["AccountID"];
|
if (isset($firstLoginAccountIDList[$AccountID])) {
|
continue;
|
}
|
$firstLoginAccountIDList[$AccountID] = 1;
|
|
$firstLoginInfo = null;
|
$firstLoginTime = "";
|
foreach ($findData as $field => $value) {
|
$ServerID = \CommFunc\GetServerIDBySid($field);
|
if ($ServerID <= 0) {
|
continue;
|
}
|
$roleInfo = $value;
|
$roleInfo["ServerID"] = $ServerID;
|
$CreateRoleTime = $roleInfo["CreateRoleTime"];
|
// $PlayerID = $roleInfo["PlayerID"];
|
// $PlayerName = $roleInfo["PlayerName"];
|
// $Job = $roleInfo["Job"];
|
// $IP = $roleInfo["IP"];
|
// $LoginTime = $roleInfo["LoginTime"];
|
// $LogoffTime = $roleInfo["LogoffTime"];
|
|
// 首次创角
|
if ($CreateRoleTime < $firstLoginTime || $firstLoginTime == "") {
|
$firstLoginTime = $CreateRoleTime;
|
$firstLoginInfo = $roleInfo;
|
}
|
}
|
|
if (isset($firstLoginInfo)) {
|
$CreateRoleTime = $firstLoginInfo["CreateRoleTime"];
|
$CreateYMD = substr($CreateRoleTime, 0, 10);
|
|
if (!array_key_exists($CreateYMD, $batchInsFirstLogin)) {
|
$batchInsFirstLogin[$CreateYMD] = array();
|
}
|
$insArray = $batchInsFirstLogin[$CreateYMD];
|
array_push($insArray, array(
|
"Channel" => $Channel,
|
"AccountID" => $AccountID,
|
"CreateYMD" => $CreateYMD,
|
"CreateTime" => $CreateRoleTime,
|
"ServerID" => $firstLoginInfo["ServerID"],
|
"PlayerID" => $firstLoginInfo["PlayerID"],
|
"PlayerName" => $firstLoginInfo["PlayerName"],
|
"Job" => $firstLoginInfo["Job"],
|
"IP" => $firstLoginInfo["IP"],
|
));
|
$batchInsFirstLogin[$CreateYMD] = $insArray;
|
}
|
}
|
|
logweb(" firstLoginAccountIDList:" . count($firstLoginAccountIDList));
|
$gameRolesCount -= $limit;
|
$skip += $limit;
|
|
if (count($batchInsFirstLogin)) {
|
ksort($batchInsFirstLogin);
|
$succCount = 0;
|
foreach ($batchInsFirstLogin as $CreateYMD => $insArray) {
|
if (DBOper\BatchInsert("AccountFirstLogin", $insArray)) {
|
// logweb("批量导入首登账号数: CreateYMD:" . $CreateYMD . " count:" . count($insArray));
|
$succCount += count($insArray);
|
} else {
|
logweb("###批量导入首登账号数异常: CreateYMD:" . $CreateYMD . " count:" . count($insArray));
|
}
|
}
|
$succCountTotal += $succCount;
|
logweb("新增导入首登账号数: " . $succCount);
|
}
|
}
|
|
logweb("本次新增导入首登账号总数: " . $succCountTotal);
|
\Logging\LogInfo("---------------------------------------------------------------");
|
echo "<hr/>";
|
}
|
|
function impAccountFirstPay()
|
{
|
global $Channel;
|
logweb("开始导入首充账号");
|
\DBOper\Find("AccountFirstPay", array("Channel" => $Channel), $findFirstPayDataList, array("AccountID" => 1));
|
$firstPayAccountIDList = array();
|
foreach ($findFirstPayDataList as $findData) {
|
$firstPayAccountIDList[$findData["AccountID"]] = 1;
|
}
|
logweb("已存在首充账号数:" . count($firstPayAccountIDList));
|
|
$payOrderCount = \DBOper\Count("PayOrder", array("Channel" => $Channel));
|
logweb("PayOrder 总条数:" . $payOrderCount);
|
|
$limit = 10000;
|
$skip = 0;
|
$succCountTotal = 0;
|
|
while ($payOrderCount > 0) {
|
$ret = \DBOper\Find("PayOrder", array("Channel" => $Channel), $payDataList, null, array("PayTime" => 1), $limit, $skip);
|
logweb("查询PayOrder: limit:" . $limit . " skip:" . $skip . " ret:" . $ret . " findCount:" . count($payDataList));
|
|
$batchInsFirstPay = array();
|
foreach ($payDataList as $payOrderInfo) {
|
$AccountID = $payOrderInfo["AccountID"];
|
if (isset($firstPayAccountIDList[$AccountID])) {
|
continue;
|
}
|
$firstPayAccountIDList[$AccountID] = 1;
|
|
$PayYMD = substr($payOrderInfo["PayTime"], 0, 10);
|
|
if (!array_key_exists($PayYMD, $batchInsFirstPay)) {
|
$batchInsFirstPay[$PayYMD] = array();
|
}
|
$insArray = $batchInsFirstPay[$PayYMD];
|
|
array_push($insArray, array(
|
"Channel" => $Channel,
|
"AccountID" => $AccountID,
|
"OrderID" => $payOrderInfo["OrderID"],
|
"OrderIDSDK" => $payOrderInfo["OrderIDSDK"],
|
"ServerID" => $payOrderInfo["ServerID"],
|
"OrderInfo" => $payOrderInfo["OrderInfo"],
|
"OrderAmount" => $payOrderInfo["OrderAmount"], // 中心的这个字段是实际支付金额
|
"OriginalAmount" => $payOrderInfo["OriginalAmount"],
|
"PayTime" => $payOrderInfo["PayTime"],
|
"PayYMD" => $PayYMD,
|
"Extras" => $payOrderInfo["Extras"],
|
));
|
|
$batchInsFirstPay[$PayYMD] = $insArray;
|
}
|
|
logweb(" firstPayAccountIDList:" . count($firstPayAccountIDList));
|
$payOrderCount -= $limit;
|
$skip += $limit;
|
|
if (count($batchInsFirstPay)) {
|
ksort($batchInsFirstPay);
|
$succCount = 0;
|
foreach ($batchInsFirstPay as $PayTime => $insArray) {
|
if (DBOper\BatchInsert("AccountFirstPay", $insArray)) {
|
// logweb("批量导入首充账号数: PayTime:" . $PayTime . " count:" . count($insArray));
|
$succCount += count($insArray);
|
} else {
|
logweb("###批量导入首充账号数异常: PayTime:" . $PayTime . " count:" . count($insArray));
|
}
|
}
|
$succCountTotal += $succCount;
|
logweb("新增导入首充账号数: " . $succCount);
|
}
|
}
|
|
logweb("本次新增导入首充账号总数: " . $succCountTotal);
|
\Logging\LogInfo("---------------------------------------------------------------");
|
echo "<hr/>";
|
}
|
|
function impAccountDayActive($bakWay = "")
|
{
|
global $Channel;
|
$startDate = $_GET["startDate"];
|
if (!$startDate) {
|
$startDate = "2024-05-01";
|
}
|
logweb("开始从中心导入备档日活数据! startDate:" . $startDate);
|
|
$allDateAccIDInfo = array(); // 所有记录
|
// 查询备份流向
|
if ($bakWay == "rar") {
|
$pack_data = array();
|
$pack_data["spID"] = $Channel;
|
$pack_data["eventType"] = "QueryAccountLoginOut";
|
$pack_data["queryCenterbak"] = 1; # 设置查询中心的
|
$pack_data["allServer"] = 1; # 设置检索所有服务器流向
|
$pack_data["startDate"] = $startDate;
|
$pack_data["endDate"] = "";
|
$centerToolUrl = 'http://' . $_SERVER['HTTP_HOST'] . "/Server/eventdata/toolcenter.php";
|
logweb("centerToolUrl:" . $centerToolUrl);
|
|
$retStr = \CommFunc\DoPost($centerToolUrl, $pack_data, false, 300);
|
$ret = json_decode($retStr, true);
|
if (isset($ret)) {
|
$allDateAccIDInfo = $ret[0];
|
} else {
|
logweb("query center backup error: " . $retStr);
|
return;
|
}
|
} elseif ($bakWay == "json") {
|
if (!\CommFunc\GetConfig("ServerInfo", "PlayerCenterRoot", $PlayerCenterRoot)) {
|
return "";
|
}
|
$jsonFile = $PlayerCenterRoot . "/Server/eventdata/BakDailyActive.json";
|
logweb("jsonFile:" . $jsonFile);
|
if (!file_exists($jsonFile)) {
|
logweb("###jsonFile is not exists:" . $jsonFile);
|
return;
|
}
|
$allDateAccIDInfo = json_decode(file_get_contents($jsonFile), true);
|
}
|
if (!isset($allDateAccIDInfo)) {
|
logweb("###center bak AccountDayActive error.");
|
return;
|
}
|
ksort($allDateAccIDInfo);
|
foreach ($allDateAccIDInfo as $dateStr => $accIDInfo) {
|
logweb("中心流向备档日活数量:" . " dateStr:" . $dateStr . " count:" . count($accIDInfo));
|
}
|
|
logweb("开始从子服导入日活数据! startDate:" . $startDate);
|
$pack_data = array();
|
$pack_data["spID"] = $Channel;
|
$pack_data["eventType"] = "QueryAccountLoginOut";
|
// $pack_data["queryAllData"] = "on"; // 设置可查询备份数据,子服不查备份流向,防止同时多服访问多次
|
$pack_data["startDate"] = $startDate;
|
$pack_data["endDate"] = "";
|
$sendServers = array();
|
$serverPageInfos = \CommFunc\GetGameServerPageInfo($Channel);
|
// 多服查询的
|
foreach ($serverPageInfos as $mainServerID => $serverInfo) {
|
$sendServers[] = array($mainServerID, \CommFunc\GetQueryEventToolUrl($serverInfo['Page']), $pack_data);
|
}
|
\Logging\LogInfo("待发送的服务器信息: " . count($sendServers) . " " . print_r($sendServers, true));
|
|
$retList = array();
|
$retMulti = \CommFunc\DoPostMulti($sendServers);
|
if ($retMulti && count($retMulti) == count($sendServers)) {
|
for ($i = 0; $i < count($sendServers); $i++) {
|
$ret = json_decode($retMulti[$i], true);
|
if (!isset($ret)) {
|
$retList[$sendServers[$i][0]] = $retMulti[$i];
|
} else {
|
$retList[$sendServers[$i][0]] = $ret;
|
}
|
}
|
}
|
|
$retCount = count($retList);
|
\Logging\LogInfo("返回查询结果条数: " . $retCount);
|
// \Logging\LogInfo("retList: " . print_r($retList, true));
|
|
// 先合并中心备份 及 各服务器数据
|
foreach ($retList as $serverName => $ret) {
|
logweb("-----");
|
if (is_array($ret) && $ret["OK"] == 1) {
|
ksort($ret["loginoutDateAccIDInfo"]);
|
foreach ($ret["loginoutDateAccIDInfo"] as $dateStr => $accIDInfo) {
|
logweb("服务器返回日活数量 serverName:" . $serverName . " dateStr:" . $dateStr . " count:" . count($accIDInfo));
|
if (!isset($allDateAccIDInfo[$dateStr])) {
|
$allDateAccIDInfo[$dateStr] = array();
|
}
|
$allAccIDInfo = $allDateAccIDInfo[$dateStr];
|
foreach ($accIDInfo as $accID => $loginoutInfo) {
|
$allAccIDInfo[$accID] = $loginoutInfo; // 各子服一定是最新的,直接替换备份流向数据
|
}
|
$allDateAccIDInfo[$dateStr] = $allAccIDInfo;
|
}
|
} else {
|
logweb("###服务器返回日活数据异常! serverName:" . $serverName . " ret:" . $ret);
|
}
|
}
|
|
ksort($allDateAccIDInfo);
|
foreach ($allDateAccIDInfo as $dateStr => $accIDInfo) {
|
logweb("日活游戏账号数量:" . " dateStr:" . $dateStr . " count:" . count($accIDInfo));
|
$accountIDArray = array();
|
$dateInsInfo = array();
|
foreach ($accIDInfo as $accID => $loginoutInfo) {
|
// logweb(" accID:" . $accID. json_encode($loginoutInfo));
|
$accIDParts = explode("@", $accID);
|
$AccountID = implode("@", array_slice($accIDParts, 0, count($accIDParts) - 2));
|
$ServerID = \CommFunc\GetServerIDBySid($accIDParts[count($accIDParts) - 1]);
|
$LoginTime = $loginoutInfo[0];
|
$LogoffTime = $loginoutInfo[1];
|
$IP = $loginoutInfo[2];
|
$ActiveYMD = "";
|
if ($LoginTime != "") {
|
$ActiveYMD = substr($LoginTime, 0, 10);
|
} else {
|
$ActiveYMD = substr($LogoffTime, 0, 10);
|
}
|
|
if ($accountIDArray[$AccountID]) {
|
logweb("###今日日活账号已存在:AccountID:" . $$AccountID . " accID:" . $accID);
|
continue;
|
}
|
$accountIDArray[$AccountID] = 1;
|
array_push($dateInsInfo, array(
|
"Channel" => $Channel,
|
"AccountID" => $AccountID,
|
"ActiveYMD" => $ActiveYMD,
|
"LoginTime" => $LoginTime,
|
"LogoffTime" => $LogoffTime,
|
"ServerID" => $ServerID,
|
"IP" => $IP,
|
));
|
}
|
|
$actCount = DBOper\Count("AccountDayActive", array("Channel" => $Channel, "ActiveYMD" => $dateStr));
|
if ($actCount == count($dateInsInfo)) {
|
logweb("日活数据数相同,不重新插入: " . $dateStr . " count:" . $actCount);
|
continue;
|
}
|
// 数据量不同,则删除后重新插入
|
if ($actCount > 0) {
|
if (!DBOper\Remove("AccountDayActive", array("Channel" => $Channel, "ActiveYMD" => $dateStr), false)) {
|
logweb("###日活数据数不同,移除时失败!: " . $dateStr . " delCount:" . $actCount . " insCount:" . count($dateInsInfo));
|
continue;
|
}
|
}
|
if (DBOper\BatchInsert("AccountDayActive", $dateInsInfo)) {
|
logweb("批量导入日活数:" . $dateStr . " count:" . count($dateInsInfo));
|
} else {
|
logweb("###批量导入日活数失败:" . $dateStr . " count:" . count($dateInsInfo));
|
}
|
}
|
|
\Logging\LogInfo("---------------------------------------------------------------");
|
echo "<hr/>";
|
}
|
|
// 插入山寨日活数据
|
function impAccountDayActiveTestData()
|
{
|
global $Channel;
|
DBOper\Remove("AccountDayActive", array(), false);
|
\DBOper\Find("AccountFirstLogin", array("Channel" => $Channel), $findFirstLoginDataList, array("CreateYMD" => 1, "AccountID" => 1));
|
$firstAccountIDInfo = array();
|
foreach ($findFirstLoginDataList as $findData) {
|
$CreateYMD = $findData["CreateYMD"];
|
$AccountID = $findData["AccountID"];
|
if (!isset($firstAccountIDInfo[$CreateYMD])) {
|
$firstAccountIDInfo[$CreateYMD] = array();
|
}
|
$accountIDList = $firstAccountIDInfo[$CreateYMD];
|
array_push($accountIDList, $AccountID);
|
$firstAccountIDInfo[$CreateYMD] = $accountIDList;
|
}
|
|
$keepPer = 100;
|
$keepPerSet = array(100, 50, 35, 30, 25, 15, 10);
|
ksort($firstAccountIDInfo);
|
foreach ($firstAccountIDInfo as $CreateYMD => $accountIDList) {
|
logweb("CreateYMD:" . $CreateYMD . " count:" . count($accountIDList));
|
if ($CreateYMD < "2024-05-23") {
|
continue;
|
}
|
$dateInsInfo = array();
|
$accountCount = count($accountIDList);
|
$onePerCount = $accountCount * 0.1;
|
for ($i = 0; $i < 30; $i++) {
|
// $randNum = mt_rand(1, 100);
|
if (count($keepPerSet) > $i) {
|
$keepPer = $keepPerSet[$i];
|
} else {
|
$keepPer = mt_rand(-1, 5);
|
}
|
if ($keepPer <= 0) {
|
continue;
|
}
|
|
$keepCount = $accountCount;
|
if ($keepPer < 100) {
|
$keepCount = intval($accountCount * $keepPer / 100.0);
|
$keepCount = mt_rand($keepCount - $onePerCount, $keepCount + $onePerCount);
|
}
|
if ($keepCount <= 0) {
|
continue;
|
}
|
|
$ActiveYMD = date("Y-m-d", strtotime("+" . $i . " day", strtotime($CreateYMD)));
|
logweb("CreateYMD:" . $CreateYMD . " i:" . $i . " ActiveYMD:" . $ActiveYMD . " keepPer:" . $keepPer . " keepCount:" . $keepCount);
|
|
for ($k = 0; $k < $keepCount; $k++) {
|
$AccountID = $accountIDList[$k];
|
array_push($dateInsInfo, array(
|
"Channel" => $Channel,
|
"AccountID" => $AccountID,
|
"ActiveYMD" => $ActiveYMD,
|
"LoginTime" => $ActiveYMD . " 00:00:00",
|
"LogoffTime" => $ActiveYMD . " 23:59:59",
|
"ServerID" => 999,
|
"IP" => "127.0.0.1",
|
));
|
}
|
}
|
|
if (DBOper\BatchInsert("AccountDayActive", $dateInsInfo)) {
|
logweb("批量山寨日活数, CreateYMD:" . $CreateYMD . " count:" . count($dateInsInfo));
|
} else {
|
logweb("###批量山寨日活数失败, CreateYMD:" . $CreateYMD . " count:" . count($dateInsInfo));
|
}
|
}
|
}
|
|
function logweb($msg, $showWeb = True)
|
{
|
\Logging\LogInfo($msg);
|
if ($showWeb) {
|
echo date('Y-m-d H:i:s'), $msg, "<br/>";
|
}
|
}
|