Merge branch 'master_hotfix' of wmtx/platform into master

优化玩家列表数据
master
万盟天下 5 years ago committed by Gogs
commit 8665b9c131

@ -1726,6 +1726,48 @@ function getOffspringByPromoteId($promote_id = null) {
}
return $promote_ids;
}
/**
* csv 导出函数
* @param [array] $data 一般为数据库查询结果集
* @param [string] $title 表格名称
* @param [array] $fields [字段=>首行名称,...]例如:['name'=>'名称']
* @return void
*/
function data2csv(&$data,$title,$fields){
set_time_limit(0);
ini_set('memory_limit', '-1'); //设置内存不受限制
$csvFileName = $title.'.csv';
//设置好告诉浏览器要下载excel文件的headers
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$fp = fopen('php://output', 'a');//打开output流
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
$field = array_keys($fields);
//生成首行
$header = array_values($fields);
fputcsv($fp, $header);
$index = 0;
foreach ($data as $row) {
$a = [];
foreach($field as $k=>$v){
// $a[$v] = $row[$v] . "\t";//防止格式错误
$a[$v] = $row[$v];
}
if ($index == 10000) { //每次写入1000条数据清除内存
$index = 0;
ob_flush();//清除内存
flush();
}
$index++;
fputcsv($fp, $a);
}
ob_flush();
fclose($fp); //每生成一个文件关闭
die();
}
?>

@ -67,7 +67,7 @@ class MemberController extends ThinkController
$map['tab_user.register_type'] = $_GET['register_way'];
}else{
if (I('type', 1) == 1) {
$map['tab_user.register_type'] = ['in', [1, 2, 7]];
$map['tab_user.register_type'] = ['not in', [0, 3, 4, 5, 6]];
}else{
$map['tab_user.register_type'] = ['in', [0, 3, 4, 5, 6]];
}
@ -80,18 +80,17 @@ class MemberController extends ThinkController
if (isset($_REQUEST['viplevel'])) {
$havs = get_vip_level_limit('recharge_total', $_REQUEST['viplevel']);
}
//1.2 与游戏相关
$game_map = false;
//1.2 与游戏相关 查询游戏玩家表
$gameplay =false;
if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type'])) {
$game_map = " and tab_user_play_info.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")";
$gameplay = " and tab_user_play.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")";
}
if (isset($_REQUEST['server_name'])) {
if($game_map){
$game_map .= " and tab_user_play_info.server_name = '{$_REQUEST['server_name']}' ";
}else{
$game_map = " and tab_user_play_info.server_name = '{$_REQUEST['server_name']}' ";
}
//查询游戏角色表
$game_map = false;
if (isset($_REQUEST['server_id'])) { //有区服,一定有游戏
$gameplay =false;
$game_map = " and tab_user_play_info.server_id = '{$_REQUEST['server_id']}' ";
$game_map .= " and tab_user_play_info.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")";
}
$promoteRoot = getPowerPromoteIds();
@ -132,17 +131,25 @@ class MemberController extends ThinkController
}
}
}
//计算用户列表
$data = M("user","tab_")
->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(sum(ss.pay_amount), 0) AS recharge_total")
->where($map)
->group("tab_user.id")
->page($page, $row)
// ->page($page, $row)
->order($order);
if(!isset($_REQUEST['export'])){
$data ->page($page, $row);
}
if($havs){
$data->having($havs);
}
if($gameplay){
$data->join("
(select user_id from tab_user_play where 1 $gameplay group by tab_user_play.user_id) a ON a.user_id = tab_user.id
");
}
if($game_map){
$data->join("
(select user_id from tab_user_play_info where 1 $game_map group by tab_user_play_info.user_id) a ON a.user_id = tab_user.id
@ -154,6 +161,55 @@ class MemberController extends ThinkController
$data->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1","left");
}
$data = $data->select();
if(isset($_REQUEST['export'])){
$isadmin = is_administrator();
//获取等级
$tool = M('tool',"tab_")->field('config,status')->where(['name'=>'viplevel'])->find();
$viplevel = false;
if(!empty($tool) && $tool['status']==1){
$viplevel = json_decode($tool['config'],true);
$len = count($viplevel);
if(empty($viplevel)) {$viplevel = false;}
}
foreach ($data as $k => &$v) {
$v['register_type'] = get_registertype($v['register_type']);
if(!$isadmin){
$v['account'] = encryptStr($v['account']);
$v['promote_account'] = encryptStr($v['promote_account']);
$v['device_number'] = encryptStr($v['device_number']);
}
empty($v['alipay']) && $v['alipay']="--";
empty($v['small_count']) && $v['small_count']="--";
$v['gold_coin']?:'0.00';
if($viplevel){
$vl=0;
$money = intval($v['recharge_total']*10000);
foreach($viplevel as $k=>$value) {
$i = intval(str_replace('vip','',$k));
if($money<intval($value*10000)) {$vl = $i-1;break;}
if($i == $len) {$vl = $i;}
}
$v['vip_level'] = $vl;
}else{
$v['vip_level'] = 0;
}
$v['register_time'] = date('Y-m-d H:i:s',$v['register_time']);
$v['login_time'] = date('Y-m-d H:i:s',$v['login_time']);
$v['lock_status'] = get_info_status($v['lock_status'],4);
$v['check_status'] = $v['check_status']==1 ? "正常" :"拉黑";
// $data[$k] = $v;
}
$field = array(
"id"=>"账号ID","account"=>"玩家账号","promote_account"=>"所属推广员","balance"=>"账户平台币","recharge_total"=>"累计充值","gold_coin"=>"金币",
"alipay"=>"绑定支付宝","small_count"=>"小号","vip_level"=>"VIP等级","register_type"=>"注册方式","register_time"=>"注册时间","register_ip"=>"注册IP","login_time"=>"最后登录时间",
"device_number"=>"设备号","lock_status"=>"账号状态","check_status"=>"拉黑状态"
);
data2csv($data,"玩家_玩家列表",$field);
}
if($havs){
//判断是否需要vip等级分类
@ -167,6 +223,11 @@ class MemberController extends ThinkController
(select user_id from tab_user_play_info where 1 $game_map group by tab_user_play_info.user_id) a ON a.user_id = tab_user.id
");
}
if($gameplay){
$user_count->join("
(select user_id from tab_user_play where 1 $gameplay group by tab_user_play.user_id) a ON a.user_id = tab_user.id
");
}
if($promoterSelect){
$user_count->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1".$spendprom,"left");
}else{
@ -187,6 +248,11 @@ class MemberController extends ThinkController
(select user_id from tab_user_play_info where 1 $game_map group by tab_user_play_info.user_id) a ON a.user_id = tab_user.id
");
}
if($gameplay){
$user_count->join("
(select user_id from tab_user_play where 1 $gameplay group by tab_user_play.user_id) a ON a.user_id = tab_user.id
");
}
$user_count = $user_count->find()['user_count'];
//计算累计充值总额
$now_count = M("user","tab_")
@ -197,6 +263,11 @@ class MemberController extends ThinkController
(select user_id from tab_user_play_info where 1 $game_map group by tab_user_play_info.user_id) a ON a.user_id = tab_user.id
");
}
if($gameplay){
$now_count->join("
(select user_id from tab_user_play where 1 $gameplay group by tab_user_play.user_id) a ON a.user_id = tab_user.id
");
}
if($promoterSelect){
$now_count->join("tab_spend AS ss ON ss.user_id = tab_user.id AND ss.pay_status = 1".$spendprom,"left");
}else{
@ -221,6 +292,11 @@ class MemberController extends ThinkController
if($game_map){
$history_count->join("(select user_id from tab_user_play_info where 1 $game_map group by tab_user_play_info.user_id) a ON a.user_id = tab_user.id");
}
if($gameplay){
$history_count->join("
(select user_id from tab_user_play where 1 $gameplay group by tab_user_play.user_id) a ON a.user_id = tab_user.id
");
}
$history_count = $history_count->find()['recharge_total'];
$this->assign('history_count', $history_count?:0);
}
@ -1057,7 +1133,7 @@ class MemberController extends ThinkController
unset($_REQUEST['end']);
}
if (isset($_REQUEST['account'])) {
$map['user_account'] = array('like', '%' . trim($_REQUEST['account']) . '%');
$map['user_account'] = array('like', trim($_REQUEST['account']) . '%');
unset($_REQUEST['account']);
}
if (isset($_REQUEST['server_name'])) {
@ -1093,9 +1169,13 @@ class MemberController extends ThinkController
// $map['login_time'] = ['exp', 'login_time<>0'];
$extend = array();
$extend['map'] = $map;
$count = M('UserLoginRecord','tab_')->table('tab_user_login_record FORCE INDEX(user_id_promote_idx)')->field('user_id')->where($extend['map'])->group('user_id')->select(false);
$count = M('UserLoginRecord','tab_')
// ->table('tab_user_login_record FORCE INDEX(user_id_promote_idx)')
->field('user_id')->where($extend['map'])
->group('user_id')
->select(false);
$sql = "select count(user_id) as count from ({$count})t";
// dd($sql);
$count = M('UserLoginRecord','tab_')->query($sql);
$this->m_title = '登录记录';

@ -37,7 +37,7 @@
</div>
<h3 class="page_title">玩家列表</h3>
<if condition="(I('type',1) eq 1) ">
<p class="description_text">说明:此列表数据以平台账号为统计基数</p>
<p class="description_text">说明:此列表统计平台账号总数,当筛选条件为游戏不含区服时为该游戏的玩家数量,含区服时为玩家创建角色数量</p>
<else/>
<p class="description_text">说明游客登录默认属于第三方用户当用户通过SDK设置了用户名以后记录变换到本站用户列表里账户自动更换为设置的账号</p>
</if>
@ -131,7 +131,7 @@
</select>
</div>
<div class="input-list input-list-server search_label_rehab">
<select id="server_name" name="server_name" class="select_gallery" style="width:120px;">
<select id="server_id" name="server_id" class="select_gallery" style="width:120px;">
<option value="">区服名称</option>
</select>
</div>
@ -354,7 +354,9 @@
</div>
<div class="page">
<if condition="$is_admin eq true ">
<a class="sch-btn" href="{:U('Export/expUser',array_merge(['id'=>3,'xlsname'=>'玩家_玩家列表_'.(I('get.type')==2?'第三方玩家':'本站玩家')],I('get.')))}">导出</a>
<a class="sch-btn export-btn"
href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a>
<!-- <a class="sch-btn" href="{:U('Export/expUser',array_merge(['id'=>3,'xlsname'=>'玩家_玩家列表_'.(I('get.type')==2?'第三方玩家':'本站玩家')],I('get.')))}">导出</a> -->
</if>
{$_page|default=''}
</div>
@ -393,6 +395,15 @@
<script type="text/javascript">
$(function(){
$(".select_gallery").select2();
$(".export-btn").on("click",function(e){
e.preventDefault();
var cont = {$user_count};
if(cont < 50000){
window.location.href=$(this).attr("href")
}else{
layer.msg('为保证导出效率大于50000条数据暂不支持导出请更换检索条件后再次尝试');
}
})
//搜索功能
$("#search").click(function(){
var url = $(this).attr('url');
@ -501,7 +512,7 @@
});
$("#promote_level").change();
})
var game_server = "{:I('server_name')}";
var game_server = "{:I('server_id')}";
$("#game_type").change(function(){
console.log({sdk_version:$("#game_type option:selected").val(), game_name:$("#game_name option:selected").val()})
$.ajax({
@ -513,11 +524,11 @@
console.log(data)
str = "<option value=''>请选择区服</option>";
for (var i in data){
str += "<option value='"+data[i].server_name+"' "+(game_server && data[i].server_name == game_server?'selected':'')+">"+data[i].server_name+"</option>"
str += "<option value='"+data[i].server_id+"' "+(game_server && data[i].server_id == game_server?'selected':'')+">"+data[i].server_name+"</option>"
}
$("#server_name").empty();
$("#server_name").append(str);
$("#server_name").select2();
$("#server_id").empty();
$("#server_id").append(str);
$("#server_id").select2();
}
})
});

Loading…
Cancel
Save