计算ARPU

master
ELF 5 years ago
parent 490d52395f
commit 144e4e4ea7

@ -428,4 +428,111 @@ class ConsoleController extends Think {
}
}
public function arpu()
{
$start = I('start', date('Y-m-d'));
$end = I('end', date('Y-m-d'));
$gameIds = I('game_ids', '');
$startTime = strtotime($start . ' 00:00:00');
$endTime = strtotime($end . ' 23:59:59');
$gameIdRows = explode(',', $gameIds);
// 新增用户
/* M('user', 'tab_')
->field('count(*) count, FROM_UNIXTIME(register_time, "%Y-%m-%d") date')
->where([
'game_id' => ['in', $gameIdRows],
'register_time' => ['between', [$startTime, $endTime]]
])
->group('date')
->select(); */
$newUsers = M('user_play', 'tab_')
->field('count(DISTINCT user_id) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") date')
->where([
'game_id' => ['in', $gameIdRows],
'create_time' => ['between', [$startTime, $endTime]]
])
->group('date')
->select();
$newUsers = index_by_column('date', $newUsers);
// 活跃用户
$loginUsers = M('login_daily_record', 'tab_')
->field('count(DISTINCT user_id) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") date')
->where([
'game_id' => ['in', $gameIdRows],
'create_time' => ['between', [$startTime, $endTime]]
])
->group('date')
->select();
$loginUsers = index_by_column('date', $loginUsers);
// 付费玩家,付费金额
$payLogs = M('spend', 'tab_')
->field('count(DISTINCT user_id) count, sum(pay_amount) amount, FROM_UNIXTIME(pay_time, "%Y-%m-%d") date')
->where([
'game_id' => ['in', $gameIdRows],
'pay_time' => ['between', [$startTime, $endTime]],
'pay_status' => 1,
])
->group('date')
->select();
$payLogs = index_by_column('date', $payLogs);
// 起始时间前的总充值金额
/* $beforePayAmount =M('spend', 'tab_')
->where([
'game_id' => ['in', $gameIdRows],
'pay_time' => ['lt', $startTime],
'pay_status' => 1,
])
->sum('pay_amount'); */
$rows = [];
for ($time = $startTime; $time < $endTime; $time = $time + 24*3600) {
$date = date('Y-m-d', $time);
$newUser = isset($newUsers[$date]) ? $newUsers[$date]['count'] : 0;
$loginUser = isset($loginUsers[$date]) ? $loginUsers[$date]['count'] : 0;
$payAmount = isset($payLogs[$date]) ? $payLogs[$date]['amount'] : 0;
$payUser = isset($payLogs[$date]) ? $payLogs[$date]['count'] : 0;
$rows[] = [
'date' => $date,
'new_user' => $newUser,
'login_user' => $loginUser,
'pay_amount' => $payAmount,
'pay_user' => $payUser,
'pay_rate' => $loginUser > 0 ? (round($payUser / $loginUser * 100, 2) . '%') : '--',
'arpu' => $loginUser > 0 ? (round($payAmount / $loginUser, 2)) : '0.00',
'arppu' => $payUser > 0 ? (round($payAmount / $payUser, 2)) : '0.00',
];
}
$thml = '';
$html .= '<table>' . PHP_EOL;
$html .= '<tr>' . PHP_EOL;
$html .= '<th>日期</th><th>新增用户</th><th>活跃玩家</th><th>充值金额</th><th>付费玩家</th><th>付费率</th><th>ARPU</th><th>ARPPU</th>' . PHP_EOL;
$html .= '</tr>' . PHP_EOL;
foreach ($rows as $row) {
$html .= '<tr>' . PHP_EOL;
$html .= '<td>' . $row['date'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['new_user'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['login_user'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['pay_amount'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['pay_user'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['pay_rate'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['arpu'] . '</td>' . PHP_EOL;
$html .= '<td>' . $row['arppu'] . '</td>' . PHP_EOL;
$html .= '</tr>' . PHP_EOL;
}
$html .= '<table>' . PHP_EOL;
echo $html;
// 付费率 (当日充值用户数/当日活跃用户数)
// ARPU (当日充值金额/当日活跃用户数)
// ARRPU (当日充值金额/当日充值用户数)
}
}

Loading…
Cancel
Save