|
|
@@ -15,7 +15,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
$params = $this->searchByAuth($params);
|
|
|
$whereRaw = $this->getCommonWhereRaw($params);
|
|
|
$field = "SUM(reg_total) AS reg_total, tdate, game_id";
|
|
|
- $yearRange = getYearRange($params['reg_date'][0], $params['reg_date'][1]);
|
|
|
+ $yearRange = getYearRange($params['tdate'][0], $params['tdate'][1]);
|
|
|
$baseData = $this->generateUnionList('base_total_day', $yearRange, $whereRaw, $field, 'game_id,tdate');
|
|
|
|
|
|
$data = [];
|
|
|
@@ -40,7 +40,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
}
|
|
|
|
|
|
// 获取两个注册日期之间的日期列表
|
|
|
- $dateList = getDateRange($params['reg_date'][0], $params['reg_date'][1]);
|
|
|
+ $dateList = getDateRange($params['tdate'][0], $params['tdate'][1]);
|
|
|
$columnsData = [
|
|
|
[
|
|
|
'title' => '游戏ID',
|
|
|
@@ -73,29 +73,20 @@ class AnalyseLogic extends BaseLogic
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- 数据总览
|
|
|
- */
|
|
|
-
|
|
|
- public function getRegHourDataList($where)
|
|
|
+ // 注册分时
|
|
|
+ public function getRegHourDataList($params)
|
|
|
{
|
|
|
- $params = $this->searchByAuth($where);
|
|
|
-
|
|
|
+ $params = $this->searchByAuth($params);
|
|
|
+ $regDate = $params['tdate'];
|
|
|
+ $params['tdate'] = [$params['tdate'], $params['tdate']];
|
|
|
$field = "SUM(role_create_user) AS role_create_user, tdate,game_id,thour";
|
|
|
- $regDate = $where['reg_date'];
|
|
|
+
|
|
|
// 将$regDate转化为年月格式,如202509
|
|
|
$ym = date('Ym', strtotime($regDate));
|
|
|
-
|
|
|
$tableName = 'base_total_hour_' . $ym;
|
|
|
-
|
|
|
- $whereRaw = 'WHERE 1=1';
|
|
|
- if (!empty($params['game_id'])) {
|
|
|
- $whereRaw .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
|
|
|
- }
|
|
|
- if (!empty($params['reg_date'])) {
|
|
|
- $whereRaw .= " AND tdate = '" . $params['reg_date'] . "'";
|
|
|
- }
|
|
|
+ $whereRaw = $this->getCommonWhereRaw($params);
|
|
|
$sql = "SELECT {$field} FROM {$tableName} {$whereRaw} GROUP BY game_id,thour,tdate";
|
|
|
+
|
|
|
$baseData = Db::connect('db_data_report')->query($sql);
|
|
|
$data = [];
|
|
|
foreach ($baseData as &$row) {
|
|
|
@@ -127,28 +118,21 @@ class AnalyseLogic extends BaseLogic
|
|
|
/*
|
|
|
数据总览(按月)
|
|
|
*/
|
|
|
-
|
|
|
public function getRetentionDayDataList($where)
|
|
|
{
|
|
|
$params = $this->searchByAuth($where);
|
|
|
// 构建whereSql
|
|
|
- $whereRaw = '';
|
|
|
- if (!empty($params['game_id'])) {
|
|
|
- $whereRaw .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
|
|
|
- }
|
|
|
- if (!empty($params['reg_date'])) {
|
|
|
- $whereRaw .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
|
|
|
- }
|
|
|
+ $whereRaw = $this->getCommonWhereRaw($params);
|
|
|
|
|
|
$data = [];
|
|
|
$totalRow = ['game_id' => '合计'];
|
|
|
|
|
|
|
|
|
$baseField = "SUM(reg_total) AS reg_total, tdate,game_id";
|
|
|
- $activeField = "SUM(active_total) AS active_total, reg_date,game_id,days";
|
|
|
+ $activeField = "SUM(active_total) AS active_total, reg_date, game_id, days";
|
|
|
|
|
|
// 1. 查询每天的注册数,根据注册时间,游戏
|
|
|
- $yearRange = getYearRange($params['reg_date'][0], $params['reg_date'][1]);
|
|
|
+ $yearRange = getYearRange($params['tdate'][0], $params['tdate'][1]);
|
|
|
$baseData = $this->generateUnionList('base_total_day', $yearRange, $whereRaw, $baseField, 'game_id,tdate');
|
|
|
$baseData = array_column($baseData, null, 'tdate');
|
|
|
|
|
|
@@ -159,7 +143,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
$activeWhereSql .= " AND days = {$params['days']}";
|
|
|
}
|
|
|
|
|
|
- $activeData = $this->generateUnionList('game_active_day', $yearRange, $activeWhereSql, $activeField, 'game_id,reg_date');
|
|
|
+ $activeData = $this->generateUnionList('game_active_day', $yearRange, $activeWhereSql, $activeField, 'game_id, reg_date');
|
|
|
$activeData = array_column($activeData, null, 'reg_date');
|
|
|
|
|
|
foreach ($baseData as $row) {
|
|
|
@@ -207,7 +191,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
$totalRow['total'] = getPercent($totalRow['total_active_total'] ?? 0, $totalRow['total_reg_total'] ?? 0);
|
|
|
|
|
|
// 获取两个注册日期之间的日期列表
|
|
|
- $dateList = getDateRange($where['reg_date'][0], $where['reg_date'][1]);
|
|
|
+ $dateList = getDateRange($where['tdate'][0], $where['tdate'][1]);
|
|
|
$columnsData = [
|
|
|
[
|
|
|
'title' => '游戏ID',
|
|
|
@@ -257,7 +241,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
SUM(reg_pay_total) AS reg_pay_total,
|
|
|
SUM(old_login_total) AS old_login_total,
|
|
|
tdate";
|
|
|
- $yearRange = getYearRange($params['reg_date'][0], $params['reg_date'][1]);
|
|
|
+ $yearRange = getYearRange($params['tdate'][0], $params['tdate'][1]);
|
|
|
|
|
|
$baseData = $this->generateUnionList('base_total_day', $yearRange, $whereRaw, $field, 'tdate');
|
|
|
|
|
|
@@ -270,7 +254,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
|
|
|
$actWhereSql = str_replace("tdate", "reg_date", $whereRaw);
|
|
|
$actWhereSql .= " AND days = 1";
|
|
|
- $actData = $this->generateUnionList('game_active_day', $yearRange, $actWhereSql, 'SUM(active_total) AS active_total,reg_date', 'reg_date');
|
|
|
+ $actData = $this->generateUnionList('game_active_day', $yearRange, $actWhereSql, 'SUM(active_total) AS active_total, reg_date', 'reg_date');
|
|
|
$actData = array_column($actData, null, 'reg_date');
|
|
|
|
|
|
$totalRow = [
|
|
|
@@ -342,7 +326,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
SUM(reg_pay_total) AS reg_pay_total,
|
|
|
SUM(old_login_total) AS old_login_total,
|
|
|
date_format(`tdate`, '%Y-%m') AS mdate";
|
|
|
- $yearRange = getYearRange($params['reg_date'][0], $params['reg_date'][1]);
|
|
|
+ $yearRange = getYearRange($params['tdate'][0], $params['tdate'][1]);
|
|
|
|
|
|
$baseData = $this->generateUnionList('base_total_day', $yearRange, $whereRaw, $field, 'mdate');
|
|
|
|
|
|
@@ -413,10 +397,10 @@ class AnalyseLogic extends BaseLogic
|
|
|
public function getIncomeAnalysis($where)
|
|
|
{
|
|
|
$params = $this->searchByAuth($where);
|
|
|
- $tdate = $params['reg_date'] ?? date('Y-m-d');
|
|
|
+ $tdate = $params['tdate'] ?? date('Y-m-d');
|
|
|
$ldate = date('Y-m-d', strtotime($tdate . ' -1 days'));
|
|
|
$wdate = date('Y-m-d', strtotime($tdate . ' -7 days'));
|
|
|
- unset($params['reg_date']);
|
|
|
+ unset($params['tdate']);
|
|
|
$whereRaw = $this->getCommonWhereRaw($params);
|
|
|
$whereRaw .= " AND tdate IN ('{$tdate}','{$ldate}','{$wdate}')";
|
|
|
|
|
|
@@ -514,12 +498,12 @@ class AnalyseLogic extends BaseLogic
|
|
|
$params = $this->searchByAuth($where);
|
|
|
|
|
|
// 判断不能超过90天查询
|
|
|
- $days = getDateNum($where['reg_date'][0], $where['reg_date'][1]);
|
|
|
+ $days = getDateNum($where['tdate'][0], $where['tdate'][1]);
|
|
|
if ($days > 90) {
|
|
|
throw new ApiException('时间查询范围请勿超过90天');
|
|
|
}
|
|
|
$whereParams = $params;
|
|
|
- unset($whereParams['reg_date']);
|
|
|
+ unset($whereParams['tdate']);
|
|
|
$whereRaw = $this->getCommonWhereRaw($whereParams);
|
|
|
|
|
|
$whereRaw = str_replace('tdate', 'reg_date', $whereRaw);
|
|
|
@@ -530,45 +514,49 @@ class AnalyseLogic extends BaseLogic
|
|
|
SUBSTRING(reg_date,1,10) as dimension,
|
|
|
COUNT(DISTINCT uid) as pay_num
|
|
|
FROM sdk_order_success
|
|
|
- WHERE {$whereRaw} AND reg_date BETWEEN '{$params['reg_date'][0]} 00:00:00' AND '{$params['reg_date'][1]} 23:59:59'
|
|
|
+ WHERE {$whereRaw} AND reg_date BETWEEN '{$params['tdate'][0]} 00:00:00' AND '{$params['tdate'][1]} 23:59:59'
|
|
|
GROUP BY
|
|
|
dimension
|
|
|
");
|
|
|
+
|
|
|
$payDataMap = array_column($payData, null, 'dimension');
|
|
|
|
|
|
// 2. 计算留存付费的人数
|
|
|
$sqlArr = [];
|
|
|
- $medate = date("Y-m-d", strtotime("+ 60 day", strtotime($params['reg_date'][1])));
|
|
|
- $monthRange = getMonthRange($params['reg_date'][0], $medate);
|
|
|
+ $medate = date("Y-m-d", strtotime("+ 60 day", strtotime($params['tdate'][1])));
|
|
|
+ $monthRange = getMonthRange($params['tdate'][0], $medate);
|
|
|
+ $newMonth = date("Ym");
|
|
|
foreach ($monthRange as $month) {
|
|
|
+ if($month>$newMonth){
|
|
|
+ break;
|
|
|
+ }
|
|
|
$tableName = 'sdk_login_log_' . $month;
|
|
|
$sqlArr[] = "
|
|
|
- SELECT
|
|
|
- CONCAT(FROM_UNIXTIME(reg_time, '%Y-%m-%d'), '|', TIMESTAMPDIFF(DAY, FROM_UNIXTIME(reg_time), FROM_UNIXTIME(login_time))) AS dimension,
|
|
|
- FROM_UNIXTIME(reg_time, '%Y-%m-%d') AS reg_date,
|
|
|
- TIMESTAMPDIFF(DAY, FROM_UNIXTIME(reg_time), FROM_UNIXTIME(login_time)) AS day_num,
|
|
|
- COUNT(DISTINCT a.user_name) AS remain_num
|
|
|
- FROM {$tableName} AS a
|
|
|
- INNER JOIN (
|
|
|
- SELECT
|
|
|
- DISTINCT user_name
|
|
|
- FROM sdk_order_success
|
|
|
- WHERE 1=1
|
|
|
- {$whereRaw} AND reg_date BETWEEN '{$params['reg_date'][0]} 00:00:00' AND '{$params['reg_date'][1]} 23:59:59'
|
|
|
- ) AS b ON a.user_name = b.user_name
|
|
|
- WHERE 1=1
|
|
|
- {$whereRaw} AND reg_time BETWEEN " . strtotime($params['reg_date'][0] . " 00:00:00") . " AND " . strtotime($params['reg_date'][1] . " 23:59:59") . "
|
|
|
- GROUP BY dimension
|
|
|
- ";
|
|
|
+ SELECT
|
|
|
+ CONCAT(FROM_UNIXTIME(reg_time, '%Y-%m-%d'), '|', TIMESTAMPDIFF(DAY, FROM_UNIXTIME(reg_time), FROM_UNIXTIME(login_time))) AS dimension,
|
|
|
+ FROM_UNIXTIME(reg_time, '%Y-%m-%d') AS reg_date,
|
|
|
+ TIMESTAMPDIFF(DAY, FROM_UNIXTIME(reg_time), FROM_UNIXTIME(login_time)) AS day_num,
|
|
|
+ COUNT(DISTINCT a.user_name) AS remain_num
|
|
|
+ FROM {$tableName} AS a
|
|
|
+ INNER JOIN (
|
|
|
+ SELECT
|
|
|
+ DISTINCT user_name
|
|
|
+ FROM sdk_order_success
|
|
|
+ WHERE
|
|
|
+ {$whereRaw} AND reg_date BETWEEN '{$params['tdate'][0]} 00:00:00' AND '{$params['tdate'][1]} 23:59:59'
|
|
|
+ ) AS b ON a.user_name = b.user_name
|
|
|
+ WHERE
|
|
|
+ {$whereRaw} AND reg_time BETWEEN " . strtotime($params['tdate'][0] . " 00:00:00") . " AND " . strtotime($params['tdate'][1] . " 23:59:59") . "
|
|
|
+ GROUP BY dimension
|
|
|
+ ";
|
|
|
}
|
|
|
|
|
|
$sql = implode(" UNION ALL ", $sqlArr);
|
|
|
-
|
|
|
-
|
|
|
+ echo $sql . "\n";
|
|
|
$remainData = Db::connect('db_game_log')->query($sql);
|
|
|
$remainData = $remainData ? array_column($remainData, null, "dimension") : [];
|
|
|
|
|
|
- $regDateRange = getDateRange($params['reg_date'][0], $params['reg_date'][1]);
|
|
|
+ $regDateRange = getDateRange($params['tdate'][0], $params['tdate'][1]);
|
|
|
$remainRange = [];
|
|
|
for ($i = 2; $i <= 30; $i++) {
|
|
|
$remainRange[] = $i;
|
|
|
@@ -645,7 +633,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
";
|
|
|
|
|
|
// 获取对比日期1的数据, 注册、登录、充值
|
|
|
- $params['reg_date'] = $params['compare_date1'];
|
|
|
+ $params['tdate'] = $params['compare_date1'];
|
|
|
$whereRaw1 = $this->getCommonWhereRaw($params);
|
|
|
$yearRange = getYearRange($params['compare_date1'][0], $params['compare_date1'][1]);
|
|
|
$baseData1 = $this->generateUnionList('base_total_day', $yearRange, $whereRaw1, $field, 'tdate');
|
|
|
@@ -658,7 +646,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
|
|
|
|
|
|
// 获取对比日期2的数据, 注册、登录、充值
|
|
|
- $params['reg_date'] = $params['compare_date2'];
|
|
|
+ $params['tdate'] = $params['compare_date2'];
|
|
|
$whereRaw2 = $this->getCommonWhereRaw($params);
|
|
|
$yearRange = getYearRange($params['compare_date2'][0], $params['compare_date2'][1]);
|
|
|
$baseData2 = $this->generateUnionList('base_total_day', $yearRange, $whereRaw2, $field, 'tdate');
|
|
|
@@ -672,13 +660,13 @@ class AnalyseLogic extends BaseLogic
|
|
|
|
|
|
|
|
|
// 获取消耗数据1
|
|
|
- $params['reg_date'] = $params['compare_date1'];
|
|
|
+ $params['tdate'] = $params['compare_date1'];
|
|
|
$costWhereSql1 = $this->getCommonWhereRaw($params);
|
|
|
|
|
|
$costData1 = Db::connect('db_advert')->query("
|
|
|
SELECT SUM(money) as money, tdate
|
|
|
FROM media_cost
|
|
|
- WHERE 1=1 {$costWhereSql1}
|
|
|
+ WHERE {$costWhereSql1}
|
|
|
GROUP BY tdate
|
|
|
");
|
|
|
|
|
|
@@ -688,12 +676,12 @@ class AnalyseLogic extends BaseLogic
|
|
|
|
|
|
|
|
|
// 获取消耗数据2
|
|
|
- $params['reg_date'] = $params['compare_date2'];
|
|
|
+ $params['tdate'] = $params['compare_date2'];
|
|
|
$costWhereSql2 = $this->getCommonWhereRaw($params);
|
|
|
$costData2 = Db::connect('db_advert')->query("
|
|
|
SELECT SUM(money) as money, tdate
|
|
|
FROM media_cost
|
|
|
- WHERE 1=1 {$costWhereSql2}
|
|
|
+ WHERE {$costWhereSql2}
|
|
|
GROUP BY tdate
|
|
|
");
|
|
|
|
|
|
@@ -727,7 +715,6 @@ class AnalyseLogic extends BaseLogic
|
|
|
}
|
|
|
|
|
|
// 格式化x轴的时间
|
|
|
- $forData = [];
|
|
|
$days1 = [];
|
|
|
$days2 = [];
|
|
|
if (count($data1['days']) > count($data2['days'])) {
|
|
|
@@ -774,7 +761,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
";
|
|
|
|
|
|
// 获取对比日期1的数据, 注册、登录、充值
|
|
|
- $params['reg_date'] = $params['compare_date1_date'];
|
|
|
+ $params['tdate'] = $params['compare_date1_date'];
|
|
|
$whereRaw1 = $this->getCommonWhereRaw($params);
|
|
|
$monthRange = getMonthRange($params['compare_date1'][0], $params['compare_date1'][1]);
|
|
|
$baseData1 = $this->generateUnionList('base_total_hour', $monthRange, $whereRaw1, $field, 'thour');
|
|
|
@@ -787,7 +774,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
}
|
|
|
|
|
|
// 获取对比日期2的数据, 注册、登录、充值
|
|
|
- $params['reg_date'] = $params['compare_date2_date'];
|
|
|
+ $params['tdate'] = $params['compare_date2_date'];
|
|
|
$whereRaw2 = $this->getCommonWhereRaw($params);
|
|
|
$monthRange2 = getMonthRange($params['compare_date2'][0], $params['compare_date2'][1]);
|
|
|
$baseData2 = $this->generateUnionList('base_total_hour', $monthRange2, $whereRaw2, $field, 'thour');
|