@ -1726,6 +1726,7 @@ class QueryController extends BaseController
$begTime = strtotime($initBegTime);
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$endTime = strtotime($initEndTime);
$endTime += 3600 * 24;
$endTime += 3600 * 24;
$nowTime = strtotime(date('Y-m-d 00:00:00', time()));
$promote = $this->getLoginPromote();
$promote = $this->getLoginPromote();
$levelPromote = $this->getLevelPromote();
$levelPromote = $this->getLevelPromote();
@ -1735,50 +1736,38 @@ class QueryController extends BaseController
$pagination = '';
$pagination = '';
$count = 0;
$count = 0;
if (intval($endTime - $begTime) / (24 * 3600) < = 31) {
if (intval($endTime - $begTime) / (24 * 3600) < = 31) {
$map = [
$map['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'];
'_logic' => 'or',
'id' => $queryPromote['id'],
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
$ids[] = $queryPromote['id'];
$map = [];
$map = ['uc.promote_id' => ['in', $ids]];
if (count($ids) > 0) {
$subMap = ['promote_id' => ['in', $ids]];
$map = ['promote_id' => ['in', $ids]];
} else {
$map['_string'] = '1< >1';
}
$subMap = [];
if ($relationGameId != 0) {
if ($relationGameId != 0) {
$gameMap['relation_game_id'] = $relationGameId;
$gameMap['relation_game_id'] = $relationGameId;
if ($sdkVersion != 0) {
if ($sdkVersion != 0) {
$gameMap['sdk_version'] = $sdkVersion;
$gameMap['sdk_version'] = $sdkVersion;
}
}
$gameId = M('game', 'tab_')->where($gameMap)->getField('id', true);
$gameId = M('game', 'tab_')->where($gameMap)->getField('id', true);
$map['game_id'] = ['in', $gameId];
$map['uc.game_id'] = ['in', $gameId];
$subMap['game_id'] = ['in', $gameId];
$subMap['game_id'] = ['in', $gameId];
}
}
if ($serverId != 0) {
if ($serverId != 0) {
$map['server_id'] = $serverId;
$map['uc. server_id'] = $serverId;
$subMap['server_id'] = $serverId;
$subMap['server_id'] = $serverId;
}
}
if ($roleName != '') {
if ($roleName != '') {
$map['role_name'] = ['like', '%' . $roleName . '%'];
$map['ui. role_name'] = ['like', $roleName . '%'];
}
}
if ($userAccount != '') {
if ($userAccount != '') {
$map['user_account'] = ['like', '%' . $userAccount . '%'];
$map['ui.u ser_account'] = ['like', $userAccount . '%'];
}
}
if ($isSelf) {
if ($isSelf) {
$map['promote_id'] = $queryPromote['id'];
$map['uc. promote_id'] = $queryPromote['id'];
}
}
$subMap['create_time'] = ['between', [$begTime, $endTime - 1]];
$subMap['create_time'] = ['between', [$begTime, $endTime - 1]];
$roleIdMap = $subMap;
$roleIds = M('user_play_data_count', 'tab_')->where($roleIdMap)->group('role_id')->getField('role_id', true);
if (count($roleIds) > 0) {
$map['role_id'] = ['in', $roleIds];
}
if ($costBegin != '' || $costEnd != '') {
if ($costBegin != '' || $costEnd != '') {
$having = '';
$having = '';
if ($costBegin != '' & & $costEnd != '') {
if ($costBegin != '' & & $costEnd != '') {
@ -1793,10 +1782,10 @@ class QueryController extends BaseController
->group('game_id,server_id,role_id')
->group('game_id,server_id,role_id')
->having($having)
->having($having)
->buildSql();
->buildSql();
$map['_string'] = 'role_id in(' . $subQuery . ')';
$map['_string'] = 'ui. role_id in(' . $subQuery . ')';
}
}
$orderBy = 'play_time desc';
$orderBy = 'ui. play_time desc';
if (!empty($sortName)) {
if (!empty($sortName)) {
if (in_array($sortName, $sortNameData)) {
if (in_array($sortName, $sortNameData)) {
$desc = ' desc';
$desc = ' desc';
@ -1819,53 +1808,25 @@ class QueryController extends BaseController
}
}
}
}
$spendMap['uc.create_time'] = ['between', [$begTime, $endTime - 1]];
$map['uc.create_time'] = ['between', [$begTime, $endTime - 1]];
$spendMap['_string'] = 'uc.game_id = tab_user_play_info.game_id and uc.server_id = tab_user_play_info.server_id and uc.role_id = tab_user_play_info.role_id';
$fieldUC = "sum(uc.recharge_cost) recharge_cost,sum(uc.recharge_count) recharge_count,sum(if(uc.create_time = {$nowTime},uc.recharge_cost,0)) as recharge_cost_today";
$sqlCost = M('user_play_data_count', 'tab_')->alias('uc')
$fieldUI = "ui.user_account,ui.game_name,ui.role_name,ui.role_level,ui.server_name,ui.play_time,ui.play_ip,ui.promote_account,ui.sdk_version";
->field('sum(uc.recharge_cost) cost')
$field = $fieldUC . ',' . $fieldUI;
->where($spendMap)
$subQuery = M('user_play_data_count', 'tab_')->alias('uc')
->buildSql();
->field($field)
$sqlCount = M('user_play_data_count', 'tab_')->alias('uc')
->join('tab_user_play_info as ui on ui.promote_id = uc.promote_id and ui.game_id = uc.game_id and ui.server_id = uc.server_id and ui.role_id = uc.role_id')
->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();
$subQuery = M('user_play_info', 'tab_')
->field("*,$sqlCost as recharge_cost,$sqlCount as recharge_count,$sqlTodayCost as recharge_cost_today")
->where($map)
->where($map)
->having('recharge_cost > 0')
->group('uc.role_id,uc.server_id,uc.game_id')
->order('play_time desc')
->buildSql();
->buildSql();
$query = M()->field('* ')
$query = M()->alias('record')
->table($subQuery)
->table($subQuery)
->alias('a')
->order($orderBy);
->order($orderBy);
list($rol es, $pagination, $count) = $this->paginate($query);
list($records, $pagination, $count) = $this->paginate($query);
foreach ($roles as $role) {
foreach ($records as & $list) {
$records[] = [
$list['user_account'] = encryption($list['user_account']);
'user_account' => encryption($role['user_account']),
$list['unlogin_day'] = intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $list['play_time']))) / (24 * 3600));
'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' => empty($role['recharge_cost']) ? 0 : $role['recharge_cost'],
'recharge_count' => empty($role['recharge_count']) ? 0 : $role['recharge_count'],
'recharge_cost_today' => empty($role['recharge_cost_today']) ? 0 : $role['recharge_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))
];
}
}
}
}