@ -1100,9 +1100,9 @@ class QueryController extends BaseController
$this->display();
}
public function summary($p = 1 )
public function summary()
{
$page = intval($p );
$page = intval(I('get.p', 0) );
$page = $page ? $page : 1; //默认显示第一页数据arraypage
if (isset($_REQUEST['row'])) {
@ -1114,17 +1114,17 @@ class QueryController extends BaseController
$childPromoteIds = getAllChildPromoteList(3);
if (empty($childPromoteIds)) {
$map['tab_apply.promote_id'] = 0;
$userPlayInfoWhere ['tab_user_play_info.promote_id'] = 0;
$userGameLoginWhere ['tab_user_game_login_record.promote_id'] = 0;
$spendWhere ['tab_spend.promote_id'] = 0;
$userPlayInfoMap ['tab_user_play_info.promote_id'] = 0;
$userGameLoginMap ['tab_user_game_login_record.promote_id'] = 0;
$spendMap ['tab_spend.promote_id'] = 0;
} else {
$map['tab_apply.promote_id'] = ['in', $childPromoteIds];
$userPlayInfoWhere ['tab_user_play_info.promote_id'] = ['in', $childPromoteIds];
$userGameLoginWhere ['tab_user_game_login_record.promote_id'] = ['in', $childPromoteIds];
$spendWhere ['tab_spend.promote_id'] = ['in', $childPromoteIds];
$userPlayInfoMap ['tab_user_play_info.promote_id'] = ['in', $childPromoteIds];
$userGameLoginMap ['tab_user_game_login_record.promote_id'] = ['in', $childPromoteIds];
$spendMap ['tab_spend.promote_id'] = ['in', $childPromoteIds];
}
$teamLeaderId = I('team_leader_id');//组长账号
$teamLeaderId = intval( I('team_leader_id') );//组长账号
if (!empty($teamLeaderId)) {
$hasTeamLeaderPermission = hasPromotePermission(PID, $teamLeaderId);
if ($hasTeamLeaderPermission === false) {
@ -1132,57 +1132,174 @@ class QueryController extends BaseController
}
$map['tab_apply.promote_id'] = $teamLeaderId;
$userPlayInfoWhere ['tab_user_play_info.promote_id'] = $teamLeaderId;
$userGameLoginWhere ['tab_user_game_login_record.promote_id'] = $teamLeaderId;
$spendWhere ['tab_spend.promote_id'] = $teamLeaderId;
$userPlayInfoMap ['tab_user_play_info.promote_id'] = $teamLeaderId;
$userGameLoginMap ['tab_user_game_login_record.promote_id'] = $teamLeaderId;
$spendMap ['tab_spend.promote_id'] = $teamLeaderId;
}
$promoteId = I('promote_id');//推广员账号
$promoteId = intval( I('promote_id') );//推广员账号
if (!empty($promoteId)) {
$hasPromotePermission = hasPromotePermission(PID, $promoteId);
if ($hasPromotePermission === false) {
$this->error('推广员权限异常');
}
if (!empty($map['tab_apply.promote_id'])) {
$map['_string'] = 'tab_apply.promote_id = ' . $promoteId;
$userPlayInfoWhere['_string'] = 'tab_user_play_info.promote_id = ' . $promoteId;
$userGameLoginWhere['_string'] = 'tab_user_game_login_record.promote_id = ' . $promoteId;
$spendWhere['_string'] = 'tab_spend.promote_id = ' . $promoteId;
} else {
$map['tab_apply.promote_id'] = $promoteId;
$userPlayInfoWhere['tab_user_play_info.promote_id'] = $promoteId;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = $promoteId;
$spendWhere['tab_spend.promote_id'] = $promoteId;
}
$userPlayInfoMap['_string'] = 'tab_user_play_info.promote_id = ' . $promoteId;
$userGameLoginMap['_string'] = 'tab_user_game_login_record.promote_id = ' . $promoteId;
$spendMap['_string'] = 'tab_spend.promote_id = ' . $promoteId;
}
if (!empty(I('own_id'))) {
$ownId = intval(I('own_id'));//本账号
if (!empty($ownId)) {
if (!empty($map['_string'])) {
unset($map['_string']);
unset($userPlayInfoWhere ['_string']);
unset($userGameLoginWhere ['_string']);
unset($spendWhere ['_string']);
unset($userPlayInfoMap ['_string']);
unset($userGameLoginMap ['_string']);
unset($spendMap ['_string']);
}
$map['tab_apply.promote_id'] = I('own_id');//本账号
$userPlayInfoWhere['tab_user_play_info.promote_id'] = I('own_id') ;
$userGameLoginWhere['tab_user_game_login_record.promote_id'] = I('own_id') ;
$spendWhere['tab_spend.promote_id'] = I('own_id') ;
$map['tab_apply.promote_id'] = $ownId;
$userPlayInfoMap['tab_user_play_info.promote_id'] = $ownId ;
$userGameLoginMap['tab_user_game_login_record.promote_id'] = $ownId ;
$spendMap['tab_spend.promote_id'] = $ownId ;
}
empty(I('relation_game_id')) || $map['tab_game.relation_game_id'] = I('relation_game_id');
empty(I('sdk_version')) || $map['tab_game.sdk_version'] = I('sdk_version');
empty(I('relation_game_id')) || $map['tab_game.relation_game_id'] = intval(I('relation_game_id'));
empty(I('sdk_version')) || $map['tab_game.sdk_version'] = intval(I('sdk_version'));
$serverField = '';
$serverJoin = '';
if (!empty(I('server_id'))) {
$serverId = intval(I('server_id'));
if (!empty($serverId)) {
$serverField = ',tab_server.id as server_id';
$serverJoin = 'tab_server on tab_apply.game_id = tab_server.game_id';
$map['tab_server.id'] = I('server_id');
$map['tab_server.id'] = $serverId;
$userPlayInfoMap['tab_user_play_info.server_id'] = $serverId;
$userGameLoginMap['tab_user_game_login_record.server_id'] = $serverId;
$spendMap['tab_spend.server_id'] = $serverId;
}
$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);
$userPlayInfoWhere['_string'] = 'tab_user_play_info.game_id = tab_apply.game_id';
$userPlayInfoMap['_complex'] = $userPlayInfoWhere;
$userPlayInfoMap2 = $userPlayInfoMap;
$userPlayInfoMap['tab_user_play_info.create_time'] = ['between', [$begTime, $endTime + 86399]];
$userGameLoginWhere['_string'] = 'tab_user_game_login_record.game_id = tab_apply.game_id';
$userGameLoginMap['_complex'] = $userGameLoginWhere;
$userGameLoginMap['tab_user_game_login_record.login_time'] = ['between', [$begTime, $endTime + 86399]];
$spendMap['tab_spend.pay_time'] = ['between', [$begTime, $endTime + 86399]];
$spendMap2 = $spendMap;
$spendWhere['_string'] = 'tab_spend.game_id = tab_apply.game_id';
$spendMap['_complex'] = $spendWhere;
$userPlayInfoModel = M('UserPlayInfo', 'tab_');
$userGameLoginModel = M('UserGameLoginRecord', 'tab_');
$spendModel = M('Spend', 'tab_');
$roleNumSql = $userPlayInfoModel
->where($userPlayInfoMap)
->fetchSql(true)
->count();
$roleNumSql = ',(' . $roleNumSql . ') as role_num';//创角数
$userNumSql = $userPlayInfoModel
->where($userPlayInfoMap)
->fetchSql(true)
->count('distinct tab_user_play_info.user_id');
$userNumSql = ',(' . $userNumSql . ') as user_num';//创角用户
$newUserNumSql = $userPlayInfoModel
->field('tab_user_play_info.create_time')
->where($userPlayInfoMap2)
->group('tab_user_play_info.user_id')
->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399))
->order('tab_user_play_info.id')
->fetchSql(true)
->select();
$newUserNumSql = ',count((' . $newUserNumSql . ')) as new_user_num';//新创角用户
$newDeviceSql = $userPlayInfoModel
->field('tab_user_play_info.create_time')
->where($userPlayInfoMap2)
->group('tab_user_play_info.create_device_number')
->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399))
->order('tab_user_play_info.id')
->fetchSql(true)
->select();
$newDeviceSql = ',count((' . $newDeviceSql . ')) as new_device_num';//新创角设备
$newIpSql = $userPlayInfoModel
->field('tab_user_play_info.create_time')
->where($userPlayInfoMap2)
->group('tab_user_play_info.create_ip')
->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399))
->order('tab_user_play_info.id')
->fetchSql(true)
->select();
$newIpSql = ',count((' . $newIpSql . ')) as new_ip_num';//新增创角IP
$loginUserNumSql = $userGameLoginModel
->where($userGameLoginMap)
->fetchSql(true)
->count('distinct tab_user_game_login_record.user_id');
$loginUserNumSql = ',(' . $loginUserNumSql . ') as login_user_num';//登录用户数
$spendUserNumSql = $spendModel
->where($spendMap)
->fetchSql(true)
->count('distinct tab_spend.user_id');
$spendUserNumSql = ',(' . $spendUserNumSql . ') as spend_user_num';//充值人数
$spendNumSql = $spendModel
->where($spendMap)
->fetchSql(true)
->count();
$spendNumSql = ',(' . $spendNumSql . ') as spend_num';//充值次数
$spendAllAmountSql = $spendModel
->where($spendMap)
->fetchSql(true)
->sum('tab_spend.pay_amount');
$spendAllAmountSql = ',(' . $spendAllAmountSql . ') as spend_all_amount';//充值总额
$spendCashSql = $spendModel
->where($spendMap)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->fetchSql(true)
->sum('tab_spend.pay_amount');
$spendCashSql = ',(' . $spendCashSql . ') as spend_cash';//现金充值
$spendGenericSql = $spendModel
->where($spendMap)
->where(array('tab_spend.pay_way' => 0))
->fetchSql(true)
->sum('tab_spend.pay_amount');
$spendGenericSql = ',(' . $spendGenericSql . ') as spend_generic';//通用币
$spendBindingSql = $spendModel
->where($spendMap)
->where(array('tab_spend.pay_way' => -1))
->fetchSql(true)
->sum('tab_spend.pay_amount');
$spendBindingSql = ',(' . $spendBindingSql . ') as spend_binding';//绑定币
// var_dump($spendCashSql);
// die;
$field = 'tab_apply.game_id,tab_game.game_name,tab_game.sdk_version';
$field .= $serverField . $roleNumSql . $userNumSql . $newUserNumSql . $newDeviceSql . $newIpSql . $loginUserNumSql . $spendUserNumSql . $spendNumSql . $spendAllAmountSql . $spendCashSql . $spendGenericSql . $spendBindingSql;
$data = M('Apply', 'tab_')
->field('tab_apply.game_id,tab_game.game_name,tab_game.sdk_version' . $serverField)
->field($f ield)
->join('tab_game on tab_apply.game_id = tab_game.id')
->join($serverJoin)//关联区服表
->where($map)
@ -1195,15 +1312,7 @@ class QueryController extends BaseController
->join('tab_game on tab_apply.game_id = tab_game.id')
->join($serverJoin)//关联区服表
->where($map)
->group('tab_apply.game_id')
->select();
$count = count($count);
$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');
->count('distinct tab_apply.game_id');
//分页
$parameter['p'] = I('get.p', 1);
@ -1219,125 +1328,31 @@ class QueryController extends BaseController
$allData = [];
if (!empty($data)) {
$userPlayInfoModel = M('UserPlayInfo', 'tab_');
$newWhere = '';
$begTime = strtotime($initBegTime);
$endTime = strtotime($initEndTime);
$userPlayInfoWhere['tab_user_play_info.create_time'] = ['between', [$begTime, $endTime + 86399]];
$userGameLoginWhere['tab_user_game_login_record.login_time'] = ['between', [$begTime, $endTime + 86399]];
$spendWhere['tab_spend.pay_time'] = ['between', [$begTime, $endTime + 86399]];
$spendWhere['tab_spend.pay_status'] = 1;
if (!empty(I('server_id'))) {
$userPlayInfoWhere['tab_user_play_info.server_id'] = I('server_id');
$userGameLoginWhere['tab_user_game_login_record.server_id'] = I('server_id');
$spendWhere['tab_spend.server_id'] = I('server_id');
$newWhere = ' and ti.server_id = ' . I('server_id');
}
foreach ($data as & $list) {
$userPlayInfoWhere['tab_user_play_info.game_id'] = $list['game_id'];
$list['role_num'] = $userPlayInfoModel
->where($userPlayInfoWhere)
->count();//创角数
$list['user_num'] = count($userPlayInfoModel
->field('tab_user_play_info.id')
->where($userPlayInfoWhere)
->group('tab_user_play_info.user_id')
->select());//创角用户
$newUserSql = '(select count(ti.id) from tab_user_play_info as ti where ti.user_id = tab_user_play_info.user_id and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $begTime . $newWhere . ') as old_num';
$list['new_user_num'] = count($userPlayInfoModel
->field($newUserSql)
->where($userPlayInfoWhere)
->group('tab_user_play_info.user_id')
->having('old_num = 0')
->select());//新创角用户
$newDeviceSql = '(select count(ti.id) from tab_user_play_info as ti where ti.create_device_number = tab_user_play_info.create_device_number and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $begTime . $newWhere . ') as old_num';
$list['new_device_num'] = count($userPlayInfoModel
->field($newDeviceSql)
->where($userPlayInfoWhere)
->group('tab_user_play_info.create_device_number')
->having('old_num = 0')
->select());//新创角设备
$newIpSql = '(select count(ti.id) from tab_user_play_info as ti where ti.create_ip = tab_user_play_info.create_ip and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $begTime . $newWhere . ') as old_num';
$list['new_ip_num'] = count($userPlayInfoModel
->field($newIpSql)
->where($userPlayInfoWhere)
->group('tab_user_play_info.create_ip')
->having('old_num = 0')
->fetchSql(true)
->select());//新增创角IP
$list['login_user_num'] = count(M('UserGameLoginRecord', 'tab_')
->field('id')
->where($userGameLoginWhere)
->group('user_id')
->select());//登录用户数
$list['spend_user_num'] = count(M('Spend', 'tab_')
->field('tab_spend.id')
->where($spendWhere)
->group('tab_spend.user_id')
->select());//充值人数
$list['spend_num'] = M('Spend', 'tab_')
->where($spendWhere)
->count();//充值次数
$list['spend_all_amount'] = M('Spend', 'tab_')
->where($spendWhere)
->sum('tab_spend.pay_amount');//充值总额
$list['spend_all_amount'] = empty($list['spend_all_amount']) ? 0 : $list['spend_all_amount'];
$list['spend_cash'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$list['spend_cash'] = empty($list['spend_cash']) ? 0 : $list['spend_cash'];
$list['spend_generic'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$list['spend_generic'] = empty($list['spend_generic']) ? 0 : $list['spend_generic'];
$list['spend_binding'] = M('Spend', 'tab_')
->where($spendWhere)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
$list['spend_binding'] = empty($list['spend_binding']) ? 0 : $list['spend_binding'];
$list['spend_discount'] = 0;//折扣币
$list['spend_voucher'] = 0;//代金券
}
$allData['spend_num'] = M('Spend', 'tab_')
->where($spendWhere )
->where($spendMap2)
->count();//充值次数
$allData['spend_all_amount'] = M('Spend', 'tab_')
->where($spendWhere )
->where($spendMap2)
->sum('tab_spend.pay_amount');//充值总额
$allData['spend_all_amount'] = empty($list['spend_all_amount']) ? 0 : $list ['spend_all_amount'];
$allData['spend_all_amount'] = empty($allData['spend_all_amount']) ? 0 : $allData['spend_all_amount'];
$allData['spend_cash'] = M('Spend', 'tab_')
->where($spendWhere )
->where($spendMap2)
->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6']))
->sum('tab_spend.pay_amount');//现金充值
$allData['spend_cash'] = empty($list['spend_cash']) ? 0 : $list ['spend_cash'];
$allData['spend_cash'] = empty($allData['spend_cash']) ? 0 : $allData['spend_cash'];
$allData['spend_generic'] = M('Spend', 'tab_')
->where($spendWhere )
->where($spendMap2)
->where(array('tab_spend.pay_way' => 0))
->sum('tab_spend.pay_amount');//通用币
$allData['spend_generic'] = empty($list['spend_generic']) ? 0 : $list ['spend_generic'];
$allData['spend_generic'] = empty($allData['spend_generic']) ? 0 : $allData['spend_generic'];
$allData['spend_binding'] = M('Spend', 'tab_')
->where($spendWhere )
->where($spendMap2)
->where(array('tab_spend.pay_way' => -1))
->sum('tab_spend.pay_amount');//绑定币
$allData['spend_binding'] = empty($list['spend_binding']) ? 0 : $list ['spend_binding'];
$allData['spend_binding'] = empty($allData['spend_binding']) ? 0 : $allData['spend_binding'];
$allData['spend_discount'] = 0;//折扣币
$allData['spend_voucher'] = 0;//代金券