diff --git a/Application/Home/Controller/DownloadController.class.php b/Application/Home/Controller/DownloadController.class.php index 2b1fe7df7..a271b502a 100644 --- a/Application/Home/Controller/DownloadController.class.php +++ b/Application/Home/Controller/DownloadController.class.php @@ -1241,6 +1241,17 @@ class DownloadController extends BaseController { $promoteId = I('promote_id', 0); $sdkVersion = I('sdk_version', 0); $headmanPromoteId = I('headman_promote_id', 0); + $costBegin = I('cost_begin', ''); //充值总额范围 + $costEnd = I('cost_end', ''); + $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; + $map1['chain'] = ['like','%'.'/'.PID.'/'.'%']; $rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select(); $childPromoteIds = ''; @@ -1270,7 +1281,7 @@ class DownloadController extends BaseController { if(empty($levelPromote)) { array_push($ids,PID); } - array_push($ids,$queryPromote['id']); + // array_push($ids,$queryPromote['id']); if (!empty($ids)) { $map['promote_id'] = ['in',$ids]; @@ -1304,6 +1315,18 @@ class DownloadController extends BaseController { } } + if($costBegin) { + $map['costbegin'] = $costBegin; + }else { + $map['costbegin'] = ""; + } + if($costEnd) { + $map['costend'] = $costEnd; + }else { + $map['costend'] = ""; + } + $map['begintime'] = $begTime; + $map['endtime'] = $endTime; $conditions = json_encode($map,TRUE); $addtime = time(); $data = [ @@ -1763,11 +1786,11 @@ class DownloadController extends BaseController { array('promote_account','推广账号'), array('game_name','游戏名称'), array('server_name','区服'), - array('user_nickname','游戏昵称'), + array('role_name','游戏昵称'), array('role_level','等级'), ); $model = M('user_play_info','tab_'); - $data = $model->field('user_account,promote_account,game_name,server_name,user_nickname,role_level')->where($map)->select(); + $data = $model->field('user_account,promote_account,game_name,server_name,role_name,role_level')->where($map)->select(); $xlsData = []; foreach ($data as $key1 => $value1) { $value1['user_account'] = $this->encryption($value1['user_account']); @@ -2703,55 +2726,80 @@ class DownloadController extends BaseController { array('play_time','最后登录时间'), array('promote_account','推广员账号'), - ); - if(!empty($map['promote_id'])) { - $spendMap['promote_id'] = $map['promote_id']; - } - $map['create_time'] = ['between', [strtotime(date('Y-m-d 00:00:00')) - 6*24*3600, strtotime(date('Y-m-d 23:59:59'))]]; - $roles = M('user_play_info','tab_')->where($map)->select(); - - $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 = []; + $subMap['game_id'] = $map['game_id']; + $subMap['server_id'] = $map['server_id']; + $costBegin = $map['costbegin']; + $costEnd = $map['costend']; + unset($map['costbegin']); + unset($map['costend']); + $roleIds = M('user_play_data_count', 'tab_')->group('role_id')->getField('role_id', true); + $map['role_id'] = ['in', $roleIds]; + $subMap['create_time'] = ['between', [$map['begintime'], $map['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', [$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(); - $map['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($map)->group('game_player_id')->select(); - $todayRecords = []; - foreach ($todayRecharges as $recharge) { - $todayRecords[$recharge['game_player_id']] = $recharge; - } + $sqlCount = M('user_play_data_count', 'tab_')->alias('uc') + ->field('sum(uc.recharge_count) count') + ->where($spendMap) + ->buildSql(); - $records = []; + $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(); + unset($map['begintime']); + unset($map['endtime']); + $roles = M('user_play_info', 'tab_') + ->field("*,$sqlCost as cost,$sqlCount as count,$sqlTodayCost as today_cost") + ->where($map) + ->order('play_time desc') + ->select(); foreach ($roles as $role) { - $records[] = [ - 'user_account' => $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)) - ]; - } + $records[] = [ + 'user_account' => $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)) + ]; + } + $xlsData = []; foreach ($records as $key1 => $value1) { $value1['user_account'] = $this->encryption($value1['user_account']);