推广平台->数据汇总->充值玩家--更新

master
chenxiaojun 5 years ago
parent 09ab8bf8ad
commit 3e68880ac0

@ -1709,118 +1709,132 @@ class QueryController extends BaseController
$isSelf = I('is_self', 0);
$roleName = I('role_name', '');
$userAccount = I('user_account', '');
$promoteId = I('promote_id', 0);
$sdkVersion = I('sdk_version', 0);
$costBegin = I('cost_begin', '');
$costEnd = I('cost_end', '');
$sortName = trim(I('sort_name', ''));
$sort = intval(I('sort', 1));
$nowTime = date('Y-m-d');
$initBegTime = date('Y-m-d', strtotime('-6 day', strtotime($nowTime)));
$initBegTime = empty(I('begtime')) ? $initBegTime : I('begtime');
$initEndTime = $nowTime;
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$endTime += 3600 * 24;
$promote = $this->getLoginPromote();
$levelPromote = $this->getLevelPromote();
$queryPromote = $this->getQueryPromote($levelPromote);
$map[] = [
'_logic' => 'or',
'id' => $queryPromote['id'],
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$map = [];
if (count($ids) > 0) {
$map = ['promote_id' => ['in', $ids]];
} else {
$map['_string'] = '1<>1';
}
$records = [];
$pagination = '';
$count = 0;
if (intval($endTime - $begTime) / (24 * 3600) <= 31) {
$map[] = [
'_logic' => 'or',
'id' => $queryPromote['id'],
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$spendMap = $map;
if ($gameId != 0) {
$map['game_id'] = $gameId;
}
if ($serverId != 0) {
$map['server_id'] = $serverId;
}
if ($roleName != '') {
$map['role_name'] = ['like', '%' . $roleName . '%'];
}
if ($userAccount != '') {
$map['user_account'] = ['like', '%' . $userAccount . '%'];
}
if ($sdkVersion != 0) {
$map['sdk_version'] = $sdkVersion;
}
if ($isSelf) {
$map['promote_id'] = $queryPromote['id'];
$spendMap['promote_id'] = $queryPromote['id'];
}
if ($costBegin != '' || $costEnd != '') {
$having = '';
if ($costBegin != '' && $costEnd != '') {
$having = 'sum(cost) between ' . $costBegin . ' and ' . $costEnd;
} elseif ($costBegin != '' && $costEnd == '') {
$having = 'sum(cost) >= ' . $costBegin;
} elseif ($costBegin == '' && $costEnd != '') {
$having = 'sum(cost) <= ' . $costEnd;
$map = [];
if (count($ids) > 0) {
$map = ['promote_id' => ['in', $ids]];
} else {
$map['_string'] = '1<>1';
}
$subMap = $map;
$subMap['pay_status'] = 1;
$subMap['pay_game_status'] = 1;
$subQuery = M('spend', 'tab_')->field('game_player_id')->where($subMap)->group('game_player_id')->having($having)->buildSql();
$map['_string'] = 'role_id in (' . $subQuery . ')';
}
$query = M('user_play_info', 'tab_')->where($map)->order('play_time desc');
list($roles, $pagination, $count) = $this->paginate($query);
$roleIds = array_column($roles, 'role_id');
$spendMap['pay_status'] = 1;
$spendMap['pay_game_status'] = 1;
if (count($roleIds) > 0) {
$spendMap['game_player_id'] = ['in', $roleIds];
} else {
$spendMap['_string'] = '1<>1';
}
$allRecharges = M('spend', 'tab_')->field('count(*) count, sum(cost) cost, game_player_id')->where($spendMap)->group('game_player_id')->select();
$allRecords = [];
foreach ($allRecharges as $recharge) {
$allRecords[$recharge['game_player_id']] = $recharge;
}
$subMap = [];
if ($gameId != 0) {
$map['game_id'] = $gameId;
$subMap['game_id'] = $gameId;
}
if ($serverId != 0) {
$map['server_id'] = $serverId;
$subMap['server_id'] = $serverId;
}
if ($roleName != '') {
$map['role_name'] = ['like', '%' . $roleName . '%'];
}
if ($userAccount != '') {
$map['user_account'] = ['like', '%' . $userAccount . '%'];
}
if ($sdkVersion != 0) {
$map['sdk_version'] = $sdkVersion;
}
if ($isSelf) {
$map['promote_id'] = $queryPromote['id'];
}
$spendMap['pay_time'] = ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
$todayRecharges = M('spend', 'tab_')->field('sum(cost) cost, game_player_id')->where($spendMap)->group('game_player_id')->select();
$todayRecords = [];
foreach ($todayRecharges as $recharge) {
$todayRecords[$recharge['game_player_id']] = $recharge;
}
$subMap['create_time'] = ['between', [$begTime, $endTime - 1]];
if ($costBegin != '' || $costEnd != '') {
$having = '';
if ($costBegin != '' && $costEnd != '') {
$having = 'sum(recharge_cost) between ' . $costBegin . ' and ' . $costEnd;
} elseif ($costBegin != '' && $costEnd == '') {
$having = 'sum(recharge_cost) >= ' . $costBegin;
} elseif ($costBegin == '' && $costEnd != '') {
$having = 'sum(recharge_cost) <= ' . $costEnd;
}
$subQuery = M('user_play_data_count', 'tab_')->field('role_id')
->where($subMap)
->group('game_id,server_id,role_id')
->having($having)
->buildSql();
$map['_string'] = 'role_id in (' . $subQuery . ')';
}
$spendMap['uc.create_time'] = ['between', [$begTime, $endTime - 1]];
$spendMap['_string'] = 'uc.game_id = game_id and uc.server_id = server_id and uc.role_id = role_id';
$sqlCost = M('user_play_data_count', 'tab_')->alias('uc')
->field('sum(uc.recharge_cost) cost')
->where($spendMap)
->buildSql();
$sqlCount = M('user_play_data_count', 'tab_')->alias('uc')
->field('sum(uc.recharge_count) count')
->where($spendMap)
->buildSql();
$spendMap['uc.create_time'] = ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]];
$sqlTodayCost = M('user_play_data_count', 'tab_')->alias('uc')
->field('sum(uc.recharge_count) count')
->where($spendMap)
->buildSql();
$query = M('user_play_info', 'tab_')
->field("*,$sqlCost as cost,$sqlCount as count,$sqlTodayCost as today_cost")
->where($map)
->order('play_time desc');
list($roles, $pagination, $count) = $this->paginate($query);
$records = [];
foreach ($roles as $role) {
$records[] = [
'user_account' => encryption($role['user_account']),
'game_name' => $role['game_name'],
'role_name' => $role['role_name'],
'role_id' => $role['role_id'],
'role_level' => $role['role_level'],
'server_id' => $role['server_id'],
'server_name' => $role['server_name'],
'recharge_cost' => isset($allRecords[$role['role_id']]) ? round(floatval($allRecords[$role['role_id']]['cost']), 2) : 0,
'recharge_count' => isset($allRecords[$role['role_id']]) ? $allRecords[$role['role_id']]['count'] : 0,
'recharge_cost_today' => isset($todayRecords[$role['role_id']]) ? round(floatval($todayRecords[$role['role_id']]['cost']), 2) : 0,
'play_time' => $role['play_time'],
'play_ip' => $role['play_ip'],
'promote_id' => $role['promote_id'],
'promote_account' => $role['promote_account'],
'sdk_version' => $role['sdk_version'],
'unlogin_day' => intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $role['play_time']))) / (24 * 3600))
];
foreach ($roles as $role) {
$records[] = [
'user_account' => encryption($role['user_account']),
'game_name' => $role['game_name'],
'role_name' => $role['role_name'],
'role_id' => $role['role_id'],
'role_level' => $role['role_level'],
'server_id' => $role['server_id'],
'server_name' => $role['server_name'],
'recharge_cost' => $role['cost'],
'recharge_count' => $role['count'],
'recharge_cost_today' => $role['cost_today'],
'play_time' => $role['play_time'],
'play_ip' => $role['play_ip'],
'promote_id' => $role['promote_id'],
'promote_account' => $role['promote_account'],
'sdk_version' => $role['sdk_version'],
'unlogin_day' => intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $role['play_time']))) / (24 * 3600))
];
}
}
$games = $this->getGamesByPromote($promote);
$this->assign('games', $games);
$this->assign('promotes', $promotes);
$this->assign('groupPromotes', $groupPromotes);
$this->assign('records', $records);
$this->assign('pagination', $pagination);
$this->assign('count', $count);
$this->assign('initBegTime', $initBegTime);
$this->assign('initEndTime', $initEndTime);
$this->display('userRecharges');
}

Loading…
Cancel
Save