数据汇总 每日概况

master
chenxiaojun 5 years ago
parent 3fc4438754
commit 52d9da8f1d

@ -4,6 +4,9 @@ namespace Home\Controller;
use OT\DataDictionary;
use User\Api\PromoteApi;
use Base\Repository\PromoteRepository;
use Base\Repository\SpendRepository;
use Base\Repository\UserRepository;
/**
* 前台首页控制器
@ -634,6 +637,85 @@ class QueryController extends BaseController
}
}
private function getDayList($beginTime, $endTime)
{
$dayList = [];
do {
$dayList[] = date('Y-m-d', $beginTime);
$beginTime += 24 * 60 * 60;
} while ($beginTime < $endTime);
return $dayList;
}
public function arpu()
{
$this->meta_title = 'ARPU统计';
$defaultTime = date('Y-m-d', time() - 7 * 24 * 3600) . ' 至 ' . date('Y-m-d');
$time = I('time', $defaultTime);
$sdkVersion = I('sdk_version', 0);
$gameId = I('game_id', 0);
$serverId = I('server_id', 0);
$promote = $this->getLoginPromote();
$map = [
'_logic' => 'or',
'id' => $promote['id'],
'parent_id' => $promote['id'],
'grand_id' => $promote['id'],
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$params = [];
if ($gameId > 0) {
$params['game_id'] = $gameId;
}
if ($serverId > 0) {
$params['server_id'] = $serverId;
}
if ($sdkVersion > 0) {
$params['sdk_version'] = $sdkVersion;
}
$params['promote_id'] = $ids;
list($beginTime, $endTime) = $this->getBetweenTime($time);
$params['begin_time'] = $beginTime;
$params['end_time'] = $endTime;
$dayList = $this->getDayList($beginTime, $endTime);
$params['dayList'] = $dayList;
$userRepository = new UserRepository();
$spendRepository = new SpendRepository();
$payGameCountList = $spendRepository->getPayGameCountByDay($params);
$payUserCountList = $spendRepository->getPayUserCountByDay($params);
$newPayUserCountList = $spendRepository->getNewPayUserCountByDay($params);
$payAmountList = $spendRepository->getPayAmountByDay($params);
$newPayAmountList = $spendRepository->getNewPayAmountByDay($params);
$historyPayCountList = $spendRepository->getHistoryPayCountByDay($params);
$loginCountList = $userRepository->getLoginCountByDay($params);
$registerCountList = $userRepository->getRegisterCountByDay($params);
$records = [];
foreach ($dayList as $day) {
$records[] = [
'day' => $day,
'payGameCount' => $payGameCountList[$day],
'payUserCount' => $payUserCountList[$day],
'newPayUserCount' => $newPayUserCountList[$day],
'payAmount' => number_format($payAmountList[$day], 2),
'newPayAmount' => number_format($newPayAmountList[$day], 2),
'historyPayCount' => $historyPayCountList[$day],
'loginCount' => $loginCountList[$day],
'registerCount' => $registerCountList[$day],
'payRate' => $loginCountList[$day] == 0 ? '--' : round($payUserCountList[$day] / $loginCountList[$day] * 100, 2) . '%',
'ratentionOneDay' => '--',
'arpu' => $loginCountList[$day] == 0 ? '0.00' : number_format(round($payAmount[$day] / $loginCountList[$day], 2), 2),
'arppu' => $payUserCount[$day] == 0 ? '0.00' : number_format(round($payAmount[$day] / $payUserCount[$day], 2), 2),
];
}
$this->assign('records', $records);
$this->display();
}
public function arpu_analysis()
{
@ -707,7 +789,7 @@ class QueryController extends BaseController
}
$spend2 = D('Spend');
$data = M('Game', 'tab_')->field('id as game_id, game_name')->order('id desc')->select();
$data = M('Apply', 'tab_')->field('game_id, game_name')->where(['promote_id' => $promote_id])->order('game_id desc')->select();
foreach ($data as $key => $value) {
$game_id = $value['game_id'];
$map_list['game_id'] = $game_id;
@ -967,11 +1049,12 @@ class QueryController extends BaseController
->where($map)
->order('play_time desc')
->count();//创角数
$list['user_num'] = $userPlayInfoModel
$list['user_num'] = count($userPlayInfoModel
->join($join)
->where($userPlayInfoWhere)
->where($map)
->count('distinct tab_user_play_info.user_id');//创角用户
->group('tab_user_play_info.game_id,tab_user_play_info.user_id')
->select());//创角用户
$newUserNumData = $userPlayInfoModel
->field('tab_user_play_info.create_time,count(distinct tab_user_play_info.user_id) as num')
@ -997,17 +1080,19 @@ class QueryController extends BaseController
->find();
$list['new_ip_num'] = empty($newIpNumData['num']) ? 0 : $newIpNumData['num'];//新增创角IP
$list['login_user_num'] = M('UserGameLoginRecord', 'tab_')
$list['login_user_num'] = count(M('UserGameLoginRecord', 'tab_')
->join($join)
->where($userGameLoginWhere)
->where($map)
->count('distinct tab_user_game_login_record.user_id');//登录用户数
$list['spend_user_num'] = M('Spend', 'tab_')
->field('tab_spend.id')
->group('tab_user_game_login_record.game_id,tab_user_game_login_record.user_id')
->select());//登录用户数
$list['spend_user_num'] = count(M('Spend', 'tab_')
->join($join)
->where($spendWhere)
->where($map)
->count('distinct tab_spend.user_id');//充值人数
->group('tab_spend.game_id,tab_spend.user_id')
->select());//充值人数
$list['spend_num'] = M('Spend', 'tab_')
->join($join)
->where($spendWhere)
@ -1186,6 +1271,7 @@ class QueryController extends BaseController
$userGameLoginMap['tab_user_game_login_record.login_time'] = ['between', [$begTime, $endTime + 86399]];
$spendMap['tab_spend.pay_time'] = ['between', [$begTime, $endTime + 86399]];
$spendMap['tab_spend.pay_status'] = 1;
$spendMap2 = $spendMap;
// $spendWhere['_string'] = 'tab_spend.game_id = tab_apply.game_id';
// $spendMap['_complex'] = $spendWhere;
@ -1231,7 +1317,13 @@ class QueryController extends BaseController
$parameter['begtime'] = $initBegTime;
$parameter['endtime'] = $initEndTime;
$allData = [];
$allData['spend_num'] = 0;
$allData['spend_all_amount'] = 0;
$allData['spend_cash'] = 0;
$allData['spend_generic'] = 0;
$allData['pay_amount'] = 0;
$allData['spend_discount'] = 0;
$allData['spend_voucher'] = 0;
if (!empty($data)) {
foreach ($data as &$list) {
$userPlayInfoMap['tab_user_play_info.game_id'] = $list['game_id'];
@ -1301,36 +1393,18 @@ class QueryController extends BaseController
->where($spendMap)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
}
$allData['spend_num'] = M('Spend', 'tab_')
->where($spendMap2)
->count();//充值次数
$allData['spend_all_amount'] = M('Spend', 'tab_')
->where($spendMap2)
->sum('tab_spend.pay_amount');//充值总额
$allData['spend_all_amount'] = empty($allData['spend_all_amount']) ? 0 : $allData['spend_all_amount'];
$allData['spend_cash'] = M('Spend', 'tab_')
->where($spendMap2)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$allData['spend_cash'] = empty($allData['spend_cash']) ? 0 : $allData['spend_cash'];
$allData['spend_generic'] = M('Spend', 'tab_')
->where($spendMap2)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$allData['spend_generic'] = empty($allData['spend_generic']) ? 0 : $allData['spend_generic'];
$list['spend_discount'] = 0;//折扣币
$list['spend_voucher'] = 0;//代金券
$allData['spend_binding'] = M('Spend', 'tab_')
->where($spendMap2)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
$allData['spend_binding'] = empty($allData['spend_binding']) ? 0 : $allData['spend_binding'];
$allData['spend_discount'] = 0;//折扣币
$allData['spend_voucher'] = 0;//代金券
$allData['spend_num'] += $list['spend_num'];
$allData['spend_all_amount'] += $list['spend_all_amount'];
$allData['spend_cash'] += $list['spend_cash'];
$allData['spend_generic'] += $list['spend_generic'];
$allData['spend_binding'] += $list['spend_binding'];
$allData['spend_discount'] += $list['spend_discount'];
$allData['spend_voucher'] += $list['spend_voucher'];
}
}
$serverData = $this->getServer(I('relation_game_id'), I('sdk_version'));
@ -1896,4 +1970,129 @@ class QueryController extends BaseController
$this->meta_title = "订单详情";
$this->display('view_spend_detailed');
}
private function getBetweenTime($time, $defaultBegin = 0, $defaultEnd = 0)
{
$delimiter = ' 至 ';
$begin = $defaultBegin;
$end = $defaultEnd;
if ($time != '') {
if (strpos($time, $delimiter) == -1) {
$begin = strtotime($time . ' 00:00:00');
$end = strtotime($time . ' 23:59:59');
} else {
$timeRow = explode($delimiter, $time);
$begin = strtotime($timeRow[0] . ' 00:00:00');
$end = strtotime($timeRow[1] . ' 23:59:59');
}
}
return [$begin, $end];
}
public function achievement()
{
$time = I('time', date('Y-m-d'));
$sdkVersion = I('sdk_version', 0);
$gameId = I('game_id', 0);
$serverId = I('server_id', 0);
$parentId = I('parent_id', 0);
$loginPromote = $this->getLoginPromote();
$promote = null;
if ($parentId > 0) {
$promote = M('promote', 'tab_')->where(['id' => $parentId])->find();
} else {
$promote = $loginPromote;
}
$games = $this->getGamesByPromote($promote);
$subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['parent_id' => $promote['id']])->select();
$query = M('promote', 'tab_')->field(['id', 'account', 'real_name'])->where(['parent_id' => $promote['id']]);
list($promotes, $pagination, $count) = $this->paginate($query);
$ids = array_column($promotes, 'id');
$rows = [];
if (count($ids) > 0) {
$rows = M('promote', 'tab_')->field(['id', 'parent_id'])->where(['parent_id' => ['in', $ids]])->select();
}
$basicPromotes = [];
foreach ($rows as $row) {
$basicPromotes[$row['id']] = $row['parent_id'];
}
$params = [
'isContainSubs' => true,
'basicPromotes' => $basicPromotes,
];
if ($gameId > 0) {
$params['game_id'] = $gameId;
}
if ($serverId > 0) {
$params['server_id'] = $serverId;
}
if ($sdkVersion > 0) {
$params['sdk_version'] = $sdkVersion;
}
list($beginTime, $endTime) = $this->getBetweenTime($time);
$params['begin_time'] = $beginTime;
$params['end_time'] = $endTime;
$promoteRepository = new PromoteRepository();
$createRoleCountList = $promoteRepository->getCreateRoleCountByIds($ids, $params);
$createRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds($ids, $params);
$newCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds($ids, $params);
$newCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds($ids, $params);
$newCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds($ids, $params);
$loginUserCountList = $promoteRepository->getLoginUserCountByIds($ids, $params);
$rechargeCountList = $promoteRepository->getRechargeCountByIds($ids, $params);
$rechargeUserCountList = $promoteRepository->getRechargeUserCountByIds($ids, $params);
$rechargeAmountList = $promoteRepository->getRechargeAmountByIds($ids, $params);
$records = [];
foreach ($promotes as $promote) {
$id = $promote['id'];
$records[] = [
'id' => $id,
'account' => $promote['account'],
'real_name' => $promote['real_name'],
'create_role_count' => $createRoleCountList[$id],
'create_role_user_count' => $createRoleUserCountList[$id],
'new_create_role_user_count' => $newCreateRoleUserCountList[$id],
'new_create_role_device_count' => $newCreateRoleDeviceCountList[$id],
'new_create_role_ip_count' => $newCreateRoleIpCountList[$id],
'login_user_count' => $loginUserCountList[$id],
'recharge_count' => $rechargeCountList[$id],
'recharge_user_count' => $rechargeUserCountList[$id],
'recharge_amount' => $rechargeAmountList[$id]['ban_coin'] + $rechargeAmountList[$id]['coin'] + $rechargeAmountList[$id]['cash'],
'recharge_by_ban_coin' => $rechargeAmountList[$id]['ban_coin'],
'recharge_by_coin' => $rechargeAmountList[$id]['coin'],
'recharge_by_cash' => $rechargeAmountList[$id]['cash'],
];
}
$level = 0;
if ($parentId > 0) {
$level = 2;
} elseif ($loginPromote['parent_id'] == 0) {
$level = 1;
} elseif ($loginPromote['parent_id'] > 0 && $loginPromote['grand_id'] == 0) {
$level = 2;
} elseif ($loginPromote['parent_id'] > 0 && $loginPromote['grand_id'] > 0) {
$level = 3;
}
$this->assign('games', $games);
$this->assign('level', $level);
$this->assign('subPromotes', $subPromotes);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->assign('count', $count);
$this->display();
}
}

Loading…
Cancel
Save