diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index 75804c516..aa9ee0cc8 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -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(); +} ?> diff --git a/Application/Admin/Controller/MemberController.class.php b/Application/Admin/Controller/MemberController.class.php index 260683adb..6badf7cd0 100644 --- a/Application/Admin/Controller/MemberController.class.php +++ b/Application/Admin/Controller/MemberController.class.php @@ -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"账号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); } diff --git a/Application/Admin/View/Member/user_info.html b/Application/Admin/View/Member/user_info.html index ec448a0ce..42450fb62 100644 --- a/Application/Admin/View/Member/user_info.html +++ b/Application/Admin/View/Member/user_info.html @@ -37,7 +37,7 @@

玩家列表

-

说明:此列表数据以平台账号为统计基数

+

说明:此列表统计平台账号总数,当筛选条件为游戏不含区服时为该游戏的玩家数量,含区服时为玩家创建角色数量

说明:游客登录,默认属于第三方用户;当用户通过SDK设置了用户名以后,记录变换到本站用户列表里,账户自动更换为设置的账号!

@@ -131,7 +131,7 @@
-
@@ -354,7 +354,9 @@
- 导出 + 导出 + {$_page|default=''}
@@ -393,6 +395,15 @@