|
|
@@ -122,6 +122,89 @@ class AnalyseLogic extends BaseLogic
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+ // 留存按日
|
|
|
+ public function getRetentionDayDataList($where){
|
|
|
+ $params = $this->searchByAuth($where);
|
|
|
+ // 构建whereSql
|
|
|
+ $whereSql = '';
|
|
|
+ if(!empty($params['game_id'])){
|
|
|
+ $whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
|
|
|
+ }
|
|
|
+ if(!empty($params['reg_date'])){
|
|
|
+ $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
|
|
|
+ }
|
|
|
+
|
|
|
+ $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";
|
|
|
+
|
|
|
+ // 1. 查询每天的注册数,根据注册时间,游戏
|
|
|
+ $baseData = $this->generateYearUnionList('base_total_day_',$params['reg_date'],$whereSql,$baseField,'game_id,tdate');
|
|
|
+ $baseData = array_column($baseData,null,'tdate');
|
|
|
+
|
|
|
+
|
|
|
+ // 2. 查询每天的活跃数,根据注册时间,游戏,留存天数
|
|
|
+ $activeWhereSql = str_replace("AND tdate", "AND reg_date", $whereSql);
|
|
|
+ if(!empty($params['days'])){
|
|
|
+ $activeWhereSql .= " AND days = {$params['days']}";
|
|
|
+ }
|
|
|
+
|
|
|
+ $activeData = $this->generateYearUnionList('game_active_day_',$params['reg_date'],$activeWhereSql,$activeField,'game_id,reg_date');
|
|
|
+ $activeData = array_column($activeData,null,'reg_date');
|
|
|
+
|
|
|
+ foreach($baseData as $row){
|
|
|
+ $game_id = $row['game_id'];
|
|
|
+ $tdate = $row['tdate'];
|
|
|
+ $data[$game_id][$tdate]['reg_total'] = $row['reg_total'];
|
|
|
+ $data[$game_id][$tdate]['active_total'] = !empty($activeData[$tdate]['active_total']) ? $activeData[$tdate]['active_total'] : 0;
|
|
|
+ $data[$game_id][$tdate]['retention_total'] = ToolLogic::getPercent($data[$game_id][$tdate]['active_total'],$data[$game_id][$tdate]['reg_total']);
|
|
|
+ // 每日合计
|
|
|
+ $data[$game_id]['total_reg_total'] = !empty($data[$game_id]['total_reg_total']) ? $data[$game_id]['total_reg_total'] + $data[$game_id][$tdate]['reg_total'] : $data[$game_id][$tdate]['reg_total'];
|
|
|
+ $data[$game_id]['total_active_total'] = !empty($data[$game_id]['total_active_total']) ? $data[$game_id]['total_active_total'] + $data[$game_id][$tdate]['active_total'] : $data[$game_id][$tdate]['active_total'];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 底部合计
|
|
|
+ $totalRow['total_reg_total'] = !empty($totalRow['total_reg_total']) ? $totalRow['total_reg_total'] + $data[$game_id][$tdate]['reg_total'] : $data[$game_id][$tdate]['reg_total'];
|
|
|
+ $totalRow['total_active_total'] = !empty($totalRow['total_active_total']) ? $totalRow['total_active_total'] + $data[$game_id][$tdate]['active_total'] : $data[$game_id][$tdate]['active_total'];
|
|
|
+
|
|
|
+ $totalRow[$tdate]['reg_total'] = !empty($totalRow[$tdate]['reg_total']) ? $totalRow[$tdate]['reg_total'] + $data[$game_id][$tdate]['reg_total'] : $data[$game_id][$tdate]['reg_total'];
|
|
|
+ $totalRow[$tdate]['active_total'] = !empty($totalRow[$tdate]['active_total']) ? $totalRow[$tdate]['active_total'] + $data[$game_id][$tdate]['active_total'] : $data[$game_id][$tdate]['active_total'];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = array_values($data);
|
|
|
+ foreach($data as &$row){
|
|
|
+ foreach($row as $key => $value){
|
|
|
+ if($key == 'total_reg_total' || $key == 'game_id'){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if($key == 'total_active_total'){
|
|
|
+ $row['total'] = ToolLogic::getPercent($row['total_active_total'],$row['total_reg_total']);
|
|
|
+ }else{
|
|
|
+ $row[$key] = ToolLogic::getPercent($value['active_total'],$value['reg_total']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($totalRow as $totalKey => &$row){
|
|
|
+ if($totalKey == 'game_id' || $totalKey == 'total_active_total'||$totalKey == 'total_reg_total'){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $totalRow[$totalKey] = ToolLogic::getPercent($row['active_total'],$row['reg_total']);
|
|
|
+
|
|
|
+ }
|
|
|
+ $totalRow['total'] = ToolLogic::getPercent($totalRow['total_active_total'],$totalRow['total_reg_total']);
|
|
|
+
|
|
|
+
|
|
|
+ $result['data'] = $data;
|
|
|
+ $result['totalRow'] = $totalRow;
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -140,6 +223,7 @@ class AnalyseLogic extends BaseLogic
|
|
|
if (!empty($group)) {
|
|
|
$finalSql .= " GROUP BY {$group}";
|
|
|
}
|
|
|
+
|
|
|
$baseData = Db::connect('db_data_report')->query($finalSql);
|
|
|
return $baseData;
|
|
|
}
|