@ -1289,25 +1289,12 @@ class DownloadController extends BaseController {
$levelPromote = $this->getLevelPromote();
$queryPromote = $this->getQueryPromote($levelPromote);
$map2[] = [
'_logic' => 'or',
'id' => $queryPromote['id'],
'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']
];
$map2['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'];
$ids = M('promote', 'tab_')->where($map2)->getField('id', true);
if(empty($ids)) {
$ids = array();
}
if(empty($levelPromote)) {
array_push($ids,PID);
}
// array_push($ids,$queryPromote['id']);
if (!empty($ids)) {
$map['promote_id'] = ['in',$ids];
$ids[] = $queryPromote['id'];
}else {
$map['_string'] = '1< >1';
}
$map = ['promote_id' => ['in', $ids]];
$subMap = ['promote_id' => ['in', $ids]];
if ($gameId != 0) {
$gameMap['relation_game_id'] = $gameId;
@ -1315,7 +1302,9 @@ class DownloadController extends BaseController {
$gameMap['sdk_version'] = $sdkVersion;
}
$gameId1 = M('game', 'tab_')->where($gameMap)->getField('id', true);
$map['game_id'] = ['in', $gameId1];
$subMap['game_id'] = ['in', $gameId1];
}
if ($serverId != 0) {
$map['server_id'] = $serverId;
@ -2816,21 +2805,33 @@ class DownloadController extends BaseController {
$subMap = [];
if(!empty($map['game_id'])) {
$subMap['game_id'] = $map['game_id'];
$map['uc.game_id'] = $map['game_id'];
unset($map['game_id']);
}
if(!empty($map['server_id'])) {
$subMap['server_id'] = $map['server_id'];
$map['ui.server_id'] = $map['server_id'];
unset($map['server_id']);
}
if(!empty($map['role_name'])) {
$map['ui.role_name'] = $map['role_name'];
unset($map['role_name']);
}
if(!empty($map['user_account'])) {
$map['ui.user_account'] = $map['user_account'];
unset($map['user_account']);
}
if(!empty($map['promote_id'])) {
$map['uc.promote_id'] = $map['promote_id'];
unset($map['promote_id']);
}
$costBegin = $map['costbegin'];
$costEnd = $map['costend'];
unset($map['costbegin']);
unset($map['costend']);
$nowTime = strtotime(date('Y-m-d 00:00:00', time()));
$subMap['create_time'] = ['between', [$map['begintime'], $map['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 != '') {
$having = '';
if ($costBegin != '' & & $costEnd != '') {
@ -2845,39 +2846,23 @@ class DownloadController extends BaseController {
->group('game_id,server_id,role_id')
->having($having)
->buildSql();
$map['_string'] = 'role_id in (' . $subQuery . ')';
}
$spendMap['uc.create_time'] = ['between', [$map['begintime'], $map['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';
// $map['create_time'] = ['between', [strtotime(date('Y-m-d 00:00:00')) - 6*24*3600, strtotime(date('Y-m-d 23:59:59'))]];
$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();
$map['_string'] = 'ui.role_id in (' . $subQuery . ')';
}
$map['uc.create_time'] = ['between', [$map['begintime'], $map['endtime'] - 1]];
unset($map['begintime']);
unset($map['endtime']);
$subQuery = M('user_play_info', 'tab_')
->field("*,$sqlCost as recharge_cost,$sqlCount as recharge_count,$sqlTodayCost as recharge_cost_today")
//$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";
$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 = $fieldUC . ',' . $fieldUI;
$subQuery = M('user_play_data_count', 'tab_')->alias('uc')
->field($field)
->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')
->where($map)
->having('recharge_cost > 0')
->order('play_time desc')
->group('uc.role_id,uc.server_id,uc.game_id')
->buildSql();
$roles = M()->field(' * ')
$roles = M()->alias('record')
->table($subQuery)
->alias('a')
->order('play_time desc')
->select();
foreach ($roles as $role) {
$records[] = [