|
|
@@ -261,17 +261,23 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
*/
|
|
|
public function getAgentDataList($where){
|
|
|
$params = $this->searchByAuth($where);
|
|
|
- // 忽略0投入
|
|
|
- $igz = !empty($params['filter']) ? $params['filter'].include('igz'):false;
|
|
|
|
|
|
-// $filter = !empty($params['filter']) ? $params['filter'] : '';
|
|
|
+ // 忽略 0 投入
|
|
|
+ $igz = !empty($params['filter']) && is_array($params['filter']) && in_array('igz',$params['filter']);
|
|
|
+
|
|
|
+
|
|
|
$group = !empty($params['group']) ?$params['group']:'';
|
|
|
|
|
|
|
|
|
// 如果分组按照 游戏组ID||游戏组
|
|
|
- if($group==1 || $group==4){
|
|
|
+ if($group==1 ){
|
|
|
$type = 'game_id';
|
|
|
- }else{
|
|
|
+ }else if($group==2){
|
|
|
+ $type = 'auth_id';
|
|
|
+ }else if($group==3){
|
|
|
+ $type = 'media_id';
|
|
|
+ }
|
|
|
+ else{
|
|
|
$type = 'agent_id';
|
|
|
}
|
|
|
|
|
|
@@ -279,7 +285,13 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
|
|
|
|
|
|
// 1.查询消耗数据, 安game_id/agent_id分组
|
|
|
- $costSql = "select {$type}, sum(money) as cost from media_cost WHERE 1=1 {$whereSql} group by {$type}";
|
|
|
+ // 忽略后台录入的消耗
|
|
|
+ $costWhereSql = $whereSql;
|
|
|
+ if( !empty($params['filter']) && is_array($params['filter']) && in_array('fak',$params['filter'])){
|
|
|
+ $costWhereSql .= " AND add_type = 0";
|
|
|
+ }
|
|
|
+ $costSql = "SELECT {$type}, SUM(money) as cost from media_cost WHERE 1=1 {$costWhereSql} GROUP BY {$type}";
|
|
|
+
|
|
|
$costData = Db::connect('db_advert')->query($costSql);
|
|
|
$costDataColumn = array_column($costData, 'cost', $type);
|
|
|
|
|
|
@@ -293,12 +305,11 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
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
|
|
|
+ sum(pay_num) as pay_num_total,
|
|
|
+ auth_id,
|
|
|
+ media_id
|
|
|
";
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 2. 获取基础报表数据,兼容跨年
|
|
|
$baseData = $this->generateYearUnionList('base_total_day_',$params['reg_date'], $whereSql, $totalDayField, $type);
|
|
|
|
|
|
@@ -312,6 +323,7 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
game_id,
|
|
|
agent_id";
|
|
|
$activeData = $this->generateYearUnionList('game_active_day_', $params['reg_date'], $activeWhereSql, $activeField, $type);
|
|
|
+ $activeData = array_column($activeData, 'active', $type);
|
|
|
|
|
|
|
|
|
// 4. 注册充值统计
|
|
|
@@ -324,26 +336,49 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
$regPayWhereSql = str_replace('AND tdate','AND reg_date',$regPayWhereSql);
|
|
|
|
|
|
$regPayData = $this->generateYearUnionList('game_reg_pay_day_', $params['reg_date'], $regPayWhereSql, $regPayField, $type);
|
|
|
+ $regPayData = array_column($regPayData, null, $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'])){
|
|
|
+ $hb7dayDataSum = 0;
|
|
|
+ foreach($hb7dayData as $row){
|
|
|
+ $hb7dayDataSum += $row;
|
|
|
+ }
|
|
|
+ if(empty($baseData)){
|
|
|
return [];
|
|
|
}
|
|
|
|
|
|
+ // 6. 所有游戏信息
|
|
|
+ $gameData = Db::connect('db_center')->table('pf_game')->select()->toArray();
|
|
|
|
|
|
+ // 7. 所有用户信息
|
|
|
+ $authData = Db::connect('db_system')->table('sa_system_user')->select()->toArray();
|
|
|
|
|
|
- // 拼接总数据
|
|
|
- foreach($baseData as &$row){
|
|
|
- $typeId = $row[$type]; // type, 的取值, 这里根据分组, game_id | agent_id
|
|
|
- $cost = $costDataColumn[$typeId];
|
|
|
+ // 8. 媒体列表信息
|
|
|
+ $mediaData = Db::connect('db_advert')->table('media_list')->select()->toArray();
|
|
|
+
|
|
|
+ // 9. 渠道列表信息
|
|
|
+ $agentData = Db::connect('db_advert')->table('agent_list')->select()->toArray();
|
|
|
+
|
|
|
+ $gameData = array_column($gameData, null, 'id');
|
|
|
+ $authData = array_column($authData, null, 'id');
|
|
|
+ $mediaData = array_column($mediaData, null, 'id');
|
|
|
+
|
|
|
+
|
|
|
+ // 拼接数据
|
|
|
+ foreach($baseData as $key => &$row){
|
|
|
|
|
|
+ $typeId = $row[$type]; // type, 的取值, 这里根据分组, game_id | agent_id
|
|
|
+ $cost = $costDataColumn[$typeId]??0;
|
|
|
$row['cost'] = $cost;
|
|
|
+ // 忽略0投入的
|
|
|
+ if($igz && $row['cost']===0){
|
|
|
+ unset($baseData[$key]);
|
|
|
+ }
|
|
|
+
|
|
|
// 注册成本
|
|
|
$row['reg_cost'] = ToolLogic::getRound($cost,$row['reg_total'] ?? 0);
|
|
|
// 创角率
|
|
|
@@ -373,8 +408,10 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
// 累计回本率
|
|
|
$row['re_per'] = (float)trim(ToolLogic::getPercent($row['reg_pay_total'],$row['cost']), "%");
|
|
|
|
|
|
+ $row['reg_pay_amount']= $hb7dayData[$typeId]['reg_pay_amount'] ?? 0;
|
|
|
+
|
|
|
// 实际回本率
|
|
|
- $row['re_amount_per'] = ToolLogic::getPercent($row['reg_pay_amount']??0,$row['cost'],1);
|
|
|
+ $row['re_amount_per'] = ToolLogic::getPercent($row['reg_pay_amount'],$row['cost'],1);
|
|
|
|
|
|
//ARPU
|
|
|
$row['arpu'] = ToolLogic::getRound($row['reg_pay_total'],$row['reg_pay_num']);
|
|
|
@@ -383,10 +420,181 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
$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);
|
|
|
+ $row['re_amount_per_7'] = ToolLogic::getPercent($hb7dayData[$typeId]??0,$row['cost'],1);
|
|
|
+
|
|
|
+
|
|
|
+ // 按分组信息展示,id和name
|
|
|
+ switch ($params['group']??''){
|
|
|
+ case 1:
|
|
|
+ $row['akey'] = $row['game_id'];
|
|
|
+ $row['name'] = $gameData[$row['game_id']]['name'];
|
|
|
+ $row['auth_name'] = '-';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 2:
|
|
|
+ $row['akey'] = $row['auth_id'];
|
|
|
+ $row['name'] = '-';
|
|
|
+ $row['auth_name'] = $authData[$row['auth_id']]['username'];
|
|
|
+
|
|
|
+ case 3:
|
|
|
+ $row['akey'] = $row['media_id'];
|
|
|
+ $row['name'] = $mediaData[$row['media_id']]['name'];
|
|
|
+ $row['auth_name'] = $authData[$row['auth_id']]['username'];
|
|
|
+
|
|
|
+ default:
|
|
|
+ $row['akey'] = $row['agent_id'];
|
|
|
+ $row['name'] = $agentData[$row['agent_id']]['name'];
|
|
|
+ $row['auth_name'] = '-';
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- return $baseData;
|
|
|
+
|
|
|
+
|
|
|
+ // 底部合计
|
|
|
+ $total=[
|
|
|
+ 'akey'=>'合计'
|
|
|
+ ];
|
|
|
+ foreach($baseData as &$row){
|
|
|
+ $total['cost'] = !empty($total['cost']) ? ($total['cost'] + $row['cost']) : $row['cost'];
|
|
|
+
|
|
|
+ // 激活
|
|
|
+ $total['install'] =!empty($total['install']) ? ($total['install'] + $row['install']) : $row['install'];
|
|
|
+
|
|
|
+ // 注册设备
|
|
|
+ $total['reg_dev'] =!empty($total['reg_dev']) ? ($total['reg_dev'] + $row['reg_dev']) : $row['reg_dev'];
|
|
|
+
|
|
|
+ // 注册数
|
|
|
+ $total['reg_total'] = !empty($total['reg_total']) ? ($total['reg_total'] + $row['reg_total']) : $row['reg_total'];
|
|
|
+
|
|
|
+ // 创角数
|
|
|
+ $total['role_total'] =!empty($total['role_total']) ? ($total['role_total'] + $row['role_total']) : $row['role_total'];
|
|
|
+ // 创角率
|
|
|
+
|
|
|
+ // 次留数
|
|
|
+ $total['active'] =!empty($total['active']) ? ($total['active'] + $row['active']) : $row['active'];
|
|
|
+ // 次留成本
|
|
|
+ // 次留率
|
|
|
+
|
|
|
+ // 当天付费
|
|
|
+ $total['reg_pay_total_da'] =!empty($total['reg_pay_total_da']) ? ($total['reg_pay_total_da'] + $row['reg_pay_total_da']) : $row['reg_pay_total_da'];
|
|
|
+
|
|
|
+ // 总付费人数
|
|
|
+ $total['reg_pay_num'] = !empty($total['reg_pay_num']) ? ($total['reg_pay_num'] + $row['reg_pay_num']) : $row['reg_pay_num'];
|
|
|
+
|
|
|
+ // 总付费金额
|
|
|
+ $total['reg_pay_total'] = !empty($total['reg_pay_total']) ? ($total['reg_pay_total'] + $row['reg_pay_total']) : $row['reg_pay_total'];
|
|
|
+
|
|
|
+ // 老用户
|
|
|
+ $total['old_login_total'] = !empty($total['old_login_total']) ? ($total['old_login_total'] + $row['old_login_total']) : $row['old_login_total'];
|
|
|
+
|
|
|
+ //注册总充值
|
|
|
+ $total['reg_pay_amount'] = !empty($total['reg_pay_amount']) ? ($total['reg_pay_amount'] + $row['reg_pay_amount']) : $row['reg_pay_amount'];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 注册成本
|
|
|
+ $total['reg_cost'] = ToolLogic::getRound($total['cost'],$total['reg_total'] ?? 0);
|
|
|
+
|
|
|
+ // 汇总创角率
|
|
|
+ $total['role_per'] = ToolLogic::getRound($total['role_total'],$total['reg_total'] ?? 0);
|
|
|
+
|
|
|
+ // 次留率
|
|
|
+ $total['a_per'] = ToolLogic::getPercent( $total['active'],$total['reg_total'],1);
|
|
|
+ // 次留成本
|
|
|
+ $total['a_cost'] = ToolLogic::getRound($total['cost'],$total['active'],1);
|
|
|
+
|
|
|
+ // 付费率
|
|
|
+ $total['p_per'] = ToolLogic::getPercent($total['reg_pay_num'],$total['reg_total'],1);
|
|
|
+
|
|
|
+ // 当天回本率
|
|
|
+ $total['da_per'] = ToolLogic::getPercent($total['reg_pay_total_da'],$total['cost'],1);
|
|
|
+
|
|
|
+ // 累计回本率
|
|
|
+ $total['re_per'] = (float)trim(ToolLogic::getPercent($total['reg_pay_total'],$total['cost']), "%");
|
|
|
+
|
|
|
+ // 实际回本率
|
|
|
+ $total['re_amount_per'] = ToolLogic::getPercent($total['reg_pay_amount'],$total['cost'],1);
|
|
|
+
|
|
|
+ //ARPU
|
|
|
+ $total['arpu'] = ToolLogic::getRound($total['reg_pay_total'],$total['reg_pay_num']);
|
|
|
+
|
|
|
+ //注册ARPU
|
|
|
+ $total['r_arpu'] = ToolLogic::getRound($total['reg_pay_total'],$total['reg_total']);
|
|
|
+
|
|
|
+ // 7天回本率
|
|
|
+
|
|
|
+ $total['re_amount_per_7'] = ToolLogic::getPercent($hb7dayDataSum,$total['cost'],1);
|
|
|
+
|
|
|
+ //付费成本
|
|
|
+ $total['p_cost'] = ToolLogic::getRound($total['reg_pay_num'],$total['cost'],1);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $totalData = $this->agentTotal($where);
|
|
|
+
|
|
|
+ // 汇总数据
|
|
|
+ return [
|
|
|
+ 'data' => array_merge($baseData,[$total]),
|
|
|
+ 'totalData' => $totalData
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ * 大盘数据(没有权限)
|
|
|
+ * 注册成本:消耗金额/注册数
|
|
|
+ * roi:注册付费金额 reg_pay_total /消耗 cost
|
|
|
+ * 付费成本:总付费人数/消耗
|
|
|
+ * 付费率:总付费人数/注册数
|
|
|
+ */
|
|
|
+ public function agentTotal($where){
|
|
|
+ $whereSql = $this->generateWhereSql($where);
|
|
|
+ $cost = 0; // 消耗金额
|
|
|
+ $regTotal = 0; // 注册数
|
|
|
+ $regPayTotal = 0; // 注册付费金额
|
|
|
+ $regPayNum = 0; // 总付费人数
|
|
|
+ // 1. 消耗表. 获取消耗金额
|
|
|
+ $costData = Db::connect('db_advert')->query("SELECT SUM(money) as cost FROM media_cost WHERE 1=1 $whereSql");
|
|
|
+ $cost = $costData[0]['cost'] ?? 0;
|
|
|
+
|
|
|
+ // 2. base_total_day_ 获取注册数(reg_total)、注册付费金额(reg_pay_total)、
|
|
|
+ $baseTotalField = "
|
|
|
+ SUM(reg_total) AS reg_total,
|
|
|
+ SUM(reg_pay_total) AS reg_pay_total";
|
|
|
+ $baseTotalDayData = $this->generateYearUnionList('base_total_day_', $where['reg_date'], $whereSql, $baseTotalField);
|
|
|
+
|
|
|
+ $regTotal = $baseTotalDayData[0]['reg_total'] ?? 0;
|
|
|
+ $regPayTotal = $baseTotalDayData[0]['reg_pay_total'] ?? 0;
|
|
|
+
|
|
|
+ // 3. 注册付费表. 获取总付费人数(reg_pay_num)
|
|
|
+ $regPayField = "
|
|
|
+ sum(addup_pay_num) as reg_pay_num";
|
|
|
+ $regPayWhereSql = str_replace('AND tdate','AND reg_date',$whereSql);
|
|
|
+ $regPayData = $this->generateYearUnionList('game_reg_pay_day_', $where['reg_date'], $regPayWhereSql, $regPayField);
|
|
|
+ $regPayNum = $regPayData[0]['reg_pay_num'] ?? 0;
|
|
|
+
|
|
|
+ // roi
|
|
|
+ $roi = ToolLogic::getPercent($regPayTotal,$cost,1);
|
|
|
+
|
|
|
+ // 付费成本
|
|
|
+ $pCost = ToolLogic::getRound($cost,$regPayNum);
|
|
|
+
|
|
|
+ // reg_cost 注册成本
|
|
|
+ $regCost = ToolLogic::getRound($cost,$regTotal);
|
|
|
+
|
|
|
+ // 付费率
|
|
|
+ $pPer = ToolLogic::getPercent($regPayNum,$regTotal,1);
|
|
|
+
|
|
|
+ // 返回数据
|
|
|
+ return [
|
|
|
+ 'reg_cost' => $regCost,
|
|
|
+ 'roi' => $roi,
|
|
|
+ 'p_cost' => $pCost,
|
|
|
+ 'p_per' => $pPer,
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -448,7 +656,6 @@ class channelAnalysisLogic extends BaseLogic
|
|
|
if (!empty($group)) {
|
|
|
$finalSql .= " GROUP BY {$group}";
|
|
|
}
|
|
|
-echo $finalSql;
|
|
|
$baseData = Db::connect('db_data_report')->query($finalSql);
|
|
|
return $baseData;
|
|
|
}
|
|
|
@@ -495,13 +702,6 @@ echo $finalSql;
|
|
|
$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;
|
|
|
}
|
|
|
|