| | |
| | | }
|
| | | $StartYMDTime = 0; // 需要导出的起始日期时间戳
|
| | | if (isset($retInfo)) {
|
| | | // \Logging\LogInfo("DailyReport retInfo:" . print_r($retInfo, true));
|
| | | $lastActiveYMD = $retInfo["YMD"]; // 最后一次导出的报表日期
|
| | | $StartYMDTime = strtotime("+1 day", strtotime($lastActiveYMD)); // 从+1天开始导出
|
| | | $lastYMD = $retInfo["YMD"]; // 最后一次导出的报表日期
|
| | | $StartYMDTime = strtotime("+1 day", strtotime($lastYMD)); // 从+1天开始导出
|
| | | \Logging\LogInfo("ExportDailyReport Channel:" . $Channel . " lastYMD:" . $lastYMD . " StartYMDTime:" . date("Y-m-d", $StartYMDTime));
|
| | | } else {
|
| | | // 取出最早的首登日期
|
| | | if (!\DBOper\FindOneSort("AccountFirstLogin", array("Channel" => $Channel), $retInfo, array("CreateYMD" => 1), array("CreateYMD" => 1))) {
|
| | | return;
|
| | | }
|
| | | if (!isset($retInfo)) {
|
| | | // \Logging\LogInfo("AccountFirstLogin 还没有数据,不用导出! Channel:" . $Channel);
|
| | | \Logging\LogInfo("ExportDailyReport AccountFirstLogin 还没有数据,不用导出! Channel:" . $Channel);
|
| | | return;
|
| | | }
|
| | | // \Logging\LogInfo("AccountFirstLogin retInfo:" . print_r($retInfo, true));
|
| | | $StartYMDTime = strtotime($retInfo["CreateYMD"]);
|
| | | \Logging\LogInfo("ExportDailyReport Channel:" . $Channel . " AccountFirstLogin StartYMDTime:" . date("Y-m-d", $StartYMDTime));
|
| | | }
|
| | | if (!$StartYMDTime) {
|
| | | return;
|
| | |
| | |
|
| | | $EndYMDTime = strtotime("-1 day", strtotime(date("Y-m-d"))); // 只导出到昨天
|
| | | $diffSeconds = $EndYMDTime - $StartYMDTime;
|
| | | $diffDays = floor($diffSeconds / (3600 * 24));
|
| | | $diffDays = floor($diffSeconds / (3600 * 24)) + 1;
|
| | | if ($diffDays <= 0) {
|
| | | \Logging\LogInfo("【 " . $Channel . " 】不需要导出每日报表! StartYMDTime:" . date("Y-m-d", $StartYMDTime));
|
| | | return;
|
| | |
| | | $DNU = \DBOper\Count("AccountFirstLogin", array("Channel" => $Channel, "CreateYMD" => $YMD));
|
| | | \Logging\LogInfo(" 日新增用户数 DNU:" . $DNU);
|
| | |
|
| | | $DNPU = \DBOper\Count("AccountFirstPay", array("Channel" => $Channel, "PayYMD" => $YMD));
|
| | | \Logging\LogInfo(" 日新增充值用户数 DNPU:" . $DNPU);
|
| | |
|
| | | $ret = \DBOper\Aggregate("AccountFirstPay", array(
|
| | | array(
|
| | | '$match' => array("Channel" => $Channel, "PayYMD" => $YMD),
|
| | | ),
|
| | | array(
|
| | | '$group' => array(
|
| | | '_id' => null,
|
| | | 'total' => array('$sum' => '$OrderAmount'),
|
| | | ),
|
| | | )
|
| | | ), $retInfo);
|
| | | $DRNPU = 0;
|
| | | if ($ret && isset($retInfo) && count($retInfo) > 0) {
|
| | | $DRNPU = $retInfo[0]["total"];
|
| | | \DBOper\Find("AccountFirstPay", array("Channel" => $Channel, "PayYMD" => $YMD), $ret, array("AccountID" => 1));
|
| | | $firstPayAccountIDInfo = array();
|
| | | if (isset($ret)) {
|
| | | foreach ($ret as $firstPayInfo) {
|
| | | $AccountID = $firstPayInfo["AccountID"];
|
| | | $firstPayAccountIDInfo[$AccountID] = 1;
|
| | | }
|
| | | }
|
| | | $DRNPU = round($DRNPU, 2);
|
| | | \Logging\LogInfo(" 日新增充值用户充值总额 DRNPU:" . $DRNPU);
|
| | |
|
| | | $ret = \DBOper\Aggregate("PayOrder", array(
|
| | | array(
|
| | |
| | | ), $retInfo);
|
| | | $DPU = 0;
|
| | | $DRPU = 0;
|
| | | $DRNPU = 0;
|
| | | if ($ret && isset($retInfo)) {
|
| | | foreach ($retInfo as $info) {
|
| | | $DPU += 1;
|
| | | $AccountID = $info["_id"]["AccountID"];
|
| | | $DRPU += $info["total"];
|
| | | if ($firstPayAccountIDInfo[$AccountID]) {
|
| | | $DRNPU += $info["total"];
|
| | | }
|
| | | }
|
| | | }
|
| | | $DRPU = round($DRPU, 2);
|
| | | $DRNPU = round($DRNPU, 2);
|
| | | $DNPU = count($firstPayAccountIDInfo);
|
| | | \Logging\LogInfo(" 日新增充值用户数 DNPU:" . $DNPU);
|
| | | \Logging\LogInfo(" 日新增充值用户充值总额 DRNPU:" . $DRNPU);
|
| | | \Logging\LogInfo(" 日充值用户数 DPU:" . $DPU);
|
| | | \Logging\LogInfo(" 日充值用户数充值总额 DRPU:" . $DRPU);
|
| | |
|
| | |
| | | );
|
| | | }
|
| | |
|
| | | /**检查并导出首登/首充留存每日报表 */
|
| | | /**检查并导出首登/首充每日报表 */
|
| | | function CheckAndExportFirstKeepReport($Channel)
|
| | | {
|
| | | if (!\DBOper\FindOne("ServerEvent", array("Key" => "AccountFirstKeepReportYMD"), $ret, null, false)) {
|
| | | $eventKey = "FirstKeepReportYMD_" . $Channel;
|
| | | if (!\DBOper\FindOne("ServerEvent", array("Key" => $eventKey), $ret, null, false)) {
|
| | | return;
|
| | | }
|
| | | $reportYMD = $ret["Value"] ? $ret["Value"] : ""; // 最后一次成功导出报表日期
|
| | |
| | | $StartYMDTime = 0; // 需要导出的起始日期时间戳
|
| | | if ($reportYMD) {
|
| | | $StartYMDTime = strtotime("+1 day", strtotime($reportYMD)); // 从+1天开始导出
|
| | | \Logging\LogInfo("ExportFirstKeepReport Channel:" . $Channel . " reportYMD:" . $reportYMD . " StartYMDTime:" . date("Y-m-d", $StartYMDTime));
|
| | | } else {
|
| | | // 取出最早的首登日期
|
| | | if (!\DBOper\FindOneSort("AccountFirstLogin", array("Channel" => $Channel), $retInfo, array("CreateYMD" => 1), array("CreateYMD" => 1))) {
|
| | | return;
|
| | | }
|
| | | if (!isset($retInfo)) {
|
| | | \Logging\LogInfo("ExportFirstKeepReport AccountFirstLogin 还没有数据,不用导出! Channel:" . $Channel);
|
| | | return;
|
| | | }
|
| | | $StartYMDTime = strtotime($retInfo["CreateYMD"]);
|
| | | \Logging\LogInfo("ExportFirstKeepReport Channel:" . $Channel . " AccountFirstLogin StartYMDTime:" . date("Y-m-d", $StartYMDTime));
|
| | | }
|
| | | if (!$StartYMDTime) {
|
| | | return;
|
| | |
| | | $StartYMD = date("Y-m-d", $StartYMDTime);
|
| | | $EndYMDTime = strtotime("-1 day", strtotime(date("Y-m-d"))); // 只导出到昨天
|
| | | $diffSeconds = $EndYMDTime - $StartYMDTime;
|
| | | $diffDays = floor($diffSeconds / (3600 * 24));
|
| | | $diffDays = floor($diffSeconds / (3600 * 24)) + 1;
|
| | | if ($diffDays <= 0) {
|
| | | \Logging\LogInfo("【 " . $Channel . " 】不需要导出首登每日报表! StartYMD:" . $StartYMD);
|
| | | return;
|
| | |
| | | foreach ($ymdArray as $ReportYMD => $statInfo) {
|
| | | $keepCount = $statInfo["keepCount"] ? $statInfo["keepCount"] : 0;
|
| | | $payTotal = $statInfo["payTotal"] ? $statInfo["payTotal"] : 0;
|
| | | $payCnt = $statInfo["payCnt"] ? $statInfo["payCnt"] : 0;
|
| | | $firstPayCnt = $statInfo["firstPayCnt"] ? $statInfo["firstPayCnt"] : 0;
|
| | | array_push($batchInsDatas, array(
|
| | | "Channel" => $Channel,
|
| | | "CreateYMD" => $CreateYMD,
|
| | | "ReportYMD" => $ReportYMD,
|
| | | "KeepCount" => $keepCount,
|
| | | "PayTotal" => $payTotal,
|
| | | "PayCnt" => $payCnt,
|
| | | "FirstPayCnt" => $firstPayCnt,
|
| | | ));
|
| | | }
|
| | | }
|
| | |
| | | if (!\DBOper\BatchInsert("AccountFirstLoginReport", $batchInsDatas)) {
|
| | | return;
|
| | | }
|
| | | \Logging\LogInfo("AccountFirstLoginReport 插入OK:" . count($batchInsDatas));
|
| | | }
|
| | |
|
| | | // 生成插入数据
|
| | |
| | | if (!\DBOper\BatchInsert("AccountFirstPayReport", $batchInsDatas)) {
|
| | | return;
|
| | | }
|
| | | \Logging\LogInfo("AccountFirstPayReport 插入OK:" . count($batchInsDatas));
|
| | | }
|
| | |
|
| | | // 全部处理完毕才更新
|
| | | \DBOper\Update("ServerEvent", array("Key" => "AccountFirstKeepReportYMD"), array("Value" => $EndYMD), false, true);
|
| | | \DBOper\Update("ServerEvent", array("Key" => $eventKey), array("Value" => $EndYMD), false, true);
|
| | | \Logging\LogInfo("==============================================");
|
| | | }
|
| | |
|
| | |
| | | * 统计首登相关留存日期报表,包含充值(用于ltv计算)
|
| | | * @param string $Channel
|
| | | * @param string $YMD 要统计的报表日期yyyy-MM-dd
|
| | | * @param array $fistLoginReportArray 统计首登报表结果 {首登日期:{统计日期:{keepCount:x, payTotal:x}} ...}}
|
| | | * @param array $fistLoginReportArray 统计首登报表结果 {首登日期:{统计日期:{keepCount:x, payTotal:x, payCnt:x, firstPayCnt:x}} ...}}
|
| | | * @param array $fistPayReportArray 统计首充报表结果 {首充日期:{统计日期:{keepCount:x}} ...}}
|
| | | * @param array $accountFirstLoginDateInfo 账号首登日期信息 {accountID:firstLoginYMD, ...}
|
| | | * @param array $accountFirstPayDateInfo 账号首充日期信息 {accountID:firstPayYMD, ...}
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | // 今日首付账号
|
| | | if (
|
| | | !\DBOper\Find("AccountFirstPay", array("Channel" => $Channel, "PayYMD" => $YMD), $firstPayRetArray, array("AccountID" => 1))
|
| | | || !isset($firstPayRetArray)
|
| | | ) {
|
| | | return;
|
| | | }
|
| | | $accountFirstPayDict = array(); // 统计日期首付账号
|
| | | foreach ($firstPayRetArray as $firstPayInfo) {
|
| | | $accountFirstPayDict[$firstPayInfo["AccountID"]] = 1;
|
| | | }
|
| | |
|
| | | if (
|
| | | !\DBOper\Find(
|
| | | "PayOrder",
|
| | |
| | | }
|
| | | $statYMDInfo = $fistLoginReportArray[$FirstLoginYMD];
|
| | | if (!isset($statYMDInfo[$YMD])) {
|
| | | $statYMDInfo[$YMD] = array();
|
| | | $statYMDInfo[$YMD] = array("keepCount" => 0, "payTotal" => 0, "payCnt" => 0, "firstPayCnt" => 0);
|
| | | }
|
| | | $statInfo = $statYMDInfo[$YMD];
|
| | | $statInfo["keepCount"] = ($statInfo["keepCount"] ? $statInfo["keepCount"] : 0) + 1;
|
| | |
|
| | | $payTotal = $accountPayDict[$AccountID] ? $accountPayDict[$AccountID] : 0;
|
| | | $statInfo["payTotal"] = ($statInfo["payTotal"] ? $statInfo["payTotal"] : 0) + $payTotal;
|
| | | if ($payTotal > 0) {
|
| | | $statInfo["payCnt"] = ($statInfo["payCnt"] ? $statInfo["payCnt"] : 0) + 1;
|
| | | }
|
| | |
|
| | | if ($accountFirstPayDict[$AccountID]) {
|
| | | $statInfo["firstPayCnt"] = ($statInfo["firstPayCnt"] ? $statInfo["firstPayCnt"] : 0) + 1;
|
| | | }
|
| | |
|
| | | $statYMDInfo[$YMD] = $statInfo;
|
| | | $fistLoginReportArray[$FirstLoginYMD] = $statYMDInfo;
|
| | |
| | | * @param string $Channel
|
| | | * @param string $fromYMD 起始日期yyyy-MM-dd
|
| | | * @param string $toYMD 到日期yyyy-MM-dd
|
| | | * @param array &$fistLoginReportArray {首登日期:{统计日期:{keepCount:x, payTotal:x}} ...}}
|
| | | * @param array &$fistLoginReportArray {首登日期:{统计日期:{keepCount:x, payTotal:x, payCnt:x, firstPayCnt:x}} ...}}
|
| | | * @param array &$fistPayReportArray {首充日期:{统计日期:{keepCount:x}} ...}}
|
| | | */
|
| | | function GetAccountFirstLoginPayReport($Channel, $fromYMD, $toYMD, &$fistLoginReportArray, &$fistPayReportArray)
|
| | | {
|
| | | CheckAndExportFirstKeepReport($Channel); // 每次获取检查导出
|
| | | $find = array("Channel" => $Channel, "CreateYMD" => array('$gte' => $fromYMD, '$lte' => $toYMD));
|
| | | \DBOper\Find("AccountFirstLoginReport", $find, $newUserRetArray, array("CreateYMD" => 1, "ReportYMD" => 1, "KeepCount" => 1, "PayTotal" => 1));
|
| | | \DBOper\Find("AccountFirstLoginReport", $find, $newUserRetArray);
|
| | | if (!isset($newUserRetArray)) {
|
| | | $newUserRetArray = array();
|
| | | }
|
| | |
| | | $fistLoginReportArray[$FirstLoginYMD] = array();
|
| | | }
|
| | | $statYMDInfo = $fistLoginReportArray[$FirstLoginYMD];
|
| | | $statYMDInfo[$ReportYMD] = array("keepCount" => $info["KeepCount"], "payTotal" => $info["PayTotal"]);
|
| | | $statYMDInfo[$ReportYMD] = array(
|
| | | "keepCount" => $info["KeepCount"], "payTotal" => $info["PayTotal"],
|
| | | "payCnt" => $info["PayCnt"], "firstPayCnt" => $info["FirstPayCnt"]
|
| | | );
|
| | | $fistLoginReportArray[$FirstLoginYMD] = $statYMDInfo;
|
| | | }
|
| | | ksort($fistLoginReportArray);
|
| | |
| | | ksort($fistPayReportArray);
|
| | | return;
|
| | | }
|
| | |
|
| | | // function test()
|
| | | // {
|
| | | // echo "run test" . "<br/>";
|
| | | // \Logging\CreateLogging("test.report.php");
|
| | | // $AllChannel = \CommFunc\GetAllChannel();
|
| | | // for ($i = 0; $i < count($AllChannel); $i++) {
|
| | | // $Channel = $AllChannel[$i];
|
| | | // echo "run Channel" . $Channel . "<br/>";
|
| | | // CheckAndExportDailyReport($Channel);
|
| | | // CheckAndExportFirstKeepReport($Channel);
|
| | | // }
|
| | | // echo "run test end" . "<br/>";
|
| | | // }
|
| | | // test(); |