|
|
@@ -234,16 +234,42 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- // 渠道总览
|
|
|
+ /**
|
|
|
+ * @param $where
|
|
|
+ * @return mixed
|
|
|
+ * @description 渠道总览
|
|
|
+ * 支出-> media_cost表的消耗数据
|
|
|
+ * 激活(install)、注册设备(reg_dev)、注册数(reg_total)、创角数(role_create_user) -> base_total_day_2025表的数据
|
|
|
+ * 注册成本-> 支出/注册数
|
|
|
+ * 创角率 -> 创角数/注册数
|
|
|
+ * 次留数 -> reg_date, days:1, active_total, game_active_day_2025
|
|
|
+ * 次留率 -> 次留数 / reg_login_total
|
|
|
+ * 次留成本 -> 支出 / 第二天的 ld_login_total
|
|
|
+ * 当天付费金额 -> reg_pay_total
|
|
|
+ * 总付费人数 -> pay_num
|
|
|
+ * 总付费金额 -> pay_total
|
|
|
+ * 付费率 -> 总付费人数 / 注册数
|
|
|
+ * 当天回本率 -> 当天付费 / 支出
|
|
|
+ * 累计回本率 -> 总付费 / 支出
|
|
|
+ * 实际回本率 -> game_reg_pay_day_2025表的 addup_pay_amount / 支出
|
|
|
+ * 7天实际回本率 -> game_reg_pay_day_2025表的 sum(addup_pay_amount) 根据注册时间 +6day, 遍历相加 / 支出
|
|
|
+ * 付费成本 -> 总付费人数 / 支出
|
|
|
+ * ARPU -> 付费总金额/ 付费总用户
|
|
|
+ * 注册ARPU -> 注册付费金额/注册数
|
|
|
+ * 老用户数 -> sum(old_login_total)
|
|
|
+ * 负责人 -> 渠道负责人, 根据
|
|
|
+ */
|
|
|
public function getAgentDataList($where){
|
|
|
$params = $this->searchByAuth($where);
|
|
|
+ // 忽略0投入
|
|
|
+ $igz = !empty($params['filter']) ? $params['filter'].include('igz'):false;
|
|
|
|
|
|
- $filter = $params['filter'];
|
|
|
- $group = $params['group'];
|
|
|
- $type = '';
|
|
|
+// $filter = !empty($params['filter']) ? $params['filter'] : '';
|
|
|
+ $group = !empty($params['group']) ?$params['group']:'';
|
|
|
|
|
|
- // 如果分组按照 游戏ID||游戏组
|
|
|
- if($group===1 || $group==4){
|
|
|
+
|
|
|
+ // 如果分组按照 游戏组ID||游戏组
|
|
|
+ if($group==1 || $group==4){
|
|
|
$type = 'game_id';
|
|
|
}else{
|
|
|
$type = 'agent_id';
|
|
|
@@ -251,19 +277,188 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
|
|
|
$whereSql = $this->generateWhereSql($params);
|
|
|
|
|
|
- // 1.
|
|
|
|
|
|
+ // 1.查询消耗数据, 安game_id/agent_id分组
|
|
|
+ $costSql = "select {$type}, sum(money) as cost from media_cost WHERE 1=1 {$whereSql} group by {$type}";
|
|
|
+ $costData = Db::connect('db_advert')->query($costSql);
|
|
|
+ $costDataColumn = array_column($costData, 'cost', $type);
|
|
|
+
|
|
|
+ // 2.查询按日统计数据
|
|
|
+ $totalDayField = "
|
|
|
+ {$type},
|
|
|
+ sum(install) as install,
|
|
|
+ sum(reg_pay_total) as reg_pay_total_da,
|
|
|
+ sum(reg_dev) as reg_dev,
|
|
|
+ sum(reg_total) as reg_total,
|
|
|
+ sum(login_total) as login_total,
|
|
|
+ sum(old_login_total) as old_login_total,
|
|
|
+ sum(role_create_user) as role_total,
|
|
|
+ sum(pay_num) as pay_num_total
|
|
|
+ ";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 2. 获取基础报表数据,兼容跨年
|
|
|
+ $baseData = $this->generateYearUnionList('base_total_day_',$params['reg_date'], $whereSql, $totalDayField, $type);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 3. 获取活跃数
|
|
|
+ $activeWhereSql = $whereSql.' AND days = 1';
|
|
|
+ $activeWhereSql = str_replace('AND tdate','AND reg_date',$activeWhereSql);
|
|
|
+ $activeField = "
|
|
|
+ sum(active_total) as active,
|
|
|
+ game_id,
|
|
|
+ agent_id";
|
|
|
+ $activeData = $this->generateYearUnionList('game_active_day_', $params['reg_date'], $activeWhereSql, $activeField, $type);
|
|
|
+
|
|
|
+
|
|
|
+ // 4. 注册充值统计
|
|
|
+ $regPayWhereSql = $whereSql;
|
|
|
+ $regPayField = "
|
|
|
+ sum(addup_pay_num) as reg_pay_num,
|
|
|
+ sum(addup_pay_total) as reg_pay_total,
|
|
|
+ sum(addup_pay_amount) as reg_pay_amount,
|
|
|
+ {$type}";
|
|
|
+ $regPayWhereSql = str_replace('AND tdate','AND reg_date',$regPayWhereSql);
|
|
|
+
|
|
|
+ $regPayData = $this->generateYearUnionList('game_reg_pay_day_', $params['reg_date'], $regPayWhereSql, $regPayField, $type);
|
|
|
+
|
|
|
+
|
|
|
+ // 5. 7天回本
|
|
|
+ $hb7dayData = $this->computedHb7days($params,$type);
|
|
|
+ $hb7dayData = array_column($hb7dayData, 'reg_pay_amount_7', $type);
|
|
|
+
|
|
|
+ echo '$hb7dayData';
|
|
|
+ print_r($hb7dayData);
|
|
|
+ if(empty($baseData)||!empty($baseData[0]['game_id'])){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 拼接总数据
|
|
|
+ foreach($baseData as &$row){
|
|
|
+ $typeId = $row[$type]; // type, 的取值, 这里根据分组, game_id | agent_id
|
|
|
+ $cost = $costDataColumn[$typeId];
|
|
|
+
|
|
|
+ $row['cost'] = $cost;
|
|
|
+ // 注册成本
|
|
|
+ $row['reg_cost'] = ToolLogic::getRound($cost,$row['reg_total'] ?? 0);
|
|
|
+ // 创角率
|
|
|
+ $row['role_per'] = ToolLogic::getRound($row['role_total'],$row['reg_total'] ?? 0);
|
|
|
+ // 次留数
|
|
|
+ $row['active'] = $activeData[$typeId]['active'] ?? 0;
|
|
|
+ // 次留率
|
|
|
+ $row['a_per'] = ToolLogic::getPercent( $activeData[$typeId]['active']??0,$row['reg_total'],1);
|
|
|
+ // 次留成本
|
|
|
+ $row['a_cost'] = ToolLogic::getRound($cost,$row['active'],1);
|
|
|
+
|
|
|
+ // 总付费金额
|
|
|
+ $row['reg_pay_total'] = $regPayData[$typeId]['reg_pay_total'] ?? 0;
|
|
|
+
|
|
|
+ // 总付费人数
|
|
|
+ $row['reg_pay_num'] = $regPayData[$typeId]['reg_pay_num'] ?? 0;
|
|
|
+
|
|
|
+ //付费成本
|
|
|
+ $row['p_cost'] = ToolLogic::getRound($row['cost'],$row['reg_pay_num']);
|
|
|
+
|
|
|
+ // 付费率
|
|
|
+ $row['p_per'] = ToolLogic::getPercent($row['reg_pay_num']??0,$row['reg_total'],1);
|
|
|
+
|
|
|
+ // 当天回本率
|
|
|
+ $row['da_per'] = ToolLogic::getPercent($row['reg_pay_total_da']??0,$row['cost'],1);
|
|
|
+
|
|
|
+ // 累计回本率
|
|
|
+ $row['re_per'] = (float)trim(ToolLogic::getPercent($row['reg_pay_total'],$row['cost']), "%");
|
|
|
+
|
|
|
+ // 实际回本率
|
|
|
+ $row['re_amount_per'] = ToolLogic::getPercent($row['reg_pay_amount']??0,$row['cost'],1);
|
|
|
|
|
|
+ //ARPU
|
|
|
+ $row['arpu'] = ToolLogic::getRound($row['reg_pay_total'],$row['reg_pay_num']);
|
|
|
+
|
|
|
+ //注册ARPU
|
|
|
+ $row['r_arpu'] = ToolLogic::getRound($row['reg_pay_total'],$row['reg_total']);
|
|
|
+
|
|
|
+ // 7天回本率
|
|
|
+ $row['re_amount_per_7'] = ToolLogic::getPercent($row['re_amount_per_7']??0,$row['cost'],1);
|
|
|
+
|
|
|
+ }
|
|
|
+ return $baseData;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $where
|
|
|
+ * @param $group
|
|
|
+ * @return void
|
|
|
+ * @description 计算7天回本率
|
|
|
+ * 1. 7天的注册总充值计算出来,可以通过
|
|
|
+ */
|
|
|
+ public function computedHb7days($where, $type){
|
|
|
+ $payDataAll = [];
|
|
|
+ $dateRange = ToolLogic::getDatesBetween($where['reg_date'][0], $where['reg_date'][1]);
|
|
|
+ foreach ($dateRange as $regDate){
|
|
|
+
|
|
|
+ $field = "
|
|
|
+ sum(addup_pay_amount) as reg_pay_amount_7,
|
|
|
+ $type"; // 注册总充值
|
|
|
+ $eDate = date("Y-m-d", strtotime($regDate . " +6 days"));
|
|
|
+ // 如果7天后的时间,超过今天,则今天是最后一天
|
|
|
+ if($eDate>date("Y-m-d")){
|
|
|
+ $eDate = date("Y-m-d");
|
|
|
+ }
|
|
|
+
|
|
|
+ $wherePay = $where;
|
|
|
+ unset($wherePay['reg_date']);
|
|
|
+
|
|
|
+ $whereSql = $this->generateWhereSql($wherePay);
|
|
|
+ $whereSql = "{$whereSql} AND reg_date = '{$regDate}' AND pay_date = '{$eDate}'";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $payData = $this->generateYearUnionList('game_reg_pay_day_',
|
|
|
+ [
|
|
|
+ $regDate,
|
|
|
+ $regDate
|
|
|
+ ]
|
|
|
+ , $whereSql, $field, $type);
|
|
|
+
|
|
|
+ $payDataAll = array_merge($payDataAll, $payData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $payDataAll;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 生成基础日统计表的联合查询列表
|
|
|
+ public function generateYearUnionList($namePrefix, $regDate,$whereSql='',$field='*',$group=null){
|
|
|
+
|
|
|
+ $tableNames = ToolLogic::getYearlyTableNames($namePrefix, $regDate[0],$regDate[1]);
|
|
|
+ $sqlParts = [];
|
|
|
+ foreach ($tableNames as $tableName){
|
|
|
+ $sqlParts[] = "SELECT * FROM {$tableName} WHERE 1=1 {$whereSql}";
|
|
|
+ }
|
|
|
+ $unionSql = implode(" UNION ALL ", $sqlParts);
|
|
|
+ $finalSql = "
|
|
|
+ SELECT {$field} FROM ( {$unionSql} ) AS all_total_day
|
|
|
+ ";
|
|
|
+ if (!empty($group)) {
|
|
|
+ $finalSql .= " GROUP BY {$group}";
|
|
|
+ }
|
|
|
+echo $finalSql;
|
|
|
+ $baseData = Db::connect('db_data_report')->query($finalSql);
|
|
|
+ return $baseData;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// 生成wheresql
|
|
|
public function generateWhereSql($params){
|
|
|
- $startDate = $params['reg_date'][0];
|
|
|
- $endDate = $params['reg_date'][1];
|
|
|
+
|
|
|
$whereSql = "";
|
|
|
+ // 游戏id
|
|
|
if(!empty($params['game_id'])){
|
|
|
if (is_array($params['game_id'])) {
|
|
|
$whereSql .= " AND game_id IN(" . implode(',', $params['game_id']) . ")";
|
|
|
@@ -271,12 +466,15 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
$whereSql .= " AND game_id = {$params['game_id']}";
|
|
|
}
|
|
|
}
|
|
|
+ // 媒体id
|
|
|
if(!empty($params['media_id'])){
|
|
|
$whereSql .= " AND media_id = {$params['media_id']}";
|
|
|
}
|
|
|
+ // 渠道id
|
|
|
if(!empty($params['agent_id'])){
|
|
|
$whereSql .= " AND agent_id = {$params['agent_id']}";
|
|
|
}
|
|
|
+ // 广告位id
|
|
|
if(!empty($params['site_id'])){
|
|
|
if (is_array($params['site_id'])) {
|
|
|
$whereSql .= " AND site_id IN(" . implode(',', $params['site_id']) . ")";
|
|
|
@@ -293,8 +491,15 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
}
|
|
|
}
|
|
|
// 注册日期
|
|
|
- if(!empty($params['reg_date'])){
|
|
|
- $whereSql .= " AND tdate BETWEEN '{$startDate}' AND '{$endDate}'";
|
|
|
+ if(!empty($params['reg_date'])??null){
|
|
|
+ $whereSql .= " AND tdate BETWEEN '{$params['reg_date'][0]}' AND '{$params['reg_date'][1]}'";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 忽略后台录入
|
|
|
+ if(!empty($params['filter'])){
|
|
|
+ if(is_array($params['filter'] && $params['filter'].include('fak'))){
|
|
|
+ $whereSql .= " AND add_type = 0";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $whereSql;
|