getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格 $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle); $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); for ($i = 0; $i < $cellNum; $i++) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]); } for ($i = 0; $i < $dataNum; $i++) { for ($j = 0; $j < $cellNum; $j++) { $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 3), $expTableData[$i][$expCellName[$j][0]]); } } ob_end_clean();//清除缓冲区,避免乱码 header('pragma:public'); header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"'); header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } //导出Excel function expUser($id) { $xlsName = $_REQUEST['xlsname']; switch ($id) { case 1: // $xlsCell = array( // array('user_account', "玩家账号"), // array('game_name', "游戏名称"), // array('server_name', L('Game_area_clothing')), // array('role_name', "角色名"), // array('role_level', "游戏等级"), // array('play_time', "最后登录时间", 'time_format', '*'), // array('play_ip', "最后登录ip"), // ); $xlsCell = array( "创建时间","玩家账号", "游戏名称","游戏区服", L('Game_area_clothing'), "角色ID", "角色名", "游戏等级","所属推广员", "最后登录时间", '最后登录ip', ); if (isset($_REQUEST['game_name'])) { $map['game_name'] = ['like', trim($_REQUEST['game_name'])."%"]; unset($_REQUEST['game_name']); } if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like','%'.trim($_REQUEST['user_account']).'%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['server_name'])) { $map['server_name'] = array('like','%'.trim($_REQUEST['server_name']).'%'); unset($_REQUEST['server_name']); } if (isset($_REQUEST['server_id'])) { $map['server_id'] = trim($_REQUEST['server_id']); unset($_REQUEST['server_id']); } if (isset($_REQUEST['game_type'])) { $map['sdk_version'] = trim($_REQUEST['game_type']); unset($_REQUEST['game_type']); } if (isset($_REQUEST['role_name'])) { $map['role_name'] = array('like','%'.trim($_REQUEST['role_name']).'%'); unset($_REQUEST['role_name']); } // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); if (isset($_REQUEST['promote_id'])) { $queryStr = ''; if ($_REQUEST['promote_id'] == 0) { $map['promote_id'] = '0'; } else { $queryStr = "chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}"; $promoter_ids = D("Promote")->where($queryStr)->field('id')->select(); $promoter_ids ? $map['promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))] : null; } } if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { $map['create_time'] = ['between', [strtotime(I('time_start')), strtotime(I('time_end')) + 86399]]; } elseif (isset($_REQUEST['time_start'])) { $map['create_time'] = ['GT', strtotime(I('time_start'))]; } elseif (isset($_REQUEST['time_end'])) { $map['create_time'] = ['LT', strtotime(I('time_end')) + 86399]; } $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum = M('user_play_info', 'tab_') ->where($map) ->order('play_time desc') ->count(); // $accessNum =$accessNum['count']; $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); $lastId = 0; for($i = 1; $i <= $pages; $i++) { $xlsData = M('user_play_info', 'tab_') ->field("create_time,user_account,game_name,server_id,server_name,role_id,role_name,role_level,promote_account,play_time,play_ip") ->where($map) ->limit(($i-1)*$perSize ,$perSize) ->order('play_time desc') ->select(); foreach($xlsData as $value) { $value['create_time'] = date("Y-m-d H:i:s",$value['create_time']); $value['play_time'] = date("Y-m-d H:i:s",$value['play_time']); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); $lastId = $value['id']; } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); break; case 2: $xlsName = $xlsName?$xlsName:"渠道注册"; // $xlsCell = array( // array('account', "玩家账号"), // array('fgame_name', "注册游戏"), // array('promote_account', L('Subordinate_channel')), // array('register_time', L('Registration_time'), 'time_format', '*'), // array('register_ip', L('Register_iP')), // array('parent_id', "上级推广员"), // array('ba_id', '商务专员'), // ); $xlsCell = array( "玩家账号", "注册游戏", L('Subordinate_channel'), L('Registration_time'), L('Register_iP'), "上级推广员", '商务专员', ); if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['fgame_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } $map['tab_user.promote_id'] = array("neq", 0); if (isset($_REQUEST['promote_name'])) { if ($_REQUEST['promote_name']=='全部') { unset($_REQUEST['promote_name']); } elseif ($_REQUEST['promote_name']=='自然注册') { $map['tab_user.promote_id']=array("elt",0); unset($_REQUEST['promote_name']); } else { $promoteid = get_promote_id($_REQUEST['promote_name']); $map['tab_user.promote_id']=array('eq',get_promote_id($_REQUEST['promote_name'])); unset($_REQUEST['promote_name']); if (isset($_REQUEST['parent_id'])) { $parent_id = get_promote_id($_REQUEST['parent_id']); if ($promoteid == $parent_id) { $map['tab_user.promote_id'] = $promoteid; } else { $parent_id = get_promote_id($_REQUEST['parent_id']); } } else { $map['tab_user.promote_id'] = $promoteid; } } } else { if (isset($_REQUEST['parent_id'])) { $parent_id = get_promote_id($_REQUEST['parent_id']); $pro = M('promote', 'tab_')->field('id,account')->where("chain like '%/{$parent_id}/%'")->select(); $pro_ids = array_column($pro, 'id'); $pro_ids[] = get_promote_id($_REQUEST['parent_id']); if (!empty($pro_ids)) { $map['tab_user.promote_id'] = ['in',$pro_ids]; } else { $map['tab_user.promote_id'] = array('eq',-1); } } } if (isset($_REQUEST['is_check']) && $_REQUEST['is_check'] != L('All')) { $map['is_check'] = check_status($_REQUEST['is_check']); unset($_REQUEST['is_check']); } if (isset($_REQUEST['account'])) { $map['tab_user.account'] = array('like', '%' . $_REQUEST['account'] . '%'); unset($_REQUEST['account']); } if(isset($_REQUEST['ba_id'])){ $map['ba_id'] = $_REQUEST['ba_id']; unset($_REQUEST['ba_id']); } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['register_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time_end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['register_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } //为数据权限添加 setPowerPromoteIds($map); $model = array( 'm_name' => 'User', 'join' => 'tab_promote ON tab_user.promote_id = tab_promote.id', 'fields' => array( 'tab_user.id', 'tab_user.account', 'tab_user.fgame_name', 'tab_user.nickname', 'tab_user.email', 'tab_user.phone', 'promote_id', 'tab_user.parent_id', 'tab_user.register_time', 'tab_user.register_way', 'tab_user.register_ip', 'promote_account', 'tab_user.parent_name', 'is_check', 'tab_promote.ba_id', "REPLACE(substring_index(tab_promote.chain, '/', 2),'/','') as top_promote" ), 'key' => array('tab_user.account', 'tab_game.fgame_name'), 'map' => $map, 'order' => 'id desc', 'title' => "渠道注册", 'template_list' => 'ch_reg_list', ); $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $name = $model['m_name']; $xlsData = M($name, "tab_",'union_table') ->field($model['fields']) ->join($model['join']) ->join($model['joins']) ->join($model['joinss']) ->where($model['map']) ->order($model['order']) ->group($model['group']) ->select(false); $accessNum = M()->table("({$xlsData}) as a") ->field("a.id,count(a.account) as count") ->join("left join tab_promote ON a.top_promote = tab_promote.id") ->join("left join tab_business_affairs ON tab_business_affairs.id=a.ba_id") ->order("id desc") ->find(); $accessNum =$accessNum['count']; $perSize = 2000;//每次查询的条数 $pages = ceil($accessNum / $perSize); $lastId = 0; // $xlsCell = array( // array('account', "玩家账号"), // array('fgame_name', "注册游戏"), // array('promote_account', L('Subordinate_channel')), // array('register_time', L('Registration_time'), 'time_format', '*'), // array('register_ip', L('Register_iP')), // array('parent_id', "上级推广员"), // array('ba_id', '商务专员'), // ); for($i = 1; $i <= $pages; $i++) { $xlsData = M($name, "tab_",'union_table') ->field($model['fields']) ->join($model['join']) ->join($model['joins']) ->join($model['joinss']) ->where($model['map']) ->limit(($i-1)*$perSize ,$perSize) ->order($model['order']) ->group($model['group']) ->select(false); $xlsData = M()->table("({$xlsData}) as a") ->field("a.account,a.fgame_name,a.promote_account,a.register_time,a.register_ip,tab_promote.account as parent_id,tab_business_affairs.account as ba_id") ->join("left join tab_promote ON a.top_promote = tab_promote.id") ->join("left join tab_business_affairs ON tab_business_affairs.id=a.ba_id") ->order("a.id desc") ->select(); foreach($xlsData as $value) { if (!$value['ba_id']) { $value['ba_id'] = "暂无"; } $value['register_time'] = date("Y-m-d H:i:s",$value['register_time']); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); $lastId = $value['id']; } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); break; case 3: if($_REQUEST['type']==2){ // $xlsCell = array( // array('id', L('Account_number_ID')), // array('register_type', L('Third_party_source'), "get_registertype", '*'), // array('account', "玩家账号"), // array('promote_account', L('Subordinate_channel')), // array('balance', "账户平台币"), // array('recharge_total', "累计充值"), // array('gold_coin', "金币"), // array('alipay', "绑定支付宝"), // array('small_count', "小号"), // array('vip_level', "VIP等级"), // array('register_time', L('Registration_time'), 'time_format', '*'), // array('login_time', "最后登录时间", 'time_format', '*'), // array('register_ip', L('Register_iP')), // array('lock_status', L('Account_status'), 'get_info_status', '*', '4'), // ); $field = 'a.id,a.register_type,a.account,a.promote_account,a.balance ,IFNULL(sum(ss.pay_amount),0) AS recharge_total,a.gold_coin,a.alipay,a.id as small_count, a.id as vip_level,register_time,a.login_time,a.register_ip,a.lock_status, a.age_status,a.register_way'; $xlsCell = [L('Account_number_ID'),L('Third_party_source'),"玩家账号",L('Subordinate_channel'), "账户平台币" , "累计充值", "金币", "绑定支付宝", "小号", "VIP等级", L('Registration_time'), "最后登录时间", L('Register_iP'), L('Account_status')]; $map['tab_user.register_type']= ['in','3,4,5,6']; }else{ // $xlsCell = array( // array('id', L('Account_number_ID')), // array('account', "玩家账号"), // array('promote_account', L('Subordinate_channel')), // array('balance', "账户平台币"), // array('recharge_total', "累计充值"), // array('gold_coin', "金币"), // array('alipay', "绑定支付宝"), // array('small_count', "小号"), // array('vip_level', "VIP等级"), // array('register_type', "注册方式"), // array('register_time', L('Registration_time'), 'time_format', '*'), // array('login_time', "最后登录时间", 'time_format', '*'), // array('register_ip', L('Register_iP')), // array('lock_status', L('Account_status'), 'get_info_status', '*', '4'), // ); $field = 'a.id,a.account,a.promote_account,a.balance, IFNULL(sum(ss.pay_amount),0) AS recharge_total,a.gold_coin,a.alipay ,a.id as small_count,a.id as vip_level,a.register_type,register_time,a.login_time ,a.register_ip,a.device_number,a.lock_status,check_status,a.age_status,a.register_way'; $xlsCell = [L('Account_number_ID'),"玩家账号",L('Subordinate_channel'), "账户平台币" , "累计充值", "金币", "绑定支付宝", "小号", "VIP等级", "注册方式", L('Registration_time'), "最后登录时间", L('Register_iP'), "设备号" ,L('Account_status'), "拉黑状态"]; $map['tab_user.register_type']=['in','1,2']; $map['tab_user.register_type']=['in','0,1,2,7']; } $hav = ''; // $promoteRoot = getPowerPromoteIds(); // if ($promoteRoot) { // $map['tab_user.promote_id'] =array('in',$promoteRoot); // } $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['tab_user.promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['tab_user.id'] = array('lt',1); // } setPowerPromoteIds($map,'tab_user.promote_id'); if ($_REQUEST['promote_id'] != '') { if($_REQUEST['promote_id']=='UC'){ $maps['tab_user.promote_account'] = 'UC用户'; $hav .= "tab_user.promote_account = 'UC用户' "; } else if ($_REQUEST['promote_id']==0) { $maps['tab_user.promote_id'] = 0; $hav .= "tab_user.promote_id = 0"; } else{ if ($promoteRoot) { $promoteRoot = " and id IN({$promoteRoot})"; } if ($promoteRoot == 'all') { $promoteRoot = ''; } $promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}.$promoteRoot")->field('id')->select(); if ($promoter_ids) { $map['tab_user.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))]; $hav .= "tab_user.promote_id in (" . implode(',', array_column($promoter_ids, 'id')) . ") "; $spendprom = " AND ss.promote_id IN (" . implode(',', array_column($promoter_ids, 'id')) . ") "; } } } if (I('type', 1) == 1) { if (isset($_GET['register_way'])) { if ($_GET['register_way'] == 1) { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in (1)'; $maps['tab_user.register_type'] = 1; } elseif ($_GET['register_way'] == 7) { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in(7)'; $maps['tab_user.register_type'] = 7; } else { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in(2)'; $maps['tab_user.register_type'] = 2; } } else { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in (1,2,7)'; $maps['tab_user.register_type'] = ['in', [1, 2, 7]]; } } else { if (isset($_GET['register_type'])) { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type = ' . $_GET['register_type']; $maps['tab_user.register_type'] = $_GET['register_type']; } else { empty($hav) || $hav .= ' AND '; $hav .= ' tab_user.register_type in (0,3,4,5,6)'; $maps['tab_user.register_type'] = ['in', [0, 3, 4, 5, 6]]; } } if (isset($_REQUEST['user_id'])) { empty($hav) || $hav .= ' AND '; $hav .= "tab_user.id = '{$_REQUEST['user_id']}'"; $maps['tab_user.id'] = $_REQUEST['user_id']; unset($_REQUEST['user_id']); } if (isset($_REQUEST['account'])) { empty($hav) || $hav .= ' AND '; $hav .= "tab_user.account like '%" . I('account') . "%'"; $maps['tab_user.account'] = ['like', "%" . I('account') . "%"]; unset($_REQUEST['account']); } if (isset($_REQUEST['device_number'])) { empty($hav) || $hav .= ' AND '; $hav .= "tab_user.device_number = '{$_REQUEST['device_number']}'"; $maps['tab_user.device_number'] = $_REQUEST['device_number']; unset($_REQUEST['device_number']); } if (isset($_REQUEST['age_status'])) { empty($hav) || $hav .= ' AND '; $hav .= 'tab_user.age_status =' . I('age_status'); $maps['tab_user.age_status'] = I('age_status'); unset($_REQUEST['age_status']); } if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { empty($hav) || $hav .= ' AND '; $hav .= 'tab_user.register_time BETWEEN ' . strtotime(I('time_start')) . ' AND ' . (strtotime(I('time_end')) + 24 * 60 * 60 - 1); $maps['tab_user.register_time'] = ['between', [strtotime(I('time_start')), strtotime(I('time_end')) + 86399]]; unset($_REQUEST['time_start']); unset($_REQUEST['time_end']); } elseif (isset($_REQUEST['time_start'])) { empty($hav) || $hav .= ' AND '; $hav .= 'tab_user.register_time > ' . strtotime(I('time_start')); $maps['tab_user.register_time'] = ['GT', strtotime(I('time_start'))]; unset($_REQUEST['time_start']); } elseif (isset($_REQUEST['time_end'])) { empty($hav) || $hav .= ' AND '; $hav .= 'tab_user.register_time < ' . (strtotime(I('time_end')) + 86399); $maps['tab_user.register_time'] = ['LT', strtotime(I('time_end')) + 86399]; unset($_REQUEST['time_end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { empty($hav) || $hav .= ' AND '; $hav .= 'tab_user.register_time BETWEEN ' . strtotime(I('start')) . ' AND ' . strtotime(I('end')); $maps['tab_user.register_time'] = array('between', [strtotime(I('start')), strtotime(I('end'))]); unset($_REQUEST['start']); unset($_REQUEST['end']); } if (!empty(I('line_day'))) { $day = strtotime(date('Y-m-d')) - intval(I('line_day')) * 86400; empty($hav) || $hav .= ' AND '; $hav .= $day . '> tab_user.login_time'; $maps['tab_user.login_time'] = ['lt', $day]; } if (isset($_REQUEST['status'])) { $map['lock_status'] = I('status'); unset($_REQUEST['status']); } $game_map = ""; if (isset($_REQUEST['game_name'])) { $game_map .= " and tab_user_play.game_id in (".implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')).")"; } $game_play_map = ''; if (isset($_REQUEST['server_name'])) { $game_play_map .= " and tab_user_play_info.server_name = '{$_REQUEST['server_name']}' "; } // if (isset($_REQUEST['promote_account'])) { // $map['promote_id'] = get_promote_id(trim(I('promote_account'))); // unset($_REQUEST['promote_account']); // } // if (isset($_REQUEST['register_way'])) { // if($_REQUEST['type']==1) { // if ($_GET['register_way'] == 1) { // empty($hav) || $hav .= ' AND '; // $hav .= ' tab_user.register_type in (0,1)'; // $maps['tab_user.register_type'] = ['in',[0,1]]; // } elseif($_GET['register_way'] == 7){ // empty($hav) || $hav .= ' AND '; // $hav .= ' tab_user.register_type in(7)'; // $maps['tab_user.register_type'] = 7; // }else { // empty($hav) || $hav .= ' AND '; // $hav .= ' tab_user.register_type in(2)'; // $maps['tab_user.register_type'] = 2; // } // } else { // // // $map['register_way'] = I('register_way'); // unset($_REQUEST['register_way']); // } // } // if (isset($_REQUEST['register_type'])) { // $map['register_type'] = I('register_type'); // unset($_REQUEST['register_type']); // } // if (isset($_REQUEST['status'])) { // $map['lock_status'] = $_REQUEST['status']; // unset($_REQUEST['status']); // } // $game_map = ""; // // if (isset($_REQUEST['game_name'])) { // $game_map .= " and tab_user_play.game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")"; // } // $game_play_map = ''; // if (isset($_REQUEST['server_name'])) { // $game_play_map .= " and tab_user_play_info.server_name = '{$_REQUEST['server_name']}' "; // } // empty(I('account')) || $map['account'] = ['like', '%' . I('account') . '%']; //排序 if (I('total_status') == 1) { $order = 'cumulative asc'; } elseif (I('total_status') == 2) { $order = 'cumulative desc'; } else { $order = 'id desc'; } if (isset($_REQUEST['viplevel'])) { $havs = get_vip_level_limit('recharge_total',$_REQUEST['viplevel']); } $map['puid'] = array('eq',0); $map['is_platform'] = 0; // var_dump($map);die(); set_time_limit(0); // $columns = [ // '序号ID', '姓名', '电话', // ]; $fileName = '导出.xlsx'; $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $usermodel = M('user', 'tab_'); $userField = "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"; $sql1 = $usermodel->field("{$userField},IFNULL(sum(b.pay_amount),0) as deposit_total") ->join('left join tab_deposit AS b ON tab_user.id = b.user_id AND b.pay_status = 1') ->where($hav) ->where($map) ->group('tab_user.id') // ->order($order) ->select(false); $accessNum = '100000';//从数据库获取总量,假设是十万 if($_REQUEST['promote_id'] && $_REQUEST['promote_id'] > -1){ $accessNum = $usermodel->table('(' . $sql1 . ') as a ') ->field('IFNULL(sum(ss.pay_amount),0) AS recharge_total,count(a.id) as count') // ->field($field) ->join('left join tab_spend as ss on ss.user_id=a.id AND ss.pay_status = 1'.$spendprom) ->join($game_map ? "tab_user_play on tab_user_play.user_id = a.id $game_map" : false) ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = a.id $game_play_map" : false) ->group('a.id') ->having($havs) ->select(false); $sql = "select count(t.count) as count from ({$accessNum}) as t "; $accessNum = M('user', 'tab_')->query($sql); }else{ $accessNum = $usermodel->table('(' . $sql1 . ') as a ') // ->field('tab_user.id,tab_user.age_status,tab_user.account,tab_user.gold_coin,tab_user.alipay,tab_user.balance,tab_user.promote_account,register_time,tab_user.lock_status,tab_user.register_way,tab_user.register_type,tab_user.register_ip,tab_user.login_time,IFNULL(sum(ss.pay_amount),0) AS recharge_total') ->field('IFNULL(sum(ss.pay_amount),0) AS recharge_total,count(a.id) as count') ->join('left join tab_spend as ss on ss.user_id=a.id AND ss.pay_status = 1') ->join($game_map ? "tab_user_play on tab_user_play.user_id = a.id $game_map" : false) ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = a.id $game_play_map" : false) ->group('a.id') ->having($havs) ->select(false); $sql = "select count(t.count) as count from ({$accessNum}) as t "; $accessNum = M('user', 'tab_')->query($sql); } $accessNum = $accessNum[0]['count']; $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); $lastId = 0; for($i = 1; $i <= $pages; $i++) { if($_REQUEST['promote_id'] && $_REQUEST['promote_id'] > -1){ $xlsData = $usermodel->table('(' . $sql1 . ') as a ') // ->field('tab_user.id,tab_user.age_status,tab_user.account,tab_user.gold_coin,tab_user.alipay,tab_user.balance,tab_user.promote_account,register_time,tab_user.lock_status,tab_user.register_way,tab_user.register_type,tab_user.register_ip,tab_user.login_time,IFNULL(sum(ss.pay_amount),0) AS recharge_total') ->field($field) ->join('left join tab_spend as ss on ss.user_id=a.id AND ss.pay_status = 1'.$spendprom) ->join($game_map ? "tab_user_play on tab_user_play.user_id = a.id $game_map" : false) ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = a.id $game_play_map" : false) ->limit(($i-1)*$perSize ,$perSize) ->group('a.id') ->order($order) ->having($havs) ->select(); }else{ $xlsData = $usermodel->table('(' . $sql1 . ') as a ') // ->field('tab_user.id,tab_user.age_status,tab_user.account,tab_user.gold_coin,tab_user.alipay,tab_user.balance,tab_user.promote_account,register_time,tab_user.lock_status,tab_user.register_way,tab_user.register_type,tab_user.register_ip,tab_user.login_time,IFNULL(sum(ss.pay_amount),0) AS recharge_total') ->field($field) ->join('left join tab_spend as ss on ss.user_id=a.id AND ss.pay_status = 1') ->join($game_map ? "tab_user_play on tab_user_play.user_id = a.id $game_map" : false) ->join($game_play_map ? "tab_user_play_info on tab_user_play_info.user_id = a.id $game_play_map" : false) ->limit(($i-1)*$perSize ,$perSize) ->group('a.id') ->order($order) ->having($havs) ->select(); } //数据 if($xlsData) { $ids = array_column($xlsData,'id'); /* 在手里 */ $small = M('user','tab_')->field('count(id) as count,puid')->where(['puid'=>array('in',$ids)])->group('puid')->select(); /* 出售中 */ $small2 = M('user','tab_')->field('count(id) as count,source_puid')->where(['source_puid'=>array('in',$ids),'source_time'=>0])->group('source_puid')->select(); foreach($xlsData as $k => $v) { $xlsData[$k]['vip_level'] = get_vip_level($v['recharge_total']); if(empty($v['alipay'])){ $xlsData[$k]['alipay'] = '--'; } $xlsData[$k]['register_time'] = date('Y-m-d H:i:s',$xlsData[$k]['register_time']); $xlsData[$k]['login_time'] = date('Y-m-d H:i:s',$xlsData[$k]['login_time']); $xlsData[$k]['device_number'] = encryption($xlsData[$k]['device_number']); $xlsData[$k]['lock_status'] = $xlsData[$k]['lock_status']==1?'正常':'锁定'; $xlsData[$k]['check_status'] = $xlsData[$k]['check_status']==1?'正常':'已拉黑'; $xlsData[$k]['register_type'] = $v['register_type'] == 2?'手机号':($v['register_type']==7?'邮箱':'账号'); $xlsData[$k]['small_count'] = 0; foreach($small as $s) { if($s['puid'] == $v['id']) { $xlsData[$k]['small_count'] += $s['count'];break; } } foreach($small2 as $s) { if($s['source_puid'] == $v['id']) { $xlsData[$k]['small_count'] += $s['count'];break; } } unset($xlsData[$k]['age_status']); unset($xlsData[$k]['register_way']); } } foreach($xlsData as $value) { mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); $lastId = $value['id']; } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); break; case 4: $xlsName = $xlsName?$xlsName:"渠道充值"; /* if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } if (!empty($_REQUEST['server_id'])) { $map['server_id'] = $_REQUEST['server_id']; unset($_REQUEST['server_id']); } if (isset($_REQUEST['promote_name'])) { if ($_REQUEST['promote_name'] == L('All')) { unset($_REQUEST['promote_name']); } else if ($_REQUEST['promote_name'] == "官方渠道") { $map['promote_id'] = array("lte", 0); unset($_REQUEST['promote_name']); } else { $map['promote_id'] = get_promote_id($_REQUEST['promote_name']); unset($_REQUEST['promote_name']); } } else { $map['promote_id'] = array("gt", 0); } if (isset($_REQUEST['pay_way'])) { $map['pay_way'] = $_REQUEST['pay_way']; unset($_REQUEST['pay_way']); } if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . $_REQUEST['user_account'] . '%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['spend_ip'])) { $map['spend_ip'] = array('like', '%' . $_REQUEST['spend_ip'] . '%'); unset($_REQUEST['spend_ip']); } if (isset($_REQUEST['promote_name'])) { $map['promote_account'] = $_REQUEST['promote_name']; unset($_REQUEST['user_account']); } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time_end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } */ if(isset($_REQUEST['game_name'])){ if($_REQUEST['game_name']=='全部'){ unset($_REQUEST['game_name']); }else{ $map['game_name']=$_REQUEST['game_name']; unset($_REQUEST['game_name']); } } if(!empty($_REQUEST['server_id'])){ $map['server_name']=$_REQUEST['server_id']; unset($_REQUEST['server_id']); } if(!empty($_REQUEST['pay_order_number'])){ $map['pay_order_number']=array('like','%'.$_REQUEST['pay_order_number'].'%'); unset($_REQUEST['pay_order_number']); } if(isset($_REQUEST['promote_name'])){ if($_REQUEST['promote_name']=='全部'){ unset($_REQUEST['promote_name']); }else if($_REQUEST['promote_name']=='自然注册'){ $map['promote_id']=array("lte",0); unset($_REQUEST['promote_name']); }else{ $map['promote_id']=get_promote_id($_REQUEST['promote_name']); unset($_REQUEST['promote_name']); } }else{ $map['promote_id']=array("gt",0); } if(isset($_REQUEST['pay_way'])){ $map['pay_way']=$_REQUEST['pay_way']; unset($_REQUEST['pay_way']); } if(isset($_REQUEST['user_account'])){ $map['user_account']=array('like','%'.$_REQUEST['user_account'].'%'); unset($_REQUEST['user_account']); } if(isset($_REQUEST['spend_ip'])){ $map['spend_ip']=array('like','%'.$_REQUEST['spend_ip'].'%'); unset($_REQUEST['spend_ip']); } if(isset($_REQUEST['promote_name'])){ $map['promote_account']=$_REQUEST['promote_name']; unset($_REQUEST['promote_name']); } if(isset($_REQUEST['time-start'])&&isset($_REQUEST['time-end'])){ $map['pay_time']=array('BETWEEN',array(strtotime($_REQUEST['time-start']),strtotime($_REQUEST['time-end'])+24*60*60-1)); unset($_REQUEST['time-start']);unset($_REQUEST['time_end']); }elseif(isset($_REQUEST['time-start'])){ $map['pay_time'] = ['GT',strtotime(I('time-start'))]; unset($_REQUEST['time-start']); }elseif(isset($_REQUEST['time-end'])){ $map['pay_time'] = ['LT',strtotime(I('time-end'))+86399]; unset($_REQUEST['time-end']); } if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['pay_time']=array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); }elseif(isset($_REQUEST['start'])){ $map['pay_time'] = ['GT',strtotime(I('start'))]; unset($_REQUEST['start']); }elseif(isset($_REQUEST['end'])){ $map['pay_time'] = ['LT',strtotime(I('end'))+86399]; unset($_REQUEST['end']); } if(!empty(I('parent_id'))){ $parent_id = I('parent_id'); $pro = M('promote','tab_')->field('id')->where("chain like '%/{$parent_id}/%'")->select(); $pro_ids = array_column($pro,'id'); $pro_ids[] = I('parent_id'); if (!empty($pro_ids)){ $map['promote_id'] = ['in',$pro_ids]; }else{ $map['promote_id'] = array('eq',999999999); } } if(isset($_REQUEST['ba_id'])){ $all_promote_id = array_column(get_admin_promotes($_REQUEST['ba_id'],'ba_id'),'id'); if(empty($all_promote_id)){ $all_promote_id[]=-1; } $map['promote_id']=array($map['promote_id'],array('in',implode(',',$all_promote_id)),'and'); } $model = array( 'm_name' => 'Spend', 'map' => $map, 'order' => 'id desc', 'title' => '渠道充值', 'template_list' => 'spend_list', ); $map1 = $map; $map1['pay_status'] = 1; $total = M('Spend', 'tab_')->where($map1)->sum('pay_amount'); $total = sprintf("%.2f", $total); $xlsCell = array( array('pay_order_number', "订单号"), array('pay_time', "充值时间", 'time_format', '*'), array('promote_account', L('Subordinate_channel')), array('parent_id', "上级推广员"), array('user_account', "玩家账号"), array('game_name', "游戏名称"), array('server_name', L('Game_area_clothing')), array('game_player_name', "角色名"), array('spend_ip', "充值ip"), array('pay_amount', "应付金额"), array('cost', "实付金额"), array('pay_way', "充值方式", 'get_info_status', '*', 18), array('promote_id', '商务专员', 'get_promote_business_account', '*'), array('is_check','对账状态','get_info_status','*','37') //array("", "共计充值{$total}"), ); $name = $model['m_name']; $xlsData = $data = D($name) ->where($map) ->order($model['order']) ->group($model['group']) ->select(); foreach ($xlsData as $key => &$value) { $xlsData[$key]['parent_id'] = get_top_promote($value['promote_id'], $value['parent_id']); } break; case 5: $map['promote_id'] = array("neq", 0); if (isset($_REQUEST['promote_id'])) { $map['_string'] = 'promote_id=' . $_REQUEST['promote_id']; } if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . $_REQUEST['user_account'] . '%'); unset($_REQUEST['user_account']); } if (!empty($_REQUEST['pay_way'])) { $map['pay_way'] = $_REQUEST['pay_way']; unset($_REQUEST['pay_way']); } if (isset($_REQUEST['promote_name'])) { if ($_REQUEST['promote_name'] == L('All')) { unset($_REQUEST['promote_name']); } else if ($_REQUEST['promote_name'] == "官方渠道") { $map['promote_id'] = array("elt", 0); unset($_REQUEST['promote_name']); } else { $map['promote_id'] = get_promote_id($_REQUEST['promote_name']); unset($_REQUEST['promote_name']); unset($_REQUEST['promote_id']); } } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time_end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } //为数据权限添加 setPowerPromoteIds($map); $map1 = $map; $map1['pay_status'] = 1; $total = M('Agent', 'tab_')->where($map1)->sum('amount'); $total = sprintf("%.2f", $total); $xlsName = $xlsName?$xlsName:"代充记录"; $xlsCell = array( array('promote_account', L('Subordinate_channel')), array('user_account', "玩家账号"), array('game_name', "游戏名称"), array('amount', '代充金额'), array('zhekou', '折扣比例'), array('real_amount', '实付金额'), array('pay_status', '充值状态', 'get_info_status', '*', '7'), array('pay_way', '支付方式'), array('create_time', '代充时间', 'time_format', '*'), array("", "共计代充{$total}"), ); $xlsData = D('Agent') ->where($map) ->order('id DESC') ->select(); foreach ($xlsData as $key=>$v){ $xlsData[$key]['pay_way'] = get_info_status($v['pay_way'],21); } break; case 6: if (isset($_REQUEST['account'])) { if ($_REQUEST['account'] == L('All')) { unset($_REQUEST['account']); } $map['account'] = array('like', '%' . $_REQUEST['account'] . '%'); unset($_REQUEST['account']); } $map['pay_limit'] = array('gt', '0'); $model = D('Promote'); $xlsData = $model ->where($map) ->select(); $xlsName = $xlsName?$xlsName:"代充额度"; $xlsCell = array( array('id', 'ID'), array('account', '推广员账号'), array('pay_limit_game', "游戏名称", 'get_game_limit_name', '*'), array('pay_limit', '代充额度'), array('set_pay_time', '更新时间', 'time_format', '*'), ); break; case 7: $startDate = empty($_REQUEST['timestart']) ? date('Y-m-d', strtotime('-6 day', time())) : $_REQUEST['timestart']; $endDate = empty($_REQUEST['timeend']) ? date('Y-m-d') : $_REQUEST['timeend']; $startTime = strtotime($startDate); $endTime = strtotime($endDate) + 86399; $map['pay_time'] = array('BETWEEN', array($startTime, $endTime)); unset($_REQUEST['timestart']); unset($_REQUEST['timeend']); if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', trim($_REQUEST['user_account'])); unset($_REQUEST['user_account']); } if (isset($_REQUEST['spend_ip'])) { $map['spend_ip'] = array('like', trim($_REQUEST['spend_ip']) . '%'); unset($_REQUEST['spend_ip']); } if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == '全部') { unset($_REQUEST['game_name']); } else { $map['game_id'] = ['in', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')]; unset($_REQUEST['game_name']); } } if (isset($_REQUEST['game_type']) && $_REQUEST['game_type']) { $map['sdk_version'] = $_REQUEST['game_type']; } if (isset($_REQUEST['server_id'])) { $map['server_id'] = $_REQUEST['server_id']; unset($_REQUEST['server_id']); } if (isset($_REQUEST['pay_order_number'])) { $map['pay_order_number'] = array('like', trim($_REQUEST['pay_order_number'])); unset($_REQUEST['pay_order_number']); } if (isset($_REQUEST['extend'])) { $map['extend'] = array('like', trim($_REQUEST['extend'])); unset($_REQUEST['extend']); } if (isset($_REQUEST['pay_status'])) { $map['pay_status'] = $_REQUEST['pay_status']; unset($_REQUEST['pay_status']); } if (isset($_REQUEST['pay_way'])) { if ($_REQUEST['pay_way'] == 2) { $map['pay_way'] = ['in', '2,3,4']; } else { $map['pay_way'] = $_REQUEST['pay_way']; } unset($_REQUEST['pay_way']); } if (isset($_REQUEST['pay_game_status'])) { $map['pay_game_status'] = $_REQUEST['pay_game_status']; unset($_REQUEST['pay_game_status']); } // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); if (isset($_REQUEST['promote_id'])) { $promoteId = intval($_REQUEST['promote_id']); if ($promoteId == 0) { $map['promote_id'] = 0; } else { $promoteMap['chain'] = ['like', "%/$promoteId/%"]; $promoteIds = M('Promote', 'tab_')->where($promoteMap)->getField('id', true); $promoteIds[] = $promoteId; $map['promote_id'] = ['in', $promoteIds]; } } if ($_REQUEST['data_order'] != '') { $data_order = reset(explode(',', $_REQUEST['data_order'])); $data_order_type = end(explode(',', $_REQUEST['data_order'])); $this->assign('userarpu_order', $data_order); $this->assign('userarpu_order_type', $data_order_type); $sort = $data_order == 3 ? 'desc' : 'asc'; $order = $data_order_type . ' ' . $sort; } else { $order = ' pay_time desc '; } // if (intval(($endTime + 1) - $startTime) / (24 * 3600) <= 31) { // $map1 = $map; // $map1['pay_status'] = 1; // } else { // $map = '1 = 2'; // $map1 = $map; // } $map1 = $map; $map1['pay_status'] = 1; $total = M('Spend','tab_')->where($map1)->sum('pay_amount'); // var_dump($total);die(); $total=$total?$total:0; $xlsCell = array( "支付订单号","CP订单号", "充值时间", "玩家账号", "游戏名称", L('Subordinate_channel'), "充值ip","区服ID", "游戏区服", "角色ID","角色名称", "订单金额", "实付金额", "充值方式", L('Order_status'), "游戏通知状态", "消费"."{$total}" ); $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum = D('Spend') ->where($map) ->count(); $perSize = 10000;//每次查询的条数 $pages = ceil($accessNum / $perSize); // var_dump($count);die(); for($i = 1; $i <= $pages; $i++) { $xlsData = D('Spend') // ->field('pay_order_number,extend,pay_time,user_account,game_name,promote_account,spend_ip,server_id,server_name,game_player_id,game_player_name,cost,pay_amount,pay_way,pay_status,pay_game_status') // ->where($map) // ->limit(($i-1)*$perSize ,$perSize) // ->join($tab_promote_join) // ->order('pay_time DESC') // ->select(); ->field('pay_order_number,extend,pay_time,user_account,game_name,promote_account,spend_ip,server_id,server_name,game_player_id,game_player_name,cost,pay_amount,pay_way,pay_status,pay_game_status') ->where($map) ->limit(($i-1)*$perSize ,$perSize) ->order($order ? $order : 'pay_time desc') ->select(); foreach($xlsData as $value) { $value['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']); $value['extend'] = $value['extend'].'`'; $value['pay_way'] = get_pay_way($value['pay_way']); $value['pay_status'] = get_info_status($value['pay_status'],9); $value['pay_game_status'] = get_info_status($value['pay_game_status'],14); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); // $xlsCell = array( // array('pay_order_number', "订单号"), // array('pay_time', "充值时间", 'time_format', '*'), // array('user_account', "玩家账号"), // array('game_name', "游戏名称"), // array('promote_account', L('Subordinate_channel')), // array('spend_ip', "充值ip"), // array('server_name', "游戏区服"), // array('game_player_name', "角色名称"), // array('cost', "订单金额"), // array('pay_amount', "实付金额"), // array('pay_way', "充值方式", 'get_pay_way', '*'), // array('pay_status', L('Order_status'), 'get_info_status', '*', '9'), // array('pay_game_status', "游戏通知状态", 'get_info_status', '*', '14'), // array('', "消费"."{$total}") // ); break; case 8: $xlsName = $xlsName?$xlsName:L('Platform_currency_recharge'); if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . trim($_REQUEST['user_account']) . '%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['pay_order_number'])) { $map['pay_order_number'] = array('like', '%' . trim($_REQUEST['pay_order_number']) . '%'); unset($_REQUEST['pay_order_number']); } if (isset($_REQUEST['pay_ip'])) { $map['pay_ip'] = array('like', '%' . trim($_REQUEST['pay_ip']) . '%'); unset($_REQUEST['pay_ip']); } // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); if (!isset($_REQUEST['promote_id'])) { } else if (isset($_REQUEST['promote_id']) && $_REQUEST['promote_id'] == 0) { $map['promote_id'] = array('elt', 0); unset($_REQUEST['promote_id']); unset($_REQUEST['promote_name']); } elseif (isset($_REQUEST['promote_name']) && $_REQUEST['promote_id'] == -1) { $map['promote_id'] = get_promote_id($_REQUEST['promote_name']); unset($_REQUEST['promote_id']); unset($_REQUEST['promote_name']); } else { $map['promote_id'] = $_REQUEST['promote_id']; unset($_REQUEST['promote_id']); unset($_REQUEST['promote_name']); } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time-end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } if (isset($_REQUEST['pay_way'])) { $map['pay_way'] = $_REQUEST['pay_way']; unset($_REQUEST['pay_way']); } if (isset($_REQUEST['pay_status'])) { $map['pay_status'] = $_REQUEST['pay_status']; unset($_REQUEST['pay_status']); } $map1 = $map; $map1['pay_status'] = 1; $total = D('Deposit')->where($map1)->sum('pay_amount'); if (isset($map['pay_status']) && $map['pay_status'] == 0) { $total = sprintf("%.2f", 0); } else { $total = sprintf("%.2f", $total); } $xlsCell = array( array('pay_order_number', "订单号"), array('user_account', "玩家账号"), array('promote_account', L('Subordinate_channel')), array('pay_amount', "充值平台币"), array('pay_way', "充值方式", 'get_pay_way', '*'), array('pay_ip', "充值ip"), array('create_time', "充值时间"), array('pay_status', L('Order_status'), 'get_info_status', '*', '9'), array('', "共计充值{$total}"), ); $xlsData = D('Deposit') ->where($map) ->order('id DESC') ->select(); foreach ($xlsData as $key => $value) { $xlsData[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']); } // dd($xlsData); break; case 9: $xlsName = $xlsName?$xlsName:"平台币发放"; if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . trim($_REQUEST['user_account']) . '%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time-end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } $game_ids = array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['sdk_version1']), 'id'); if ($game_ids) { $map['game_id'] = ['in', $game_ids]; unset($_REQUEST['game_name'], $_REQUEST['sdk_version1']); } $map['op_account']=session('user_auth')['username']; if (isset($_REQUEST['op_account'])) { if ($_REQUEST['op_account'] == L('All')) { unset($_REQUEST['op_account']); } else { $map['op_account'] = $_REQUEST['op_account']; unset($_REQUEST['op_account']); } } $map1 = $map; $map1['status'] = 1; $total = M('provide', 'tab_')->where($map1)->sum('amount'); $total = sprintf("%.2f", $total); $xlsData = M('provide', 'tab_') ->where($map) ->order('id DESC') ->select(); $xlsCell = array( array('pay_order_number', "订单号"), array('user_account', "玩家账号"), array('game_name', "游戏名称"), array('amount', "发放数量"), array('status', "状态", 'get_info_status', '*', '15'), array('op_account', L('Operator')), array('create_time', "发放时间", 'time_format', '*'), array('', "共计发放{$total}"), ); break; case 10: $xlsName = $xlsName?$xlsName:"绑定平台币消费"; if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . trim($_REQUEST['user_account']) . '%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['pay_order_number'])) { $map['pay_order_number'] = array('like', '%' . trim($_REQUEST['pay_order_number']) . '%'); unset($_REQUEST['pay_order_number']); } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time-end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; } unset($_REQUEST['game_name']); } if (isset($_REQUEST['server_name'])) { if ($_REQUEST['server_name'] == L('All')) { unset($_REQUEST['server_name']); } else { $map['server_name'] = $_REQUEST['server_name']; unset($_REQUEST['server_name']); } } $map1 = $map; $map1['pay_status'] = 1; $total = D('BindSpend')->where($map1)->sum('pay_amount'); $total = sprintf("%.2f", $total); $xlsCell = array( array('pay_order_number', "订单号"), array('pay_time', "充值时间", 'time_format', '*'), array('user_account', "玩家账号"), array('game_name', "游戏名称"), array('server_name', L('Game_area_clothing')), array('game_player_name', "角色名"), array('spend_ip', "充值ip"), array('pay_amount', "充值金额"), array('pay_status', L('Order_status'), 'get_info_status', '*', '9'), array('pay_game_status', '游戏通知状态', 'get_info_status', '*', '14'), array('', "共计使用{$total}") ); $xlsData = D('BindSpend') ->where($map) ->order('pay_time DESC,id DESC') ->select(); break; case 11: $xlsName = $xlsName?$xlsName:"礼包领取"; // $xlsCell = array( // array('user_account', "玩家账号"), // array('game_name', "游戏名称"), // array('gift_name', '礼包名称'), // array('novice', '礼包卡号'), // array('gift_id', '运营平台', 'get_operation_platform', '*', 'giftbag'), // array('create_time', '领取时间', 'time_format', '*'), // ); $xlsCell = array( "玩家账号", "游戏名称", '礼包名称', '礼包卡号', '运营平台', '领取时间', ); if (isset($_REQUEST['game_name'])) { $extend['tab_gift_record.game_name'] = trim($_REQUEST['game_name']); unset($_REQUEST['game_name']); } if (isset($_REQUEST['user_account'])) { $extend['tab_gift_record.user_account'] = trim($_REQUEST['user_account']); unset($_REQUEST['user_account']); } if (isset($_REQUEST['sdk_version'])) { if ($_REQUEST['sdk_version'] == '') { unset($_REQUEST['sdk_version']); } else { $map['sdk_version'] = $_REQUEST['sdk_version']; $game_ids = M('game', 'tab_')->field('id')->where($map)->select(); $game_ids = array_column($game_ids, 'id'); $extend['tab_gift_record.game_id'] = ['in', $game_ids]; unset($_REQUEST['sdk_version']); } } // var_dump($extend);die(); $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum = M('gift_record', 'tab_') ->field("user_account,game_name,gift_name,novice,gift_id,FROM_UNIXTIME(create_time) as create_time") ->where($extend) ->order("id DESC") ->count(); $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); // var_dump($count);die(); for($i = 1; $i <= $pages; $i++) { $xlsData = M('gift_record', 'tab_') ->field("tab_gift_record.user_account,tab_gift_record.game_name,tab_gift_record.gift_name,tab_gift_record.novice,giftbag_version,FROM_UNIXTIME(tab_gift_record.create_time) as create_time") ->join("left join tab_giftbag on tab_gift_record.gift_id = tab_giftbag.id") ->where($extend) ->limit(($i-1)*$perSize ,$perSize) ->order("tab_gift_record.id DESC") ->select(); foreach($xlsData as $value) { if($value['giftbag_version']==0){ $value['giftbag_version']= '双平台'; }elseif($value['giftbag_version']==1){ $value['giftbag_version']= "安卓"; }elseif($value['giftbag_version']==2){ $value['giftbag_version']= "苹果"; } else { $value['giftbag_version']= ""; } // $value['gift_id'] = get_operation_platform($value['gift_id'],'giftbag'); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); break; case 12: get_info_status(); $xlsName = $xlsName?$xlsName:"推广员提现"; $xlsCell = array( array('settlement_number', '提现单号'), array('sum_money', '提现金额'), array('promote_id', '推广员账号'), array('create_time', '申请时间', 'time_format', '*'), array('status', '提现状态', 'get_info_status', '*', 19), array('end_time', '审核时间', 'time_format', '*'), array('withdraw_type', '打款方式' ,'get_info_status', '*', 36), ); if (isset($_REQUEST['settlement_number'])) { $map['settlement_number'] = $_REQUEST['settlement_number']; } if (isset($_REQUEST['status'])) { $map['status'] = $_REQUEST['status']; } if (isset($_REQUEST['promote_account'])) { if ($_REQUEST['promote_account'] == L('All')) { unset($_REQUEST['promote_account']); } else { $map['promote_account'] = $_REQUEST['promote_account']; } } //为数据权限添加 setPowerPromoteIds($map); if ($_REQUEST['create_time'] == 2) { $order = 'create_time desc'; } elseif ($_REQUEST['create_time'] == 1) { $order = 'create_time asc'; } if ($_REQUEST['sum_money'] == 2) { $order = 'sum_money desc'; } elseif ($_REQUEST['sum_money'] == 1) { $order = 'sum_money asc'; } $model = array( 'm_name' => 'withdraw', 'order' => $order, 'title' => '推广员提现', 'template_list' => 'withdraw', ); $name = $model['m_name']; $xlsData = D($name) ->where($map) ->order($model['order']) ->select(); break; case 14: $xlsName = $xlsName?$xlsName:"游戏返利"; $xlsCell = array( array('pay_order_number', "订单号"), array('create_time', '返利时间', 'time_foramt', '*'), array('user_id', "玩家账号", 'get_user_account', '*'), array('promote_id', "所属推广员", 'get_promote_name', '*'), array('game_name', "游戏名称"), array('pay_amount', "充值金额"), array('ratio', '返利比例', 'ratio_stytl', '*'), array('ratio_amount', '返利绑币'), ); if (isset($_REQUEST['user_account'])) { $map['user_name'] = array('like', '%' . trim($_REQUEST['user_account']) . '%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } $xlsData = M('RebateList', 'tab_') ->where($map) ->order('id DESC') ->select(); break; case 15: $xlsName = $xlsName?$xlsName:"推广结算"; $xlsCell = array( array('promote_account', '推广员账号'), array('settlement_cycle', '结算周期',), array('settlement_number', "结算单号"), array('total_money', '总充值'), array('total_number', '总注册'), array('sum_money', '结算金额'), array('bind_coin_status','结算范畴','get_bind_coin_status','*'), array('create_time', '结算时间', 'time_format', '*'), ); if (isset($_REQUEST['promote_account'])) { $map['promote_account'] = array('like', '%' . trim($_REQUEST['promote_account']) . '%'); unset($_REQUEST['promote_account']); } if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == L('All')) { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } //为数据权限添加 setPowerPromoteIds($map); $xlsData = M('settlement', 'tab_') ->field(array( 'settlement_number', 'starttime','endtime', 'promote_id','promote_account', 'sum(total_money) as total_money', 'sum(total_number) as total_number', 'sum(sum_money) as sum_money', 'bind_coin_status', 'create_time')) ->where($map) ->group('promote_id,starttime,endtime,create_time,bind_coin_status') ->order('create_time DESC') ->select(); foreach ($xlsData as $key=>$v){ $xlsData[$key]['settlement_cycle'] = date('Y-m-d',$v['starttime'])."-".$v['endtime']; } break; case 16: $xlsName = $xlsName?$xlsName:"给玩家发放"; $xlsCell = array( array('pay_order_number', "订单号"), array('user_account', "玩家账号"), array('type', "发放类型"), array('amount', "发放数量"), array('status', "状态", 'get_info_status', '*', '15'), array('op_account', '操作人员'), array('create_time', '发放时间', 'time_format', '*'), ); if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . trim($_REQUEST['user_account']) . '%'); } if (isset($_REQUEST['op_id'])) { $map['op_id'] = $_REQUEST['op_id']; } $map['op_account']=session('user_auth')['username']; if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); } $xlsData = M('provide_user', 'tab_')->field('*,"平台币" as type') ->where($map) ->order('id DESC') ->select(); break; case 17: $xlsCell = array( array('id', "ID"), array('account', "开发者账号"), array('nickname', "开发者名称"), array('xingzhi', "账号性质"), array('nature', '属性','get_developer_type', '*'), array('link_man', '联系人'), array('mobile_phone', '手机号码'), array('create_time', '注册时间', 'time_format', '*'), array('last_login_time', '最后登录时间'), array('status', '状态','get_info_status', '*', '35'), ); if(isset($_GET['account'])){ $map['account']=I('get.account'); } if(isset($_GET['status'])){ $map['status']=I('get.status'); } if (isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1)); unset($_REQUEST['timestart']); unset($_REQUEST['timeend']); } $xlsData = M('Developers', 'tab_') ->field('id,account,nickname,nature,link_man,mobile_phone,create_time,last_login_time,status,"开发者" as "xingzhi"') ->where($map) ->order('id DESC') ->select(); foreach($xlsData as $k => $v) { $xlsData[$k]['last_login_time'] = $v['last_login_time']>0?date('Y-m-d H:i',$v['last_login_time']):'暂无登录'; $xlsData[$k]['mobile_phone'] = $v['mobile_phone']?$v['mobile_phone']:'空'; $xlsData[$k]['link_man'] = $v['link_man']?$v['link_man']:'空'; $xlsData[$k]['nickname'] = $v['nickname']?$v['nickname']:'空'; } break; case 18: $xlsName = $xlsName?$xlsName:"开发者结算"; $xlsCell = array( array('id', "ID"), array('timestart', "月份"), array('developers', "CP方"), array('game_name', "游戏名称"), array('total', '总充值'), array('selle_ratio', '分成比例'), array('ratio_money', '结算金额'), array('selle_status', '状态'), ); if($_REQUEST['sum_money']==2){ $order='pay_amount desc'; }else if($_REQUEST['sum_money']==1){ $order='pay_amount asc'; } if(isset($_REQUEST['timestart'])&&$_REQUEST['timestart']!=''&&$_REQUEST['group']==1){ $starttime = strtotime($_REQUEST['timestart']); $endtime = strtotime($_REQUEST['timeend'])+24*3600-1; if(isset($_REQUEST['developers_id'])){ $map['g.developers'] = $_REQUEST['developers_id']; }else{ $this->error('请选择开发者'); } if(isset($_REQUEST['selle_status'])){ if($_REQUEST['selle_status']=="未结算"){ $map['s.selle_status']=0; }else if($_REQUEST['selle_status']=="已结算"){ $map['s.selle_status']=1; } } //判断是否结算绑币 if($_REQUEST['bind_coin'] == 0){ $map['s.pay_way'] = array('neq',-1); } $map['s.pay_status']=1; $map['pay_time']=array('BETWEEN',array($starttime,$endtime)); $model = array( 'm_name' => 'Spend as s', 'order' => $order, 'title' => '渠道结算', 'group' => 'g.developers,g.id', 'fields' => 'sum(s.pay_amount) as total,s.selle_ratio,s.id,g.developers,s.selle_status,g.id as gid,g.game_name,s.pay_status,s.pay_amount', 'template_list' =>'cpsettlement', ); $fields = $model['fields']; //读取模型数据列表 $name = $model['m_name']; // var_dump($fields);exit; $new_model = M($name,'tab_'); $data = $new_model ->field($fields.",g.developers") // 查询条件 ->where($map) /* 默认通过id逆序排列 */ ->order($model['order']) ->join('tab_game as g on g.id=s.game_id','LEFT') //根据字段分组 ->group($model['group']) /* 数据分页 */ ->order($model['order']) /* 执行查询 */ ->select(); foreach ($data as $key => $value){ $data[$key]['timestart'] = I('timestart'); $data[$key]['developers'] = get_developers_account($data[$key]['developers'],'account'); $data[$key]['ratio_money'] = $data[$key]['total']*$data[$key]['selle_ratio']/100; $data[$key]['selle_status'] = $data[$key]['selle_status'] == 0 ? "未结算" : "已结算"; } $xlsData = $data; } break; case 19: $xlsCell = array( array('developers', "开发者账号"), array('settlement_number', "结算单号"), array('starttime', "周期开始时间",'time_format','*'), array('endtime', "周期结束时间",'time_format','*'), array('total_money', '总充值(元)'), array('sum_money', '结算金额(元)'), array('bind_coin_status','结算范围','get_bind_coin_status','*'), array('create_time', "结算时间",'time_format','*'), ); if(isset($_REQUEST['timestart']) && $_REQUEST['timeend']!=''){ $starttime = strtotime($_REQUEST['timestart']); $endtime = strtotime($_REQUEST['timeend'])+24*3600-1; $map['starttime'] = array('egt',$starttime); $map['endtime'] = array('elt',$endtime); }elseif(isset($_REQUEST['timestart'])){ $starttime = strtotime($_REQUEST['timestart']); $map['starttime'] = array('egt',$starttime); }elseif(isset($_REQUEST['timeend'])){ $endtime = strtotime($_REQUEST['timeend'])+24*3600-1; $map['endtime'] = array('elt',$endtime); } if(isset($_REQUEST['start']) && $_REQUEST['end']!=''){ $starttime = strtotime($_REQUEST['start']); $endtime = strtotime($_REQUEST['end'])+24*3600-1; $map['create_time'] = array('BETWEEN',array($starttime,$endtime)); }elseif(isset($_REQUEST['start'])){ $starttime = strtotime($_REQUEST['start']); $map['create_time'] = array('BETWEEN',array($starttime,time())); }elseif(isset($_REQUEST['end'])){ $endtime = strtotime($_REQUEST['end'])+24*3600-1; $map['create_time'] = array('LT',$endtime); } if(isset($_REQUEST['developers_id'])){ $map['developers']=$_REQUEST['developers_id']; }else{ $map['developers'] = array('neq',0); } $data = M('TotalSettlement','tab_')->where($map)->select(); foreach ($data as $key => $value){ $data[$key]['developers'] = get_developers_account($data[$key]['developers'],'account'); } $xlsData = $data; break; case 20: $xlsCell = array( array('settlement_number', '提现单号'), array('sum_money', '提现金额'), array('developers', '开发者账号'), array('create_time', '申请时间', 'time_format', '*'), array('status', '提现状态', 'get_info_status', '*', 19), array('end_time', '审核时间', 'time_format', '*'), ); if(isset($_REQUEST['settlement_number'])){ $map['settlement_number']=array('like','%'.$_REQUEST['settlement_number'].'%'); } if(isset($_REQUEST['status'])){ $map['status']=$_REQUEST['status']; } if(isset($_REQUEST['developers'])){ if($_REQUEST['developers']=='全部'){ unset($_REQUEST['developers']); }else{ $map['developers'] = $_REQUEST['developers']; } }else{ $map['developers'] = array('neq',0); } if(isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])){ $starttime = strtotime($_REQUEST['timestart']); $endtime = strtotime($_REQUEST['timeend'])+24*3600-1; $map['audit_time'] = array('BETWEEN',array($starttime,$endtime)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); }elseif(isset($_REQUEST['timestart'])){ $map['audit_time'] = ['GT',strtotime(I('timestart'))]; unset($_REQUEST['timestart']); }elseif(isset($_REQUEST['timeend'])){ $map['audit_time'] = ['LT',strtotime(I('timeend'))+86399]; unset($_REQUEST['timeend']); } if($_REQUEST['create_time']==2){ $order='create_time desc'; }elseif($_REQUEST['create_time']==1){ $order='create_time asc'; }else{ $order='create_time desc'; } if($_REQUEST['data_order']==3){ $order='sum_money desc'; }elseif($_REQUEST['data_order']==4){ $order='sum_money asc'; } $xlsData = D('withdraw') ->where($map) ->order($order) ->select(); foreach ($xlsData as $key => $value){ $xlsData[$key]['developers'] = get_developers_account($value['developers'],'account'); } break; case 21: $xlsCell = array( array('extend', 'CP订单号'), array('create_time', '充值时间'), array('user_account', '玩家账号'), array('game_name', '游戏名称'), array('server_name', '游戏区服'), array('promote_account', '所属推广员'), array('game_player_id', '角色ID'), array('game_player_name', '角色名称'), array('price', '订单金额'), ); $params = I('get.'); $map = []; if (isset($params['user_account'])) { $map['user_account'] = $params['user_account']; } if (isset($params['extend'])) { $map['extend'] = $params['extend']; } if (isset($params['game_name'])) { $game_id = ['in', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')]; $map['game_id'] = $game_id; } if (isset($params['server_name'])) { $map['server_name'] = $params['server_name']; } if (isset($params['user_nickname'])) { $map['user_nickname'] = $params['user_nickname']; } if (isset($params['game_player_id'])) { $map['game_player_id'] = $params['game_player_id']; } $startDate = empty($params['timestart']) ? date('Y-m-d', strtotime('-6 day', time())) : $params['timestart']; $endDate = empty($params['timeend']) ? date('Y-m-d') : $params['timeend']; $startTime = strtotime($startDate); $endTime = strtotime($endDate) + 86399; $map['create_time'] = array('BETWEEN', [$startTime, $endTime]); // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); if ($promoteId = I('promote_id')) { if ($promoteId == 0) { $map['promote_id'] = 0; } else { $promoteMap['chain'] = ['like', "%/$promoteId/%"]; $promoteIds = M('Promote', 'tab_')->where($promoteMap)->getField('id', true); $promoteIds[] = $promoteId; $map['promote_id'] = ['in', $promoteIds]; } } $xlsData = M('pay_info', 'tab_')->where($map)->order('id DESC')->select(); foreach($xlsData as $k => $v) { $xlsData[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']); } break; $startDate = empty($params['timestart']) ? date('Y-m-d', strtotime('-6 day', time())) : $params['timestart']; $endDate = empty($params['timeend']) ? date('Y-m-d') : $params['timeend']; $startTime = strtotime($startDate); $endTime = strtotime($endDate) + 86399; $map['create_time'] = array('BETWEEN', [$startTime, $endTime]); if ($promoteId = I('promote_id')) { if ($promoteId == 0) { $map['promote_id'] = 0; } else { $promoteMap['chain'] = ['like', "%/$promoteId/%"]; $promoteIds = M('Promote', 'tab_')->where($promoteMap)->getField('id', true); $promoteIds[] = $promoteId; $map['promote_id'] = ['in', $promoteIds]; } } $xlsData = M('pay_info', 'tab_')->where($map)->order('id DESC')->select(); foreach($xlsData as $k => $v) { $xlsData[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']); } break; case 22: $xlsCell = array( array('game_name', '游戏'), array('authorization_num', '已授权游戏数量'), array('pay_game_supersign', '超级签被购买数量'), array('promote_super_money', '推广超级签金额'), array('official_super_money', '官方超级签金额'), ); $params = I('get.'); if(isset($params['timestart']) && isset($params['timeend'])) { $startTime = strtotime($params['timestart']); $endTime = strtotime($params['timeend']) + 86399; $map['pay_time'] = array('BETWEEN', [$startTime, $endTime]); } if(isset($params['game_id'])) { $map['tab_game.id'] = $params['game_id']; } $map['supersign_token'] = ['NEQ','']; $supersign_game = M('game', 'tab_')->field('tab_game.id,tab_game.game_name,tab_game.supersign_token')->join('tab_game_supersign on tab_game_supersign.game_id = tab_game.id')->where($map)->group('tab_game.id')->page($page,$row)->select(); $xlsData = []; $count['authorization'] = 0; $count['pay_num'] = 0; $count['promote_super_money'] = 0; $count['official_super_money'] = 0; foreach($supersign_game as $k => $v) { $arr['game_name'] = $v['game_name']; $re_data = []; $curl['token'] = $v['supersign_token']; $curl['limit'] = 2000; for ($i = 1;$i > 0;$i++) { if($i != 1) { $pop = array_pop($data); $curl['lastid'] = $pop['id']; } $curl_re = json_decode(curl_post('https://app.ipa365.com/Kirin/OpenApi/TicketList',$curl),true); if($curl_re['errno'] == 0) { $data = $curl_re['data']['list']; $re_data = array_merge($re_data,$data); } else { break; } if(count($data) != $curl['limit']) { break; } } $arr['authorization_num'] = count($re_data); if(isset($params['timestart']) && isset($params['timeend'])) { $startTime = strtotime($params['timestart']); $endTime = strtotime($params['timeend']) + 86399; $where['pay_time'] = array('BETWEEN', [$startTime, $endTime]); } $where['game_id'] = $v['id']; $where['pay_status'] = 1; $game_supersign = M('game_supersign', 'tab_')->field('promote_id,pay_price')->join('tab_user on tab_game_supersign.user_id = tab_user.id')->where($where)->select(); $arr['pay_game_supersign'] = count($game_supersign); $arr['promote_super_money'] = 0; $arr['official_super_money'] = 0; foreach($game_supersign as $key => $val) { if($val['promote_id'] != 0) { $arr['promote_super_money'] += $val['pay_price']; }else { $arr['official_super_money'] += $val['pay_price']; } } $xlsData[] = $arr; } break; case 23: $params = I('get.'); $map['tab_game_supersign.pay_status'] = 1; if (isset($params['order_id'])) { $map['tab_game_supersign.order_id'] = $params['order_id']; } if (isset($params['pay_way'])) { $map['tab_game_supersign.pay_way'] = $params['pay_way']; } if (isset($params['account'])) { $map['tab_user.account'] = $params['account']; } if (isset($params['promote_id'])) { $promoteId = $params['promote_id']; if ($promoteId == 0) { $map['promote_id'] = 0; } else { $promoteMap['chain'] = ['like', "%/$promoteId/%"]; $promoteIds = M('Promote', 'tab_')->where($promoteMap)->getField('id', true); $promoteIds[] = $promoteId; $map['tab_user.promote_id'] = ['in', $promoteIds]; } } if(isset($params['timestart']) && isset($params['timeend'])) { $startTime = strtotime($params['timestart']); $endTime = strtotime($params['timeend']) + 86399; $map['tab_game_supersign.pay_time'] = array('BETWEEN', [$startTime, $endTime]); } if(isset($params['game_id'])) { $map['tab_game_supersign.game_id'] = $params['game_id']; } $xlsCell = array( array('order_id', '订单号'), array('account', '游戏账号'), array('promote_account', '所属推广员'), array('device_number', '设备号'), array('game_name', '游戏'), array('pay_time', '购买时间'), array('pay_way', '支付方式'), array('pay_price', '超级签金额'), ); $xlsData = M('game_supersign', 'tab_')->field('tab_game_supersign.id,tab_game_supersign.pay_price,tab_game_supersign.pay_way,tab_game_supersign.order_id,tab_user.account,tab_user.promote_account,tab_user.device_number,tab_game.game_name,tab_game_supersign.pay_time')->join('tab_user on tab_game_supersign.user_id = tab_user.id')->join('tab_game on tab_game_supersign.game_id = tab_game.id')->where($map)->order('id DESC')->select(); foreach($xlsData as $k => $v) { $xlsData[$k]['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']); if($v['pay_way'] == 0) { $xlsData[$k]['pay_way'] = '未知'; }elseif ($v['pay_way'] == 1) { $xlsData[$k]['pay_way'] = '支付宝'; }elseif ($v['pay_way'] == 2) { $xlsData[$k]['pay_way'] = '微信'; } } break; case 24: $xlsCell = array( array('authorization_all_num', '已授权游戏总数'), array('buy_num', '超级签被购买数量'), array('money_all', '超级签金额合计'), ); $params = I('get.'); $startDate = empty($params['timestart']) ? '': $params['timestart']; $endDate = empty($params['timeend']) ? '' : $params['timeend']; $startTime = strtotime($startDate); $endTime = strtotime($endDate) + 86399; if(!empty($startDate)) { $where['pay_time'] = array('BETWEEN', [$startTime, $endTime]); $map['pay_time'] = array('BETWEEN', [$startTime, $endTime]); } if(isset($params['game_id'])) { $where['game_id'] = $params['game_id']; $map['game_id'] = $params['game_id']; } $map['supersign_token'] = ['NEQ','']; $supersign_game = M('game', 'tab_')->field('id,game_name,supersign_token')->where(['supersign_token' => ['NEQ','']])->select(); $supersign_token = array_column($supersign_game, 'supersign_token'); $authorization_all_num = 0; foreach($supersign_token as $k => $v) { $re_data = []; $curl['token'] = $v; $curl['limit'] = 2000; for ($i = 1;$i > 0;$i++) { if($i != 1) { $pop = array_pop($data); $curl['lastid'] = $pop['id']; } $curl_re = json_decode(curl_post('https://app.ipa365.com/Kirin/OpenApi/TicketList',$curl),true); if($curl_re['errno'] == 0) { $data = $curl_re['data']['list']; $re_data = array_merge($re_data,$data); } else { break; } if(count($data) != $curl['limit']) { break; } } $authorization_all_num += count($re_data); } $where['pay_status'] = 1; $xlsData[0]['buy_num'] = M('game_supersign', 'tab_')->where($where)->count(); $pay_price = M('game_supersign', 'tab_')->field('sum(pay_price) as pay_price')->where($where)->select(); $xlsData[0]['money_all'] = $pay_price[0]['pay_price'] == '' ? 0 : $pay_price[0]['pay_price']; $xlsData[0]['authorization_all_num'] = $authorization_all_num; break; case 25: $xlsCell = array( array('type', '类型'), array('pay_order_number', '支付订单号'), array('extend', 'CP订单号'), array('pay_time', '充值时间'), array('user_account', '玩家账号'), array('promote_account', '所属推广员'), array('game_name', '游戏名称'), array('pay_amount', '实付金额'), array('pay_way', '充值方式'), array('admin_name', '补单管理员'), array('create_time', '补单时间'), ); $params = I('get.'); if(isset($params['timestart']) && isset($params['timeend'])) { $startTime = strtotime($params['timestart']); $endTime = strtotime($params['timeend']) + 86399; $map['tab_repair_pay.create_time'] = array('BETWEEN', [$startTime, $endTime]); } if(isset($params['type'])) { $map['tab_repair_pay.type'] = $params['type']; } if(isset($params['pay_order_number'])) { $map['tab_repair_pay.pay_order_number'] = $params['pay_order_number']; } if(isset($params['admin_name'])) { $map['tab_repair_pay.admin_name'] = $params['admin_name']; } if(!empty(I('get.extend'))) { $map['tab_spend.extend'] = I('get.extend'); $data = M('repair_pay', 'tab_')->join('tab_spend on tab_spend.pay_order_number = tab_repair_pay.pay_order_number')->where($map)->page($p, $row)->order('tab_repair_pay.id DESC')->select(); } else { $data = M('repair_pay', 'tab_')->where($map)->page($p, $row)->order('id DESC')->select(); } $xlsData = []; foreach($data as $k => $v) { if($v['tab'] == 'spend') { $order_detail = M('spend', 'tab_')->field('extend,pay_time,user_account,promote_account,game_name,pay_amount,pay_way')->where(['pay_order_number' => $v['pay_order_number']])->find(); $re_data['pay_time'] = set_show_time($order_detail['pay_time']); } elseif($v['tab'] == 'deposit') { $order_detail = M('deposit', 'tab_')->field('create_time,user_account,promote_account,pay_amount,pay_way')->where(['pay_order_number' => $v['pay_order_number']])->find(); $re_data['pay_time'] = set_show_time($order_detail['create_time']); } $re_data['extend'] = !empty($order_detail['extend']) ? $order_detail['extend'] : '-'; $re_data['user_account'] = $order_detail['user_account']; $re_data['promote_account'] = $order_detail['promote_account']; $re_data['game_name'] = !empty($order_detail['game_name']) ? $order_detail['game_name'] : '-'; $re_data['pay_amount'] = $order_detail['pay_amount']; $re_data['pay_way'] = get_pay_way($order_detail['pay_way']); $re_data['pay_order_number'] = $v['pay_order_number']; $re_data['type'] = $v['type'] == 1 ? '补单' : '通知到账'; $re_data['create_time'] = set_show_time($v['create_time']); $re_data['admin_name'] = $v['admin_name']; $xlsData[] = $re_data; } break; default: $xlsName = $xlsCell = $xlsData = []; } //数据处理 foreach ($xlsData as $key => $val) { foreach ($xlsCell as $k => $v) { if (isset($v[2])) { $ar_k = array_search('*', $v); if ($ar_k !== false) { $v[$ar_k] = $val[$v[0]]; } $fun = $v[2]; $param = $v; unset($param[0], $param[1], $param[2]); $xlsData[$key][$v[0]] = call_user_func_array($fun, $param); } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function userarpuExport($p=1){ $request=$_REQUEST; $dataKey = array('time','register_num','act_user','keep_num','spend','spend_people','new_pop','spend_rate','ARPU','ARPPU','pop_num'); if(!empty($request['game_id'])){ array_splice($dataKey,1,0,"game_id"); } if(!empty($request['promote_id'])){ $key = empty($request['game_id'])?1:2; array_splice($dataKey,$key,0,"promote_id"); } $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:"ARPU分析"; foreach ($dataKey as $key => $value) { switch ($value) { case 'time': $xlsCell[$key] = array('time', "日期"); break; case 'game_id': $xlsCell[$key] = array('game_id', "游戏名称"); break; case 'promote_id': $xlsCell[$key] = array('promote_id', "推广员账号"); break; case 'register_num': $xlsCell[$key] = array('register_num', '新增玩家', 'time_format', '*'); break; case 'act_user': $xlsCell[$key] = array('act_user', '活跃玩家', 'time_format', '*'); break; case 'keep_num': $xlsCell[$key] = array('keep_num', '1日留存'); break; case 'spend': $xlsCell[$key] = array('spend', "充值"); break; case 'spend_people': $xlsCell[$key] = array('spend_people', '付费玩家'); break; case 'spend_people': $xlsCell[$key] = array('spend_people', '付费玩家'); break; case 'new_pop': $xlsCell[$key] = array('new_pop', '新付费玩家'); break; case 'spend_rate': $xlsCell[$key] = array('spend_rate', '付费率'); break; case 'ARPU': $xlsCell[$key] = array('ARPU', 'ARPU'); break; case 'ARPPU': $xlsCell[$key] = array('ARPPU', 'ARPPU'); break; case 'pop_num': $xlsCell[$key] = array('pop_num', '累计付费玩家'); break; } } $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据arraypage $arraypage = $page ? $page : 1; //默认显示第一页数据 $row = 10; $start = I('start'); $end = empty(I('end')) ? time_format(time(),'Y-m-d') : I('end'); $game_id = I('game_id'); $promote_id = I('promote_id'); $map_list = array(); if(I('game_id') !=0){ $this->assign('game_name',get_game_name(I('game_id'))); } if(I('promote_id') !=0){ $this->assign('promote_name',get_promote_account(I('promote_id'))); } if(I('game_id') != '') $map_list['game_id'] = I('game_id'); if(I('promote_id') != '') $map_list['promote_id'] = I('promote_id'); if(!empty($start)) { //新增玩家 $data = A('Stat')->count_register($start, $end, $game_id, $promote_id); foreach ($data as $key => $value) { $time = $value['time']; //活跃玩家 $data[$key]['act_user'] = A('Stat')->count_act_user($time,$game_id,$promote_id); //1日留存 $map = $map_list; if($map_list['promote_id']!=''){ $map['tab_user.promote_id']=$map_list['promote_id']; } unset($map['promote_id']); $map["FROM_UNIXTIME(register_time,'%Y-%m-%d')"] = $time; $login_time = date('Y-m-d', strtotime("+1 day",strtotime($time))); $num = M('user','tab_') ->field('count(DISTINCT tab_user.id) as num') ->join("right join tab_user_login_record as ur on ur.user_id = tab_user.id and FROM_UNIXTIME(ur.login_time,'%Y-%m-%d') = '{$login_time}'") ->where($map) ->group('user_id') ->find(); $data[$key]['keep_num'] = (round($num['num']/$data[$key]['register_num'],4)*100) . '%'; //充值 $map = $map_list; empty($game_name ) || $map['game_name'] = array('like','%'.$game_name.'%'); empty($promote_id) || $map['promote_id'] = $promote_id; $map['pay_status'] = 1; $map["FROM_UNIXTIME(pay_time,'%Y-%m-%d')"] = $time; $spend = M('spend','tab_')->field("IFNULL(sum(pay_amount),0) as money,IFNULL(count(distinct user_id),0) as people")->where($map)->find(); $data[$key]['spend'] = $spend['money']; //付费玩家数 $data[$key]['spend_people'] = $spend['people']; //新付费玩家 $map = $map_list; $map['pay_status'] = 1; $sql = M('spend','tab_')->field("user_id,min(pay_time) as time")->group('user_id')->where($map)->select(false); $sql = "select IFNULL(count(user_id),0) as num from ({$sql}) as t WHERE FROM_UNIXTIME(t.time,'%Y-%m-%d') = '{$time}'"; $query = M()->query($sql); $data[$key]['new_pop'] = $query[0]['num']; //付费率 $data[$key]['spend_rate'] = (round($data[$key]['spend_people']/$data[$key]['act_user'],4)*100) . '%'; //ARPU $data[$key]['ARPU'] = round($data[$key]['spend']/$data[$key]['act_user'],2); //ARPPU $data[$key]['ARPPU'] = round($data[$key]['spend']/$data[$key]['spend_people'],2); //累计付费玩家 $map = $map_list; $map['pay_status'] = 1; $map["FROM_UNIXTIME(pay_time,'%Y-%m-%d')"] = array('elt',$time); $pop_num = M('spend','tab_')->field('count(distinct user_id) as num')->where($map)->find(); $data[$key]['pop_num'] = $pop_num['num']; } }else{ unset($_REQUEST['data_order']); if(count(I('get.'))!=0){ $this->error('时间选择错误,请重新选择!'); } } if($request['data_order']!=''){ $data_order=reset(explode(',',$request['data_order'])); $data_order_type=end(explode(',',$request['data_order'])); $this->assign('userarpu_order',$data_order); $this->assign('userarpu_order_type',$data_order_type); } $data=my_sort($data,$data_order_type,(int)$data_order,SORT_STRING); $size=10;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) $data = array_slice($data, ($arraypage-1)*$size, $size); foreach ($data as $key => $value) { $data[$key]['game_id'] = get_game_name($request['game_id']); $data[$key]['promote_id'] = get_promote_account($request['promote_id']); } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 统计-平台统计 * * @param int $type 1: 游戏充值统计,2:注册方式统计,3:充值方式统计,其他:游戏注册统计 * @param int $p * * @author: 鹿文学[lwx] * @since: 2019\5\7 0007 10:52 */ public function platform_statistics($type=0, $p=1) { switch($type) { case 1: $this->gamepay_statistics_export($p); break; case 2: $this->resway_statistics_export($p); break; case 3: $this->payway_statistics_export($p); break; default: $this->game_statistics_export($p); } } private function game_statistics_export($p = 1){ $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:"游戏注册统计"; $xlsCell = array( array('fgame_name', "游戏名称"), array('count', "累计注册"), array('rand', "排行榜"), array('today', "今日注册"), array('week', "本周注册"), array('mounth', "本月注册"), ); $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $arraypage=$page; $row = 10; $user=M('User','tab_'); $map['fgame_id']=array('egt',0);$map['puid'] = 0; if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); } elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) { $map['register_time'] = ['between', array(strtotime($_REQUEST['timestart']), time())]; unset($_REQUEST['timestart']); } elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) { $map['register_time'] = ['elt', strtotime($_REQUEST['timeend']) + 86399]; unset($_REQUEST['timeend']); } if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); } if(isset($_REQUEST['game_name'])&&$_REQUEST['game_name']!=''){ $map['fgame_name'] =$_REQUEST['game_name']; unset($_REQUEST['fgame_name']); } $today = total(1); $week = total(2); $mounth = total(3); //为数据权限添加 setPowerPromoteIds($map); $data = $user ->field('fgame_name,fgame_id,date_format(FROM_UNIXTIME( register_time),"%Y-%m-%d") AS time, count(id) as count') ->where($map) ->group('fgame_id') ->order('count desc,register_time') ->select(); // dd($data); $map2 = array(); $map['fgame_id'] = array('egt', 0); $map['puid'] = 0; setPowerPromoteIds($map2); $data2 = $user->field('fgame_id,count(IF(register_time ' . $today . ',1,null)) as today, count(IF(register_time ' . $week . ',1,null)) as week, count(IF(register_time ' . $mounth . ',1,null)) as mounth') ->where($map2) ->group('fgame_id') ->select(); $data2 = array_column($data2, null, 'fgame_id'); // dd($data2); $count = count($data); foreach ($data as $key => $value) { static $i = 0; $i++; $data[$key]['rand'] = $i; if ($data[$key]['fgame_id'] == 0) { $data[$key]['fgame_name'] = '其他注册'; } $data[$key]['today'] = $data2[$value['fgame_id']]['today']; $data[$key]['week'] = $data2[$value['fgame_id']]['week']; $data[$key]['mounth'] = $data2[$value['fgame_id']]['mounth']; } $total=A('Platform')->data_total($data); if($_REQUEST['data_order']!=''){ $data_order=reset(explode(',',$_REQUEST['data_order'])); $data_order_type=end(explode(',',$_REQUEST['data_order'])); $this->assign('userarpu_order',$data_order); $this->assign('userarpu_order_type',$data_order_type); } $data=my_sort($data,$data_order_type,(int)$data_order); $size=$row;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) // $data = array_slice($data, ($arraypage-1)*$size, $size); $length = count($data); $data[$length] = array( 'fgame_name'=>'汇总', 'count'=>$total['sum_count'], 'rand'=>'---', 'today'=>$total['sum_today'], 'week'=>$total['sum_week'], 'mounth'=>$total['sum_mounth'] ); $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } private function gamepay_statistics_export($p=1){ $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:"游戏充值统计"; $xlsCell = array( array('game_name', "游戏名称"), array('count', "累计充值"), array('rand', "排行榜"), array('today', "今日充值"), array('week', "本周充值"), array('mounth', "本月充值"), ); $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $arraypage=$page; $row = 10; $spend=M('Spend','tab_'); $deposit = M('Deposit',"tab_"); $map['game_id']=array('gt',0); if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); } if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); } if(isset($_REQUEST['game_name'])&&$_REQUEST['game_name']!=''){ $map['game_id'] =$_REQUEST['game_name']; unset($_REQUEST['game_name']); } $map['pay_status'] = 1; $today = total(1); $week = total(2); $mounth = total(3); $data = $spend ->field('game_name,game_id,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count') ->where($map) ->where($map) ->group('game_id') ->order('count desc,pay_time') ->select(); //今日、本周、本月不随搜索条件而变动 $map2['pay_status'] = 1; $map2['game_id'] = array('gt', 0); setPowerPromoteIds($map2); $data2 = $spend ->field('game_id,sum(IF(pay_time ' . $today . ',pay_amount,0)) as today, sum(IF(pay_time ' . $week . ',pay_amount,0)) as week, sum(IF(pay_time ' . $mounth . ',pay_amount,0)) as mounth') ->where($map2) ->group('game_id') ->select(); $data2 = array_column($data2, null, 'game_id'); $count = count($data); foreach ($data as $key => $value) { static $i = 0; $i++; $data[$key]['rand'] = $i; //加入今日、本周、本月数据 $data[$key]['today'] = $data2[$value['game_id']]['today']; $data[$key]['week'] = $data2[$value['game_id']]['week']; $data[$key]['mounth'] = $data2[$value['game_id']]['mounth']; } $total=A('Platform')->data_total($data); $this->assign('total',$total); if($_REQUEST['data_order']!=''){ $data_order=reset(explode(',',$_REQUEST['data_order'])); $data_order_type=end(explode(',',$_REQUEST['data_order'])); $this->assign('userarpu_order',$data_order); $this->assign('userarpu_order_type',$data_order_type); } if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } $data=my_sort($data,$data_order_type,(int)$data_order); $size=$row;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) // $data = array_slice($data, ($arraypage-1)*$size, $size); $length = count($data); $data[$length] = array( 'game_name'=>'汇总', 'count'=>$total['sum_count'], 'rand'=>'---', 'today'=>$total['sum_today'], 'week'=>$total['sum_week'], 'mounth'=>$total['sum_mounth'] ); $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } private function resway_statistics_export($p=0){ $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:"注册方式统计"; $xlsCell = array( array('register_way', "注册方式"), array('count', "累计注册"), array('rand', "排行榜"), array('today', "今日注册"), array('week', "本周注册"), array('mounth', "本月注册"), ); $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $arraypage=$page; $row = 10; $user=M('User','tab_'); $map['puid'] = 0; if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); } if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); } if(isset($_REQUEST['register_way'])&&$_REQUEST['register_way']!=''){ $map['register_way'] =$_REQUEST['register_way']; unset($_REQUEST['register_way']); } setPowerPromoteIds($map); $today = total(1); $week = total(2); $mounth = total(3); $data = $user ->field('register_way,date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(id) as count') ->where($map) ->group('register_way') ->order('count desc,register_time') ->select(); $map2 = array(); $map2['puid'] = 0; setPowerPromoteIds($map2); $data2 = $user ->field('register_way, count(IF(register_time ' . $today . ',1,null)) as today, count(IF(register_time ' . $week . ',1,null)) as week, count(IF(register_time ' . $mounth . ',1,null)) as mounth') ->where($map2) ->group('register_way') ->select(); $data2 = array_column($data2, null, 'register_way'); $count = count($data); foreach ($data as $key => $value) { static $i = 0; $i++; $data[$key]['rand'] = $i; $data[$key]['today'] = $data2[$value['register_way']]['today']; $data[$key]['week'] = $data2[$value['register_way']]['week']; $data[$key]['mounth'] = $data2[$value['register_way']]['mounth']; } $total=A('Platform')->data_total($data); if($_REQUEST['data_order']!=''){ $data_order=reset(explode(',',$_REQUEST['data_order'])); $data_order_type=end(explode(',',$_REQUEST['data_order'])); $this->assign('userarpu_order',$data_order); $this->assign('userarpu_order_type',$data_order_type); } if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } $data=my_sort($data,$data_order_type,(int)$data_order); $size=$row;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) $data = array_slice($data, ($arraypage-1)*$size, $size); foreach ($data as $key => $value) { $data[$key]['register_way'] = get_register_way($data[$key]['register_way']); } $length = count($data); $data[$length] = array( 'register_way'=>'汇总', 'count'=>$total['sum_count'], 'rand'=>'---', 'today'=>$total['sum_today'], 'week'=>$total['sum_week'], 'mounth'=>$total['sum_mounth'] ); $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } private function payway_statistics_export($p=0){ $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $arraypage=$page; $row = 10; $deposit = M('Deposit',"tab_"); $user=M('User','tab_'); $spend=M('Spend','tab_'); if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); } if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); } if(isset($_REQUEST['pay_way'])&&$_REQUEST['pay_way']!=''){ $map['pay_way'] = array('in',$_REQUEST['pay_way']) ; unset($_REQUEST['pay_way']); } setPowerPromoteIds($map); $map['pay_status'] = 1; $today = total(1); $week = total(2); $mounth = total(3); $data = $spend ->field('pay_way,date_format(FROM_UNIXTIME(pay_time),"%Y-%m-%d") AS time, sum(pay_amount) as count') ->where($map) ->group('pay_way') ->order('count desc,pay_time') ->select(); $map2 = array(); $map2['pay_status'] = 1; setPowerPromoteIds($map2); $data2 = $spend ->field('pay_way, sum(IF(pay_time ' . $today . ',pay_amount,0)) as today, sum(IF(pay_time ' . $week . ',pay_amount,0)) as week, sum(IF(pay_time ' . $mounth . ',pay_amount,0)) as mounth') ->where($map2) ->group('pay_way') ->select(); $data2 = array_column($data2, null, 'pay_way'); $count = count($data); foreach ($data as $key => $value) { static $i = 0; $i++; $data[$key]['rand'] = $i; $data[$key]['today'] = $data2[$value['pay_way']]['today']; $data[$key]['week'] = $data2[$value['pay_way']]['week']; $data[$key]['mounth'] = $data2[$value['pay_way']]['mounth']; } $total = A('Platform')->data_total($data); $this->assign('total',$total); if($_REQUEST['data_order']!=''){ $data_order=reset(explode(',',$_REQUEST['data_order'])); $data_order_type=end(explode(',',$_REQUEST['data_order'])); $this->assign('userarpu_order',$data_order); $this->assign('userarpu_order_type',$data_order_type); } if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } $data=my_sort($data,$data_order_type,(int)$data_order); $size=$row;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) $data = array_slice($data, ($arraypage-1)*$size, $size); $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'充值方式统计'; $xlsCell = array( array('pay_way', "充值方式"), array('count' , "累计充值"), array('rand' , "排行榜"), array('today' , "今日充值"), array('week' , "本周充值"), array('mounth' , "本月充值"), ); foreach ($data as $key => $value) { $data[$key]['pay_way'] = get_pay_way($data[$key]['pay_way']); } $length = count($data); $data[$length] = array( 'pay_way'=>'汇总', 'count'=>$total['sum_count'], 'rand'=>'---', 'today'=>$total['sum_today'], 'week'=>$total['sum_week'], 'mounth'=>$total['sum_mounth'] ); $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 统计-推广员统计 * * @param int $type 1 推广员充值统计,其他 推广员注册统计 * @param int $p * * @author: 鹿文学[lwx] * @since: 2019\5\7 0007 10:48 */ public function promote_statistics($type=0,$p=0) { if($type == 1) { $this->promotepay_statistics_export($p); } else { $this->promote_statistics_export($p); } } private function promote_statistics_export($p=0){ $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $arraypage=$page; $row = 10; $user=M('User','tab_'); if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); } elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) { $map['register_time'] = ['between', array(strtotime($_REQUEST['timestart']), time())]; unset($_REQUEST['timestart']); } elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) { $map['register_time'] = ['elt', strtotime($_REQUEST['timeend']) + 86399]; unset($_REQUEST['timeend']); } // if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ // $map['register_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); // unset($_REQUEST['start']);unset($_REQUEST['end']); // } $play_info_map = ''; if (isset($_REQUEST['game_name'])) { $map['fgame_name'] = $_REQUEST['game_name']; $play_info_map .= " and upi.game_name = '{$_REQUEST['game_name']}' "; unset($_REQUEST['game_name']); } if (isset($_REQUEST['server_id'])) { $play_info_map .= " and upi.server_name = '{$_REQUEST['server_id']}' "; } $today=total(1); $week=total(2); $mounth=total(3); if (isset($_REQUEST['promote_id'])) { $map['tp1.id'] = $_REQUEST['promote_id']; } else { $map['tp1.chain'] = '/'; } //为数据权限添加 setPowerPromoteIds($map, 'u.promote_id'); $data = M('promote', 'tab_')->alias('tp1')->field('tp1.account as promote_account,tp1.id, date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(u.id) as count, count(IF(register_time ' . $today . ',1,null)) as today, count(IF(register_time ' . $week . ',1,null)) as week, count(IF(register_time ' . $mounth . ',1,null)) as mounth') ->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left') ->join("tab_user as u on tp2.id = u.promote_id", 'left') ->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false) ->where($map) ->group('tp1.id') ->order('count desc, register_time') ->select(); unset($map['tp1.id']); unset($map['tp1.chain']); $map['promote_id'] = 0; //如果有官方渠道权限 $user_auth_promote_ids = session('user_auth_promote_ids'); if ($user_auth_promote_ids == 'all' || in_array('0', explode(",", $user_auth_promote_ids))) { //官方渠道数据添加 $authorityData = M('user', 'tab_')->alias('u') ->field('date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time, count(id) as count, count(IF(register_time ' . $today . ',1,null)) as today, count(IF(register_time ' . $week . ',1,null)) as week, count(IF(register_time ' . $mounth . ',1,null)) as mounth') ->where($map) ->find(); } $authorityData['promote_account'] = "官方渠道"; $authorityData['id'] = "1"; if (isset($_REQUEST['promote_id'])||$authorityData['count']==0) { $authorityData = []; } else { array_push($data, $authorityData); } //数据排序 $last_names = array_column($data,'count'); array_multisort($last_names,SORT_DESC,$data); // var_dump($data);die(); $count=count($data); foreach ($data as $key => $value) { static $i=0; $i++; $data[$key]['rand']=$i; } // foreach ($data as $key => $value) { // if($data[$key]['promote_id']==0){ // unset($data[$key]); // } // } $total=A('Platform')->data_total($data); if($_REQUEST['data_order']!=''){ $data_order=reset(explode(',',$_REQUEST['data_order'])); $data_order_type=end(explode(',',$_REQUEST['data_order'])); $this->assign('userarpu_order',$data_order); $this->assign('userarpu_order_type',$data_order_type); } if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } $data=my_sort($data,$data_order_type,(int)$data_order); $size=$row;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) // $data = array_slice($data, ($arraypage-1)*$size, $size); $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'推广员注册统计'; $xlsCell = array( array('promote_account', "推广员账号"), array('count' , "累计注册"), array('rand' , "排行榜"), array('today' , "今日注册"), array('week' , "本周注册"), array('mounth' , "本月注册"), ); // foreach ($data as $key => $value) { // $data[$key]['promote_id'] = get_promote_account($data[$key]['promote_id']); // } // var_dump($data);die(); $length = count($data); $data[$length] = array( 'promote_account'=>'汇总', 'count'=>$total['sum_count'], 'rand'=>'---', 'today'=>$total['sum_today'], 'week'=>$total['sum_week'], 'mounth'=>$total['sum_mounth'] ); $xlsData = $data; // var_dump($xlsData);die(); $this->exportExcel($xlsName, $xlsCell, $xlsData); } private function promotepay_statistics_export($p=0){ $map1['promote_id'] = $map['promote_id'] = array('egt', 0); $spend=M('Spend','tab_'); if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); unset($_REQUEST['timestart']);unset($_REQUEST['timeend']); } elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) { $map['create_time'] = ['between', array(strtotime($_REQUEST['timestart']), time())]; $pay_time = " between " . strtotime($_REQUEST['timestart']) . " and " . time() . " "; unset($_REQUEST['timestart']); } elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) { $map['create_time'] = ['elt', strtotime($_REQUEST['timeend']) + 86399]; $pay_time = " between 0 and " . (strtotime($_REQUEST['timeend']) + 86399) . " "; unset($_REQUEST['timeend']); } else { $pay_time = " between 0 and " . time(); } if(isset($_REQUEST['start'])&&isset($_REQUEST['end'])){ $map['pay_time'] =array('BETWEEN',array(strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1)); unset($_REQUEST['start']);unset($_REQUEST['end']); } // if(isset($_REQUEST['promote_id'])){ // $map['promote_id'] =$_REQUEST['promote_id']; // unset($_REQUEST['promote_id']); // } $map1['pay_status'] = $map['pay_status']=1; // $map1['pay_way'] = $map['pay_way'] = array('gt', 0); $today=total(1); $week=total(2); $mounth=total(3); unset( $map['create_time']); //获取所有会长 $promote_map = "`chain` = '/'"; if (isset($_REQUEST['promote_id'])) { $promote_map = "`chain` = '%/{$_REQUEST['promote_id']}/%' OR id = {$_REQUEST['promote_id']}"; } //为数据权限添加 setPowerPromoteIds($map); $promote_map2 = array(); setPowerPromoteIds($promote_map2, 'id'); $promote = M("promote","tab_")->field("id,account")->where($promote_map)->where($promote_map2)->select(); $pcount = M("promote","tab_")->field("count(*) acount")->where($promote_map)->where($promote_map2)->find()['acount']; // var_dump( $promote); $data =array(); for ($i=0; $i < count($promote); $i++) { # code... $proid = M("promote","tab_")->field("id")->where("`chain` like '%/{$promote[$i]['id']}/%'")->select(); $str = ''; for($k=0; $kfield(' floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as count, floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today, floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week, floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth') ->where($map) ->where("pay_time".$pay_time) ->find(); $dbdata['promote_account'] = $promote[$i]['account']; $dbdata['promote_id'] = $promote[$i]['id']; } else { $dbdata = $spend ->field(' floor(sum(IF(pay_time ' . $pay_time . ',pay_amount,0))*100) as count, floor(sum(IF(pay_time ' . $today . ',pay_amount,0))*100) as today, floor(sum(IF(pay_time ' . $week . ',pay_amount,0))*100) as week, floor(sum(IF(pay_time ' . $mounth . ',pay_amount,0))*100) as mounth') ->where($map) ->where("pay_time".$pay_time) ->find(); $dbdata['promote_account'] = $promote[$i]['account']; $dbdata['promote_id'] = $promote[$i]['id']; } $data[] = $dbdata; } $count = count($data); foreach ($data as $key => $value) { $value['count'] ?: 0; $value['today'] ?: 0; $value['week'] ?: 0; $value['mounth'] ?: 0; static $i = 0; $i++; $data[$key]['rand'] = $i; $data[$key]['count'] = $value['count'] / 100; $data[$key]['today'] = $value['today'] / 100; $data[$key]['week'] = $value['week'] / 100; $data[$key]['mounth'] = $value['mounth'] / 100; } $total = $this->data_total($data); $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'推广员充值统计'; $xlsCell = array( array('promote_id', "推广员账号"), array('count' , "累计充值"), array('rand' , "排行榜"), array('today' , "今日充值"), array('week' , "本周充值"), array('mounth' , "本月充值"), ); foreach ($data as $key => $value) { $data[$key]['promote_id'] = get_promote_account($data[$key]['promote_id']); } $length = count($data); $data[$length] = array( 'promote_id'=>'汇总', 'count'=>$total['sum_count'], 'rand'=>'---', 'today'=>$total['sum_today'], 'week'=>$total['sum_week'], 'mounth'=>$total['sum_mounth'] ); $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function data_total($data) { $total['sum_count'] = array_sum(array_column($data, 'count')); $total['sum_today'] = array_sum(array_column($data, 'today')); $total['sum_week'] = array_sum(array_column($data, 'week')); $total['sum_mounth'] = array_sum(array_column($data, 'mounth')); return $total; } public function userretention_export() { $this->meta_title = '留存统计'; $start = I('start', date('Y-m-d',strtotime('-7 day'))); $end = empty(I('end')) ? time_format(time(),'Y-m-d') : I('end'); $gameId = I('game_id', 0); $promoteId = I('promote_id', 0); $status = true; $data = false; $error = ''; if ($gameId == 0) { $error = '请选择游戏!'; $status = false; } $startTime = strtotime($start . ' 00:00:00'); $endTime = strtotime($end . ' 23:59:59') + 1; if ((($endTime - $startTime)/(24*3600)) > 31) { $error = '时间间隔不能超过31天'; $status = false; } if ($status) { $client = new Client([ 'base_uri' => C('TASK_URL'), 'timeout' => 10.0, ]); $response = $client->post('/statistics/player-retention', [ 'verify' => false, 'form_params' => [ 'start_time' => $start, 'end_time' => $end, 'promote_id' => I('promote_id', 0), 'game_id' => $gameId, ] ]); $result = (string)$response->getBody(); $result = json_decode($result, true); if (!$result) { $this->error('数据请求异常!'); } $gameName = get_game_name($gameId); $promoteName = '全部'; if ($promoteId) { $promoteName = get_promote_account($promoteId); } $data = $result['data']['records']; $dayList = [1, 2, 3, 4, 5, 6, 7, 15, 30]; foreach ($data as $key => $item) { $item['game_name'] = $gameName; $item['promote_name'] = $promoteName; foreach ($dayList as $day) { if ($item['register_count'] > 0) { $item['retention_day'. $day] = (round($item['retention_day'. $day]/$item['register_count'], 4)*100) . '%'; } else { $item['retention_day'. $day] = '--'; } } $data[$key] = $item; } } else { $this->error($error); } $xlsCell = [ ['date', "日期"], ['game_name', "游戏名称"], ['promote_name', "推广员账号"], ['register_count', '新增玩家', 'time_format', '*'], ['retention_day1', '1日留存', 'time_format', '*'], ['retention_day2', '2日留存'], ['retention_day3', "3日留存"], ['retention_day4', '4日留存'], ['retention_day5', '5日留存'], ['retention_day6', '6日留存'], ['retention_day7', '7日留存'], ['retention_day15', '15日留存'], ['retention_day30', '30日留存'], ]; $xlsData = $data; $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'留存分析'; $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function userretention($p = 0) { $request=$_REQUEST; $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $arraypage=$page; $row = 10; $start = I('start'); $end = empty(I('end')) ? time_format(time(),'Y-m-d') : I('end'); if(!empty($start)){ $game_id = I('game_id'); $promote_id = I('promote_id'); $map_list = array(); //统计每日注册数 $data = A('Stat')->count_register($start,$end,$game_id,$promote_id,$page); $day = array(1,2,3,4,5,6,7,15,30,60); foreach ($data as $k=>$v) { //当日注册人账号 $map = $map_list; $time = $v['time']; $map["FROM_UNIXTIME(register_time,'%Y-%m-%d')"] = $time; //每日留存 foreach ($day as $key => $value) { $map = $map_list; $map["FROM_UNIXTIME(register_time,'%Y-%m-%d')"] = $time; $login_time = date('Y-m-d', strtotime("+{$value} day",strtotime($time))); $num = M('user','tab_') ->field('count(DISTINCT tab_user.id) as num') ->join("right join tab_user_login_record as ur on ur.user_id = tab_user.id and FROM_UNIXTIME(ur.login_time,'%Y-%m-%d') = '{$login_time}'") ->where($map) ->group('user_id') ->find(); $data[$k][$value] = $num['num']; } } //分页 $time_map['time'] = array('between',array($start,$end)); $count = M('date_list')->where($time_map)->count(); if($count > $row){ $page = new \Think\Page($count, $row); $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $this->assign('_page', $page->show()); } }else{ unset($_REQUEST['data_order']); if(count(I('get.'))!=0){ $this->error('时间选择错误,请重新选择!'); } } if($request['data_order']!=''){ $data_order=reset(explode(',',$request['data_order'])); $data_order_type=end(explode(',',$request['data_order'])); } $data=my_sort($data,$data_order_type,(int)$data_order,SORT_STRING); $size=10;//每页显示的记录数 $pnum = ceil(count($data) / $size); //总页数,ceil()函数用于求大于数字的最小整数 $data = array_slice($data, ($arraypage-1)*$size, $size); $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'留存分析'; $dataKey = array('time','register_num','1','2','3','4','5','6','7','15','30'); if(!empty($request['game_id'])){ array_splice($dataKey,1,0,"game_id"); } if(!empty($request['promote_id'])){ $key = empty($request['game_id'])?1:2; array_splice($dataKey,$key,0,"promote_id"); } foreach ($dataKey as $key => $value) { switch ($value) { case 'time': $xlsCell[$key] = array('time', "日期"); break; case 'game_id': $xlsCell[$key] = array('game_id', "游戏名称"); break; case 'promote_id': $xlsCell[$key] = array('promote_id', "推广员账号"); break; case 'register_num': $xlsCell[$key] = array('register_num', '新增玩家', 'time_format', '*'); break; case '1': $xlsCell[$key] = array('1', '1日留存', 'time_format', '*'); break; case '2': $xlsCell[$key] = array('2', '2日留存'); break; case '3': $xlsCell[$key] = array('3', "3日留存"); break; case '4': $xlsCell[$key] = array('4', '4日留存'); break; case '5': $xlsCell[$key] = array('5', '5日留存'); break; case '6': $xlsCell[$key] = array('6', '6日留存'); break; case '7': $xlsCell[$key] = array('7', '7日留存'); break; case '15': $xlsCell[$key] = array('15', '15日留存'); break; case '30': $xlsCell[$key] = array('30', '30日留存'); break; } } foreach ($data as $key => $value) { $data[$key]['game_id'] = get_game_name($request['game_id']); $data[$key]['promote_id'] = get_promote_account($request['promote_id']); $data[$key]['1'] = (round($data[$key]['1']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['2'] = (round($data[$key]['2']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['3'] = (round($data[$key]['3']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['4'] = (round($data[$key]['4']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['5'] = (round($data[$key]['5']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['6'] = (round($data[$key]['6']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['7'] = (round($data[$key]['7']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['15'] = (round($data[$key]['15']/$data[$key]['register_num'],4)*100).'%'; $data[$key]['30'] = (round($data[$key]['30']/$data[$key]['register_num'],4)*100).'%'; } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function summaryQueryExport($p=1){ $xlsCell = array( array('cycle', "查询时间"), array('ba_account' , "商务专员账号"), array('pro_count' , "旗下推广员数"), array('pro_reg_count' , "总注册(个)"), array('pro_reg_sum' , "总充值(元)"), ); $xlsName = $_REQUEST['xlsname']?$_REQUEST['xlsname']:'汇总查询'; $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据arraypage $arraypage = $page ? $page : 1; //默认显示第一页数据 $size = 10; if (isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])) { if (isset($_GET['ba_id'])) { $map['id'] = $_GET['ba_id']; } $ba = M('business_affairs', 'tab_')->field('id,account,promote_id')->where($map)->select(); foreach ($ba as $key => $value) { $lists[$key]['ba_account'] = $value['account']; $pro_map['ba_id'] = $value['id']; $pro_count = M('promote', 'tab_')->field('id')->where($pro_map)->count(); $lists[$key]['pro_count'] = $pro_count; $pro_reg_map['promote_id'] = ['in', $value['promote_id']]; $pro_reg_map_time['register_time'] = array('BETWEEN', array(strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1)); $pro_reg_map_paytime['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1)); $pro_reg = M('user', 'tab_')->field('id')->where($pro_reg_map)->where($pro_reg_map_time)->count(); $lists[$key]['pro_reg_count'] = $pro_reg; $pro_reg_map['pay_status'] = 1; $pro_spend = M('spend', 'tab_')->where($pro_reg_map)->where($pro_reg_map_paytime)->sum('pay_amount'); $lists[$key]['pro_reg_sum'] = empty($pro_spend) ? 0 : $pro_spend; } $count = count($lists); $lists = array_slice($lists, ($arraypage - 1) * $size, $size); foreach ($lists as $key => $value) { $lists[$key]["cycle"] = $_REQUEST['timestart']."到".$_REQUEST['timeend']; } $xlsData = $lists; $this->exportExcel($xlsName, $xlsCell, $xlsData); }else{ $xlsCell = array( array('cycle', "查询时间"), array('ba_account' , "商务专员账号"), array('pro_count' , "旗下推广员数"), array('pro_reg_count' , "总注册(个)"), array('pro_reg_sum' , "总充值(元)"), ); $this->exportExcel($xlsName, $xlsCell, ""); } } public function BindRechargeRecordExport($p=1){ $model = new \Admin\Model\BindRechargeModel(); empty(I('game_id')) || $map['game_id'] = I('game_id'); empty(I("pay_way")) || $map['pay_way'] = I("pay_way"); empty(I('pay_status')) || $map['pay_status'] = I('pay_status'); empty(I("account")) || $map['user_account'] = ["like","%".I("account")."%"]; empty(I("time_start")) || $map['create_time'] = ["between",[strtotime(I("time_start")),empty(I("time_end"))?time():strtotime(I("time_end"))+86400-1]]; // $promoteRoot = getPowerPromoteIds(); // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); $data = $model->getLists($map,"create_time desc",$p); $xlsCell = array( array('pay_order_number', "订单号"), array('user_account' , "玩家账号"), array('promote_account' , "所属推广员"), array('game_name' , "游戏名称"), array('amount' , "充值绑币"), array('real_amount' , "实付金额"), array('pay_way' , "充值方式"), array('recharge_ip' , "充值IP"), array('create_time' , "充值时间"), array('pay_status' , "订单状态"), ); $xlsName = $_REQUEST['xlsname']; $data = $data['data']; foreach ($data as $key => $value) { $data[$key]['pay_way'] = get_pay_way($value['pay_way']); $data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']); $data[$key]['pay_status'] = get_info_status($value['pay_status'],9); } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 用户分析 * @author 鹿文学 */ public function user($p=1) { $xlsName = $_REQUEST['xlsname']; if(is_numeric($_REQUEST['game_id']) && $_REQUEST['game_id']>0) { $game_id = I('game_id',''); $gamesource = get_source_from_game($game_id); } else { $gamesource = '全部'; } if(is_numeric($_REQUEST['promote_id'])) { $promote_id = I('promote_id',0); $promoteaccount = get_promote_name($promote_id); } else { $promoteaccount = '全部'; } $xlsCell = array( array('time','日期'), array('source','来源游戏'), array('promote','推广员'), array('news','新增用户'), array('old','老用户'), array('dau','DAU'), array('wau','WAU'), array('mau','MAU'), ); if (is_file(RUNTIME_PATH.'/access_data_user.txt')) { $filetxt = file_get_contents(RUNTIME_PATH.'/access_data_user.txt'); $data = json_decode($filetxt,true); } else { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}//10; $start = I('start',date('Y-m-d',strtotime('-7 day'))); $end = I('end',date('Y-m-d',strtotime('-1 day'))); $end = strtotime($end)>=strtotime(date('Y-m-d'))?date('Y-m-d',strtotime('-1 day')):$end; $data = D('user')->user(strtotime($start),strtotime($end),$promote_id,$game_id); $count = count($list); $data = array_slice($list,($page-1)*$row,$row,true); } foreach ($data as $v) { $v['source'] = $gamesource; $v['promote'] = $promoteaccount; $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * ltv统计 * @author 鹿文学 */ public function ltv($p=1, $start, $end) { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('date','日期'), array('total_amt','充值金额'), array('user_count','活跃用户'), array('ltv_1','LTV1'), array('ltv_2','LTV2'), array('ltv_3','LTV3'), array('ltv_4','LTV4'), array('ltv_5','LTV5'), array('ltv_6','LTV6'), array('ltv_7','LTV7'), array('ltv_14','LTV14'), array('ltv_30','LTV30'), ); $start_time = $start = strtotime($start); $end_time = $end = strtotime($end) + 86400; // if (is_file(RUNTIME_PATH.'/access_data_ltv.txt')) { // $filetxt = file_get_contents(RUNTIME_PATH.'/access_data_ltv.txt'); // $data = json_decode($filetxt, true); // } $map = " 1=1 "; $game_map = ""; if (isset($_REQUEST['game_name']) && isset($_REQUEST['server_id'])) { $game_ids = implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')); $map .= " AND game_id in ({$game_ids})"; $game_map = " AND EXISTS (SELECT upi.user_id FROM tab_user_play_info as upi where upi.game_id in ({$game_ids}) AND upi.user_id = u.id "; if (isset($_REQUEST['server_id'])) { $game_map .= " AND upi.server_id = '{$_REQUEST['server_id']}' "; $map .= " AND server_id = '{$_REQUEST['server_id']}' "; }; $game_map .= ") "; } else if (isset($_REQUEST['game_name'])) { $game_ids = implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')); $map .= " AND game_id in ({$game_ids})"; $game_map = " AND EXISTS (SELECT upi.user_id FROM tab_user_play as upi where upi.game_id in ({$game_ids}) AND upi.user_id = u.id "; $game_map .= ") "; } // 获取包含的用户id $users = M()->query(" SELECT count(*) as total_count, GROUP_CONCAT(u.id) as ids, FROM_UNIXTIME(u.register_time, '%Y-%m-%d') as reg_date FROM tab_user u WHERE u.register_time BETWEEN {$start_time} AND {$end_time} {$game_map} GROUP BY reg_date ORDER BY reg_date asc "); $result = []; foreach ($users as $index => $item) { $ltv_start = strtotime($item['reg_date']); $ltv_end = strtotime($item['reg_date']) + 30 * 86400; $ltv = M()->query(" SELECT ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 1).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_1, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 2).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_2, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 3).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_3, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 4).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_4, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 5).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_5, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 6).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_6, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 7).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_7, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 14).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_14, ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 30).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_30, SUM(if (pay_time BETWEEN {$start_time} and ".($end_time).", pay_amount, 0)) as total_amt FROM tab_spend WHERE {$map} AND pay_time BETWEEN {$ltv_start} AND {$ltv_end} AND user_id IN ({$item['ids']}) AND pay_status = 1 "); $result[] = [ 'date'=>$item['reg_date'], 'total_amt'=>$ltv[0]['total_amt'] ?: 0, 'user_count'=>$item['total_count'] ?: 0, 'ltv_1'=>$ltv[0]['ltv_1'] ?: 0, 'ltv_2'=>$ltv[0]['ltv_2'] ?: 0, 'ltv_3'=>$ltv[0]['ltv_3'] ?: 0, 'ltv_4'=>$ltv[0]['ltv_4'] ?: 0, 'ltv_5'=>$ltv[0]['ltv_5'] ?: 0, 'ltv_6'=>$ltv[0]['ltv_6'] ?: 0, 'ltv_7'=>$ltv[0]['ltv_7'] ?: 0, 'ltv_14'=>$ltv[0]['ltv_14'] ?: 0, 'ltv_30'=>$ltv[0]['ltv_30'] ?: 0 ]; unset($user[$index]); } $data = []; $k = 0; for($i=$start_time; $i<$end_time; $i+=86400) { if (($result[$k]['date'] == date("Y-m-d", $i))) { $data[] = $result[$k]; $k += 1; } else { $data[] = [ 'date'=>date("Y-m-d", $i), 'total_amt'=> 0, 'user_count'=> 0, 'ltv_1'=> 0, 'ltv_2'=> 0, 'ltv_3'=> 0, 'ltv_4'=> 0, 'ltv_5'=> 0, 'ltv_6'=> 0, 'ltv_7'=> 0, 'ltv_14'=> 0, 'ltv_30'=> 0 ]; } } foreach ($data as $v) { $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 统计总揽数据 * @author 鹿文学 */ public function overview() { $xlsName = $_REQUEST['xlsname'].'_'.$_REQUEST['name']; $xlsCell = array( array('time','日期'), array('count',$_REQUEST['name']), ); $num = I('num',2); $key = $_REQUEST['key']; if (is_file(RUNTIME_PATH.'/access_data_foldline.txt')) { $filetxt = file_get_contents(RUNTIME_PATH.'/access_data_foldline.txt'); $data = json_decode($filetxt,true); $xlsData = $data[$key]; $xlsSummary[] = $data['sum'][$key]; } else { $start = I('start',date('Y-m-d',strtotime('-1 day'))); $end = I('end',date('Y-m-d',strtotime('-1 day'))); $starttime = strtotime($start); $endtime = strtotime($end)+86399; $user = D('User'); $spend = D('Spend'); $flag = 1; if ($start == $end) { $hours = ['00~01','02~03','04~05','06~07','08~09','10~11','12~13','14~15','16~17','18~19','20~21','22~23']; foreach($hours as $v) { if ($key == 'news'){ $data['news'][$v] = 0;} if ($key == 'active'){ $data['active'][$v] = 0;} if ($key == 'player'){ $data['player'][$v] = 0;} } // 新增用户 if ($key == 'news'){ $hoursnews = $user->newsAdd(['register_time'=>['between',[$starttime,$endtime]]],'news','time',5); } if ($key == 'active'){ // 活跃用户 $hoursactive = $user->totalPlayerByGroup(['tab_user_login_record.login_time'=>['between',[$starttime,$endtime]]],'active','time',true,5); }if ($key == 'player'){ // 付费用户 $hoursplayer = $spend->totalPlayerByGroup(['pay_time'=>['between',[$starttime,$endtime]]],'player','time',5); } foreach($hours as $v) { foreach($hoursnews as $h) { $time = explode(' ',$h['time']); if (strpos($v,$time[1]) !== false) { $data['news'][$v] = (integer)$h['news'];break; } } foreach($hoursactive as $h) { $time = explode(' ',$h['time']); if (strpos($v,$time[1]) !== false) { $data['active'][$v] = (integer)$h['active'];break; } } foreach($hoursplayer as $h) { $time = explode(' ',$h['time']); if (strpos($v,$time[1]) !== false) { $data['player'][$v] = (integer)$h['player'];break; } } } } else { $datelist = get_date_list($starttime,$endtime,$num==7?2:1); $flag = 0; foreach($datelist as $k => $v) { if ($key == 'news'){ $data['news'][$v] = 0;} if ($key == 'active'){ $data['active'][$v] = 0;} if ($key == 'player'){ $data['player'][$v] = 0;} } if ($key == 'news'){ // 新增用户 $news = $user->newsAdd(['register_time'=>['between',[$starttime,$endtime]]],'news','time',$num==7?2:1); } if ($key == 'active'){ // 活跃用户 $active = $user->totalPlayerByGroup(['tab_user_login_record.login_time'=>['between',[$starttime,$endtime]]],'active','time',true,$num==7?2:1); } if ($key == 'player'){ // 付费用户 $player = $spend->totalPlayerByGroup(['pay_time'=>['between',[$starttime,$endtime]]],'player','time',$num==7?2:1); } foreach($datelist as $v) { foreach($news as $h) { if ($v == $h['time']) { $data['news'][$v] = (integer)$h['news'];break; } } foreach($active as $h) { if ($v == $h['time']) { $data['active'][$v] = (integer)$h['active'];break; } } foreach($player as $h) { if ($v == $h['time']) { $data['player'][$v] = (integer)$h['player'];break; } } } } foreach ($data as $k => $v) { $sum = 0;$tempexport=[]; foreach($v as $t => $s){ $sum += $s; if($flag==1){ $tempexport[]=['time'=>((integer)substr($t,0,2)).':00','count'=>$s]; }else{ $tempexport[]=['time'=>$t,'count'=>$s]; } } $export[$k]=$tempexport; $export['sum'][$k]=$sum; } $xlsData = $export[$key]; $xlsSummary[] = $export['sum'][$key]; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 小号列表 * @author 鹿文学 */ public function small_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('account','小号'), array('fgame_name','游戏名称'), array('day','创建天数'), array('cumulative','累计充值'), array('register_time','创建时间'), array('lock_status','状态'), ); $pid = intval($_GET['id']); $xlsData = []; if(is_numeric($pid) && $pid>0) { $map['u.puid'] = $pid; if($_REQUEST['small']) {$map['u.account']=array('like','%'.$_REQUEST['small'].'%');} $data = M('User', 'tab_')->alias('u') ->field('u.account,u.register_time,u.cumulative,fgame_id,fgame_name,u.lock_status,DATEDIFF(curdate(),FROM_UNIXTIME(u.register_time,"%Y-%m-%d")) as day') ->join('tab_merchandise as m on ((m.status = 3 or m.status=0 or m.status = 4) and m.small_id = u.id) ') // 查询条件 ->where($map) /* 默认通过id逆序排列 */ ->order('u.register_time desc') /* 执行查询 */ ->select(); foreach($data as $k=>$v) { $data[$k]['register_time'] = date('Y-m-d H:i:s',$v['register_time']); $data[$k]['lock_status'] = '已锁定'; } $xlsData = $data; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 商品列表 * @author 鹿文学 */ public function merchandise() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('id','商品ID'), array('title','商品信息'), array('user_account','卖家账号'), array('day','创建天数'), array('accumulation','累计充值'), array('price','售价'), array('status','状态'), array('create_time','发布时间'), ); if(!empty($_REQUEST['account'])) {$extend['user_account']=array('like','%'.$_REQUEST['account'].'%');} if(!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {$extend['create_time'] = array('between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]);} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {$extend['create_time'] = array('between',[strtotime($_REQUEST['timestart']),time()]);} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {$extend['create_time'] = array('egt',strtotime($_REQUEST['timeend'])+86399);} if(is_numeric($_REQUEST['game_id']) && $_REQUEST['game_id']>0) {$extend['game_id']=$_REQUEST['game_id'];} if(is_numeric($_REQUEST['status'])) {$extend['status']=$_REQUEST['status'];} if(!empty($_REQUEST['keyword'])) {$extend['game_name|title|server_name|small_account']=array('like','%'.$_REQUEST['keyword'].'%');} if(!empty($_REQUEST['id'])) {$extend['id'] = $_REQUEST['id'];} $merchandise = M('Merchandise','tab_'); $data = $merchandise->field('id,title,game_name,server_name,small_account,user_account,day,accumulation,price,status,create_time') ->where($extend) ->order('id desc')->select(); foreach($data as $k=>$v) { $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $data[$k]['status'] = get_info_status($v['status'],41); } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 订单列表 * @author 鹿文学 */ public function order_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( // array('id','编号'), array('order_number','订单号'), array('title','商品信息'), // array('game_name','游戏名称'), // array('server_name','区服名称'), // array('small_account','小号账户'), // array('seller_account','卖家账号'), //// array('phone','卖家手机号'), array('buyer_account','交易用户'), array('order_price','售价'), array('poundage','手续费'), array('pay_status','状态'), array('order_time','下单时间'), // array('pay_time','付款时间'), // array('send_time','发货时间'), ); if(!empty($_REQUEST['order_number'])) {$extend['order_number']=array('like','%'.$_REQUEST['order_number'].'%');} if(!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {$extend['order_time'] = array('between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]);} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {$extend['order_time'] = array('between',[strtotime($_REQUEST['timestart']),time()]);} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {$extend['order_time'] = array('egt',strtotime($_REQUEST['timeend'])+86399);} if(is_numeric($_REQUEST['game_id']) && $_REQUEST['game_id']>0) {$extend['game_id']=$_REQUEST['game_id'];} if(is_numeric($_REQUEST['pay_status'])) {$extend['pay_status']=$_REQUEST['pay_status'];} if(!empty($_REQUEST['keyword'])) {$extend['game_name|title|server_name|small_account']=array('like','%'.$_REQUEST['keyword'].'%');} $data = M('Order','tab_')->alias('o')->field('o.id,o.order_number,o.seller_account,o.buyer_account,o.order_price,o.poundage,o.pay_status,o.order_time,o.pay_time,o.send_time,m.game_name,m.server_name,m.small_account,m.title,m.phone') ->join('tab_merchandise as m on (m.id = o.merchandise_id)') ->where($extend)->order('id desc')->select(); foreach($data as $k=>$v) { $data[$k]['order_time'] = $v['order_time']?date('Y-m-d H:i:s',$v['order_time']):''; $data[$k]['pay_time'] = $v['pay_time']?date('Y-m-d H:i:s',$v['pay_time']):''; $data[$k]['send_time'] = $v['send_time']?date('Y-m-d H:i:s',$v['send_time']):''; $data[$k]['pay_status'] = get_info_status($v['pay_status'],38); } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 用户金币提现记录列表 * @author 鹿文学 */ public function user_withdraw() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('id','编号'), array('order_number','提现单号'), array('user_account','账号'), array('coin','提现金币'), array('poundage','手续费'), array('money','实际到账'), array('gold_coin_balance','金币余额'), array('alipay','提现支付宝'), array('create_time','提现时间'), array('status','提现状态'), ); if(!empty($_REQUEST['order_number'])) {$extend['order_number']=array('like','%'.$_REQUEST['order_number'].'%');} if(!empty($_REQUEST['account'])) {$extend['user_account']=array('like','%'.$_REQUEST['account'].'%');} if(!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {$extend['create_time'] = array('between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]);} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {$extend['create_time'] = array('between',[strtotime($_REQUEST['timestart']),time()]);} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {$extend['create_time'] = array('egt',strtotime($_REQUEST['timeend'])+86399);} if(!empty($_REQUEST['alipay'])) {$extend['alipay']=array('like','%'.$_REQUEST['alipay'].'%');} if(is_numeric($_REQUEST['status'])) {$extend['status']=$_REQUEST['status'];} $wgc = M('WithdrawGoldCoin','tab_'); $data = $wgc->field('id,order_number,user_account,coin,poundage,money,gold_coin_balance,status,alipay,create_time') ->where($extend) ->order('id desc')->select(); foreach($data as $k=>$v) { $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $data[$k]['status'] = get_info_status($v['status'],39); } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 应用概况 * @author 鹿文学 */ public function device_survey() { $xlsName = $_REQUEST['xlsname'].'_'.$_REQUEST['name']; $num = I('num',2); $key = $_REQUEST['key']; if($key=='model') { $xlsCell = array( array('model',$_REQUEST['name']), array('version','系统版本'), array('count','数量'), ); } else { $xlsCell = array( array('time','日期'), array('version','系统版本'), array('count',$_REQUEST['name']), ); } if (is_file(RUNTIME_PATH.'/device_data_foldline.txt')) { $filetxt = file_get_contents(RUNTIME_PATH.'/device_data_foldline.txt'); $xlsData = $data[$key]; $xlsSummary[] = $data['sum'][$key]; } else { $start = I('start',date('Y-m-d',strtotime('-1 day'))); $end = I('end',date('Y-m-d',strtotime('-1 day'))); $starttime = strtotime($start); $endtime = strtotime($end)+86399; $device = D('DeviceRecord'); $flag = 1; if ($start == $end) { $hours = ['00~01','02~03','04~05','06~07','08~09','10~11','12~13','14~15','16~17','18~19','20~21','22~23']; foreach($hours as $v) { if ($key == 'news'){ $data['news']['ios'][$v] = 0; $data['news']['and'][$v] = 0; } if ($key == 'active'){ $data['active']['ios'][$v] = 0; $data['active']['and'][$v] = 0; } } // 新增设备 if ($key == 'news'){ $hoursnews = $device->news_on_time(['create_time'=>['between',[$starttime,$endtime]]],'news',5,'time,version'); foreach($hours as $v) { foreach($hoursnews as $h) { $time = explode(' ',$h['time']); if (strpos($v,$time[1]) !== false) { $data['news'][$h['version']==1?'and':'ios'][$v] += (integer)$h['news']; } } } } if ($key == 'active'){ // 活跃设备 $hoursactive = $device->active_on_time(['create_time'=>['between',[$starttime,$endtime]]],'active',5,'time,version'); foreach($hours as $v) { foreach($hoursactive as $h) { $time = explode(' ',$h['time']); if (strpos($v,$time[1]) !== false) { $data['active'][$h['version']==1?'and':'ios'][$v] += (integer)$h['active']; } } } } if ($key == 'model'){ // 启动机型 $hoursmodel = $device->model(['create_time'=>['between',[$starttime,$endtime]]]); foreach($hoursmodel as $k=>$h) { $data['model'][$h['version']==1?'and':'ios'][$h['model']] = (integer)$h['count']; } } } else { $datelist = get_date_list($starttime,$endtime,$num==7?2:1); $flag = 0; foreach($datelist as $k => $v) { if ($key == 'news'){ $data['news']['ios'][$v] = 0; $data['news']['and'][$v] = 0; } if ($key == 'active'){ $data['active']['ios'][$v] = 0; $data['active']['and'][$v] = 0; } } if ($key == 'news'){ // 新增设备 $news = $device->news_on_time(['create_time'=>['between',[$starttime,$endtime]]],'news',$num==7?2:1,'time,version'); foreach($datelist as $v) { foreach($news as $h) { if ($v == $h['time']) { $data['news'][$h['version']==1?'and':'ios'][$v] += (integer)$h['news']; } } } } if ($key == 'active'){ // 活跃设备 $active = $device->active_on_time(['create_time'=>['between',[$starttime,$endtime]]],'active',$num==7?2:1,'time,version'); foreach($datelist as $v) { foreach($active as $h) { if ($v == $h['time']) { $data['active'][$h['version']==1?'and':'ios'][$v] += (integer)$h['active']; } } } } if ($key == 'model'){ // 启动机型 $model = $device->model(['create_time'=>['between',[$starttime,$endtime]]]); foreach($model as $k=>$h) { $data['model'][$h['version']==1?'and':'ios'][$h['model']] = (integer)$h['count']; } } } foreach ($data as $k => $v) { $sum = 0;$tempexport=[]; if($k == 'model') { foreach($v['ios'] as $t => $s){ $tempexport[] = ['model'=>$t,'count'=>$s,'version'=>'ios']; } foreach($v['and'] as $t => $s){ $tempexport[] = ['model'=>$t,'count'=>$s,'version'=>'android']; } } else { foreach($v['ios'] as $t => $s){ $sum += $s; if($flag==1){ $tempexport[]=['time'=>$start.' '.(substr($t,0,2)).':00','count'=>$s,'version'=>'ios']; }else{ $tempexport[]=['time'=>$t,'count'=>$s,'version'=>'ios']; } } foreach($v['and'] as $t => $s){ $sum += $s; if($flag==1){ $tempexport[]=['time'=>$start.' '.(substr($t,0,2)).':00','count'=>$s,'version'=>'android']; }else{ $tempexport[]=['time'=>$t,'count'=>$s,'version'=>'android']; } } } $export[$k]=$tempexport; $export['sum'][$k]=$sum; } $xlsData = $export[$key]; $xlsSummary[] = $export['sum'][$key]; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 投放平台 * @author 鹿文学 */ public function platform() { $xlsName = $_REQUEST['xlsname']; $map['status'] = 1; if($_REQUEST['group']==1) { $xlsCell = array( array('id','编号'), array('name','名称'), array('promote_account','渠道'), array('create_time','创建时间'), array('update_time','最后更新时间'), ); $map['mark'] = 1; } else { $xlsCell = array( array('id','编号'), array('name','名称'), array('create_time','创建时间'), array('update_time','最后更新时间'), ); $map['mark'] = 0; } if(!empty($_REQUEST['name'])) {$map['name']=array('like','%'.$_REQUEST['name'].'%');} if(!empty($_REQUEST['promote_id'])) {$map['promote_id']=$_REQUEST['promote_id'];} $platform = D('LaunchPlatform'); $data = $platform->all_lists($map); foreach($data as $k => $v) { $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $data[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']); } $xlsData = $data; $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 投放数据统计 * @author 鹿文学 */ public function launch_data($p=1) { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('duration','日期'), array('platform_name','投放平台'), array('game_name','游戏名称'), array('new','新增用户数'), array('new_device','新增设备'), array('new_pay','新增付费数'), array('new_rate','新增付费率'), array('new_money','新增付费金额'), array('active','活跃用户数'), array('active_pay','活跃付费人数'), array('active_money','活跃付费金额'), array('active_rate','活跃付费率'), array('active_arpu','活跃ARPU'), array('pay_arpu','付费ARPU'), ); if (is_file(RUNTIME_PATH.'/access_data_launch.txt')) { $filetxt = file_get_contents(RUNTIME_PATH.'/access_data_launch.txt'); $data = json_decode($filetxt,true); } else { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}//10; $currentdate = mktime(0,0,0,date('m'),date('d'),date('Y')); $map = array(); if(is_numeric($_REQUEST['game_id']) && $_REQUEST['game_id']>0) {$map['game_id']=$_REQUEST['game_id'];} if(is_numeric($_REQUEST['promote_id']) && $_REQUEST['promote_id']>0) {$map['promote_id']=$_REQUEST['promote_id'];} if(is_numeric($_REQUEST['platform_id']) && $_REQUEST['platform_id']>0) {$map['platform_id']=$_REQUEST['platform_id'];} $launchrecord = D('LaunchRecord'); if(!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) { $start = strtotime($_REQUEST['timestart']); $end = strtotime($_REQUEST['timeend']); if($start<=$end){ if($end>=$currentdate) { $data = $launchrecord->lists($p,$map,$start,$currentdate+86399); } else { $data = $launchrecord->data($p,$map,array('duration'=>['between',[$start,$end+86399]])); } } } elseif(!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) { $start = strtotime($_REQUEST['timestart']); $data = $launchrecord->lists($p,$map,$start,$currentdate+86399); } elseif(empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) { $end = strtotime($_REQUEST['timeend']); if($end>=$currentdate) { $data = $launchrecord->lists($p,$map,'',$currentdate+86399); } else { $data = $launchrecord->data($p,$map,array('duration'=>['lt',$end+86399])); } } else { $data = $launchrecord->data($p,$map,array('duration'=>['lt',$currentdate])); } $current = $data['current']; $total = $data['total']; $current['duration'] = '当页汇总'; $total['duration'] = '全部汇总'; $data = $data['data']; if($map['game_id']) {$total['game_id']=$current['game_id']=$map['game_id'];} if($map['platform_id']) {$total['platform_id']=$current['platform_id']=$map['platform_id'];} $data[] = $current; $data[] = $total; } foreach ($data as $v) { if(is_numeric($v['duration'])) { $v['platform_name'] = get_launch_platform_name($v['platform_id'],'全部'); $v['game_name'] = get_game_name_by_id($v['game_id'],'全部'); $v['duration'] = date('Y-m-d',$v['duration']); } else { $v['platform_name'] = get_launch_platform_name($v['platform_id'],'--'); $v['game_name'] = get_game_name_by_id($v['game_id'],'--'); } $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 登录记录 * @author 鹿文学 */ public function login_record() { $xlsName = $_REQUEST['xlsname']; // $xlsCell = array( // array('user_account','玩家账号'), // array('game_name','游戏名称'), // array('server_name','游戏区服'), // array('user_nickname','角色名'), // array('login_time','登录时间'), // array('login_ip','最后登录ip'), // ); $xlsCell = array( '玩家账号', '游戏名称', '游戏区服', '角色名', '登录时间', '最后登录ip', ); if (isset($_REQUEST['login_ip'])) { $map['login_ip'] = $_REQUEST['login_ip']; } if (isset($_REQUEST['game_id'])) { $map['game_id'] = $_REQUEST['game_id']; } if (isset($_REQUEST['game_name'])) { $map['game_name'] = ['like', $_REQUEST['game_name']."%"]; unset($_REQUEST['game_name']); } if (isset($_REQUEST['game_type'])) { $map['sdk_version'] = $_REQUEST['game_type']; unset($_REQUEST['game_type']); } if (isset($_REQUEST['server_name'])) { $map['server_name'] = $_REQUEST['server_name']; unset($_REQUEST['server_name']); } if (isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])) { $map['login_time'] = array('BETWEEN', array(strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1)); }elseif(isset($_REQUEST['timestart'])){ $map['login_time'] = array('GT',strtotime($_REQUEST['timestart'])); }elseif(isset($_REQUEST['timeend'])){ $map['login_time'] = array('lt',(strtotime($_REQUEST['timeend'])+ 24 * 60 * 60 - 1)); } if (isset($_REQUEST['account'])) { $map['user_account'] = array('like', '%' . trim($_REQUEST['account']) . '%'); } // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); if (isset($_REQUEST['promote_id'])) { $map['promote_id'] = $_REQUEST['promote_id']; } // $map['login_time'] = array('neq', 0); $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; //查询数量 $accessNum = M('UserLoginRecord','tab_') ->where($map)->order('id desc')->count(); if ($accessNum > 1000000) { echo "数据量过大,大于100万";die(); } $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $perSize = 50000;//每次查询的条数 $pages = ceil($accessNum / $perSize); for($i = 1; $i <= $pages; $i++) { $data = M('UserLoginRecord','tab_') ->field("user_account,game_name,server_name,user_nickname,login_time,login_ip") ->where($map) ->limit(($i-1)*$perSize ,$perSize) ->order('id desc') ->select(); foreach($data as $k => $v) { $v['login_time'] = date('Y-m-d H:i:s',$v['login_time']); $v['server_name'] = empty($v['server_name'])?'空':$v['server_name']; // $gamename=trim(get_game_name($v['game_id'],'id')); $v['game_name'] = empty($v['game_name'])?'官网登录':$v['game_name']; $xlsData[] = $v; mb_convert_variables('GBK', 'UTF-8', $v); fputcsv($fp, $v); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } // $xlsData = []; exit(); // $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 账户修改记录 * @author 鹿文学 */ public function account_updatelist() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('user_account','玩家账号'), array('game_name','游戏名称'), array('type','货币类型'), array('prev_amount','修改前余额'), array('amount','修改后余额'), array('create_time','修改时间'), array('op_account','操作人员'), ); if (isset($_REQUEST['login_ip'])) { $map['login_ip'] = $_REQUEST['login_ip']; } if (isset($_REQUEST['game_id'])) { $map['game_id'] = $_REQUEST['game_id']; } if (isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])) { $map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 24 * 60 * 60 - 1)); }elseif(isset($_REQUEST['timestart'])){ $map['create_time'] = array('GT',strtotime($_REQUEST['timestart'])); }elseif(isset($_REQUEST['timeend'])){ $map['create_time'] = array('lt',(strtotime($_REQUEST['timeend'])+ 24 * 60 * 60 - 1)); } if (isset($_REQUEST['account'])) { $map['user_account'] = array('like', '%' . trim($_REQUEST['account']) . '%'); } if(isset($_REQUEST['huobi'])){ $map['type'] = $_REQUEST['huobi']; } if(!empty($_REQUEST['op_account'])){ $map['op_account'] = trim($_REQUEST['op_account']); } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=M('balance_edit','tab_') ->where($map) ->order('create_time desc') ->select(); $xlsData = []; foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['game_name'] = empty($v['game_name'])?'空':$v['game_name']; $v['op_account'] = empty($v['op_account'])?'空':$v['op_account']; $v['type']=trim(get_info_status($v['type'],17)); $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 管理员列表 * @author 鹿文学 */ public function manager_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('uid','账号ID'), array('nickname','管理员账号'), array('group_name','角色类型'), array('login','登录次数'), array('last_login_time','最后登录时间'), array('last_login_ip','最后登录IP'), array('status','状态'), ); $nickname = I('nickname'); if(is_numeric($nickname)){ $map['uid|nickname']= array(intval($nickname),array('like','%'.$nickname.'%'),'_multi'=>true); }else{ $map['nickname'] = array('like', '%'.(string)$nickname.'%'); } if(isset($_REQUEST['status'])){ $map['status'] = $_REQUEST['status']; } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=M('Member') ->where($map) ->order('uid desc') ->select(); $xlsData = []; foreach($data as $k => $v) { $v['last_login_time'] = empty($v['last_login_time'])?'暂无登录':date('Y-m-d H:i:s',$v['last_login_time']); $v['group_name']=trim(get_auth_group_name($v['uid'])); $v['last_login_ip']=trim(long2ip($v['last_login_ip'])); $v['status']=trim(get_status_title($v['status'])); $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 系统检查 * @author 鹿文学 */ public function check_lists() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('id','序号'), array('info','异常简介'), array('url','异常简介'), array('type','异常类型'), array('create_time','异常时间'), array('status','异常状态'), ); if(!empty($_REQUEST['start']) && !empty($_REQUEST['end'])){ $map['create_time'] = array('BETWEEN',array(strtotime(I('start')),strtotime(I('end'))+24*60*60-1)); }elseif(!empty($_REQUEST['start'])){ $map['create_time'] =array('egt',strtotime(I('start'))); }elseif(!empty($_REQUEST['end'])){ $map['create_time'] = array('elt',strtotime(I('end'))+24*60*60-1); } if(isset($_REQUEST['type'])){ $map['type'] = $_REQUEST['type']; } if(is_numeric($_REQUEST['status']) && $_REQUEST['status']>=0 && $_REQUEST['status']<3) {$map['status'] = $_REQUEST['status'];} else {$map['status']=array('egt',0);} if(is_numeric($_REQUEST['t']) && $_REQUEST['t']>0 && $_REQUEST['t']<5) { $map['type'] = array('like',$_REQUEST['t'].'%'); } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=M('Check','tab_') ->where($map) ->order('id desc') ->select(); $xlsData = []; foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['status']=trim(get_info_status($v['status'],40)); $v['type']=trim(get_bug_name_by_id($v['type'])); $v['url']=!empty(trim($v['url']))?($_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].trim($v['url'])):''; $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 商务专员列表 * @author 鹿文学 */ public function business_affairs_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('id','编号'), array('account','商务专员账号'), array('sw_name','姓名'), array('phone','联系电话'), array('qq','QQ号'), array('inferiors','旗下推广员数'), array('create_time','创建时间'), array('status','状态'), ); if (isset($_REQUEST['account'])) { $map['account'] = $_REQUEST['account']; unset($_REQUEST['account']); } if (isset($_REQUEST['status'])) { $map['status'] = $_REQUEST['status']; unset($_REQUEST['status']); } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=M('business_affairs','tab_') ->where($map) ->order('id desc') ->select(); $xlsData = []; foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['status']=trim(get_info_status($v['status'],30)); $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 平台币发放 * @author 鹿文学 */ public function promote_coin_send_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('promote_account','推广员账号'), array('promote_type','推广员等级'), array('banlan_type','发放类型'), array('num','发放数量'), array('create_time','发放时间'), array('op_account','发放人员'), ); // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($extend,'promote_id'); if(empty($_REQUEST['promote_id']&&$_REQUEST['promote_type'])){ $map['type'] = 1; $map['source_id'] = 0; }else{ $map['promote_id'] = $_REQUEST['promote_id']; $map['promote_type'] = $_REQUEST['promote_type']; } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $promotecoin = M('PromoteCoin','tab_'); $data=$promotecoin ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['promote_account']=trim(get_promote_account($v['promote_id'])); $v['promote_type']=trim(get_info_status($v['promote_type'],20)); $v['banlan_type']=trim(get_banlan_type($v['banlan_type'])); $v['op_account']=trim(get_nickname($v['op_id'])); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 平台币收回 * @author 鹿文学 */ public function deduct_list() { $xlsName = $_REQUEST['xlsname']; if($_REQUEST['type']==2) { $xlsCell = array( array('promote_account','所属推广员'), array('promote_type','推广员等级'), array('num','收回数量'), array('create_time','收回时间'), array('op_account','收回人员'), ); $map['type'] = 2; $map['source_id'] = 0; $extend['op_id'] = session('user_auth')['uid']; // $promoteRoot = getPowerPromoteIds(); // $data_empower_type = session('user_auth')['data_empower_type']; // // if ($promoteRoot) { // $map['promote_id'] =array('in',$promoteRoot); // } else if(!$promoteRoot&&$data_empower_type!=1){ // $map['id'] = array('lt',1); // } setPowerPromoteIds($map,'promote_id'); if(isset($_REQUEST['promote_id'])) { $map['promote_id'] = $_REQUEST['promote_id']; } if(isset($_REQUEST['promote_type'])) { $map['promote_type'] = $_REQUEST['promote_type']; } $model = M('PromoteCoin','tab_'); }else { $xlsCell = array( array('user_account','玩家账号'), array('coin_type','收回类型'), array('num','收回数量'), array('create_time','收回时间'), array('op_account','收回人员'), ); $extend['op_id'] = session('user_auth')['uid']; $model = M('user_coin','tab_'); if(isset($_GET['account'])){ $map['user_account']= array('like','%'.I('account').'%') ; } } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['op_account']=trim(get_nickname($v['op_id'])); $v['promote_account']=trim(get_promote_account($v['promote_id'])); $v['promote_type']=trim(get_info_status($v['promote_type'],20)); $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['op_account']=trim(get_nickname($v['op_id'])); $v['coin_type'] = '平台币'; $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 绑币收回 * @author 鹿文学 */ public function deduct_bind_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('user_account','玩家账号'), array('game_name','游戏名称'), array('coin_type','收回类型'), array('quantity','收回数量'), array('create_time','收回时间'), array('execute_account','收回人员'), ); $model = M('DeductBindRecord','tab_'); if(isset($_GET['account'])){ $map['user_account']= array('like','%'.I('account').'%') ; } $extend['execute_id'] = session('user_auth')['uid']; $map['execute_id'] = session('user_auth')['uid']; $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['coin_type'] = '绑定平台币'; $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 返利设置 * @author 鹿文学 */ public function rebate_set_list() { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( array('promote_account','返利对象'), array('game_name','游戏名称'), array('status','金额限制状态'), array('money','金额限制'), array('ratio','返利比例'), array('time','返利周期'), array('create_time','添加时间'), ); $model = M('rebate','tab_'); if(isset($_REQUEST['game_name'])){ if($_REQUEST['game_name']=='全部'){ }else{ $map['game_name'] = $_REQUEST['game_name']; } } if(isset($_REQUEST['status'])){ if($_REQUEST['status']=='全部'){ }else{ $map['status'] = $_REQUEST['status']; } } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['promote_account'] = ($v['promote_id']==1)?'推广渠道':(($v['promote_id']==0)?'官方渠道':'全站玩家'); $v['status'] = get_info_status($v['status']); $v['ratio'] = ratio_stytl($v['ratio']); $v['time'] = set_show_time($v['starttime'],'','forever') .'至'.set_show_time($v['endtime'],'','forever'); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 折扣设置 * @author 鹿文学 */ public function promote_welfare_list() { $xlsName = $_REQUEST['xlsname']; $model = M('PromoteWelfare','tab_'); if(isset($_REQUEST['game_id']) ){ $map['game_id'] = $_REQUEST['game_id']; } if(isset($_REQUEST['promote_id']) ){ $map['promote_id'] = $_REQUEST['promote_id']; } if($_REQUEST['type']==2) { $xlsCell = array( array('discount_obj_name','折扣对象'), array('game_name','游戏名称'), array('first_discount','首充折扣'), array('continue_discount','续充折扣'), array('create_time','设置时间'), array('op_account','设置人员'), array('promote_status','首充状态'), array('cont_status','续充状态'), ); $map['status'] = 2; $show_status = 1; if(isset($_REQUEST['promote_status']) ){ $map['promote_status'] = $_REQUEST['promote_status']; } if(isset($_REQUEST['cont_status']) ){ $map['cont_status'] = $_REQUEST['cont_status']; } } else { $xlsCell = array( array('promote_account','推广员账号'), array('game_name','游戏名称'), array('game_discount','统一折扣'), array('promote_discount','推广员折扣'), array('create_time','设置时间'), array('op_account','设置人员'), array('recharge_status','折扣状态'), ); $map['status'] = 1; if(isset($_REQUEST['recharge_status']) ){ $map['recharge_status'] = $_REQUEST['recharge_status']; } } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['promote_status'] = get_info_status($v['promote_status']); $v['cont_status'] = get_info_status($v['cont_status']); $v['discount_obj_name'] = get_discount_obj_name($v['promote_id']); $v['op_account'] = get_admin_name($v['op_id']); $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['recharge_status'] = get_info_status($v['recharge_status']); $v['promote_account'] = get_promote_name($v['promote_id']); $v['op_account'] = get_admin_name($v['op_id']); $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 游戏列表 * @author 鹿文学 */ public function game_list() { $xlsName = $_REQUEST['xlsname']; $model = M('game','tab_'); if(isset($_REQUEST['game_name'])){ $extend['game_name'] = ['like', "{$_REQUEST['game_name']}%"]; } if(isset($_REQUEST['sdk_version1'])){ $map['sdk_version']=$_REQUEST['sdk_version1']; } if(isset($_REQUEST['recommend_status'])){ $map['recommend_status']=$_REQUEST['recommend_status']; } if(isset($_REQUEST['game_status'])){ $map['game_status']=$_REQUEST['game_status']; } if(isset($_REQUEST['apply_status'])){ $map['apply_status']=$_REQUEST['apply_status']; } if(isset($_REQUEST['online_status'])){ $map['online_status']=$_REQUEST['online_status']; } if($_REQUEST['type']==2) { $xlsCell = array( array('id','游戏ID'), array('game_name','游戏名称'), array('sdk_version','运营平台'), array('game_type','游戏类型'), array('developers','游戏来源'), array('sort','排序'), array('apply_status','审核状态'), array('game_status','显示状态'), array('online_status','上线状态'), array('create_time','添加时间'), ); $map['developers'] = array('GT',0); } else { $xlsCell = array( array('id','游戏ID'), array('game_name','游戏名称'), array('sdk_version','运营平台'), array('game_type','游戏类型'), array('game_appid','游戏Appid'), array('recommend_status','推荐状态'), array('game_status','显示状态'), array('dow_num','下载次数'), array('sort','排序'), array('relation_game','关联'), /* array('relation_game_id','关联游戏编号'), */ ); $map['developers'] = array('EQ',0); } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('sort desc, id desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d',$v['create_time']); $v['sdk_version'] = get_systems_name($v['sdk_version']); $v['game_type'] = get_game_type_name($v['game_type_id']); $v['developers'] = get_developer_name($v['developers']); $v['apply_status'] = get_info_status($v['apply_status'],5); if($v['apply_status'] > 0) { $v['online_status'] = empty($v['online_status'])?'已下线':'上线'; $v['game_status'] = empty($v['game_status'])?'已关闭':'已开启'; } else { $v['online_status']='--'; $v['game_status']='--'; } $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['sdk_version'] = get_systems_name($v['sdk_version']); $v['game_type'] = get_game_type_name($v['game_type_id']); $v['recommend_status'] = get_info_status($v['recommend_status'],1); $v['game_status'] = empty($v['game_status'])?'已关闭':'已开启'; $v['relation_game'] = get_relation_game($v['id'],$v['relation_game_id'])?'已关联':'未关联'; /* $v['relation_game_id'] = $v['relation_game_id']>0?$v['relation_game_id']:'--'; */ $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 游戏类型 * @author 鹿文学 */ public function game_type_list() { $xlsName = $_REQUEST['xlsname']; if($_REQUEST['type']==2) { $xlsCell = array( array('open_name','类型名称'), array('status','显示状态'), array('op_nickname','添加人员'), array('create_time','添加时间'), ); $model = M('Opentype','tab_'); if(isset($_REQUEST['status_show'])){ if($_REQUEST['status_show']!='all'){ $map['status'] = $_REQUEST['status_show']; } } } else { $xlsCell = array( array('type_name','游戏类型'), array('status_show','显示状态'), array('op_nickname','添加人员'), array('create_time','添加时间'), ); $model = M('GameType','tab_'); if(isset($_REQUEST['status_show'])){ if($_REQUEST['status_show']!='all'){ $map['status_show'] = $_REQUEST['status_show']; } } } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['status'] = '已' . get_info_status($v['status']); $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['status_show'] = '已' . get_info_status($v['status_show']); $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 游戏原包 * @author 鹿文学 */ public function game_source_list() { $xlsName = $_REQUEST['xlsname']; if(isset($_REQUEST['game_name'])){ $map['game_name']=array('like','%'.$_REQUEST['game_name'].'%'); } if(isset($_REQUEST['sdk_version1'])){ $map['file_type']=$_REQUEST['sdk_version1']; } $model = M('GameSource','tab_'); if($_REQUEST['type']==2) { $xlsCell = array( array('developer_account','开发者账号'), array('game_name','游戏名称'), array('file_type','运营平台'), array('file_name','游戏包名'), array('version','游戏版本'), array('file_size','原包大小'), array('pay_notify_url','支付通知地址'), array('create_time','上传时间'), ); $map['develop_id'] = array('NEQ',0); } else { $xlsCell = array( array('game_name','游戏名称'), array('file_name','原包名称'), array('file_type','运营平台'), array('file_size','原包大小'), array('file_url','原包路径'), array('version','原包版本'), array('op_account','操作人员'), array('create_time','操作时间'), ); $map['develop_id'] = 0; } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['file_type'] = get_systems_name($v['file_type']); $v['developer_account'] = get_developer_account($v['develop_id']); $v['pay_notify_url'] = get_game_set_field($v['game_id'],'pay_notify_url'); $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['file_type'] = get_systems_name($v['file_type']); $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 自建官网 * @author 鹿文学 */ public function selfbuilt_list() { $xlsName = $_REQUEST['xlsname']; $model = M('Selfbuilt'); $xlsCell = array( array('id','编号'), array('game_name','游戏名称'), array('webname','官网名称'), array('template','模板名称'), array('weburl','域名'), ); $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['game_name'] = get_gamename($v['gameid']); $v['template'] = get_tepname($v['templateid']); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 区服列表 * @author 鹿文学 */ public function server_list() { $xlsName = $_REQUEST['xlsname']; if(isset($_REQUEST['show_status'])){ $map['show_status']=$_REQUEST['show_status']; } if(isset($_REQUEST['server_version'])){ $map['server_version']=$_REQUEST['server_version']; } if(isset($_REQUEST['timestart']) && isset($_REQUEST['timeend'])){ $map['start_time'] = array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); }elseif(isset($_REQUEST['timestart'])){ $map['start_time']=array('EGT',strtotime($_REQUEST['timestart'])); }elseif(isset($_REQUEST['timeend'])){ $map['start_time']=array('ELT',strtotime($_REQUEST['timeend'])); } if(isset($_REQUEST['game_name'])){ if($_REQUEST['game_name']=='全部'){ unset($_REQUEST['game_name']); }else{ $map['server_version']=$_REQUEST['server_version']; $map['game_name']=['like', "{$_REQUEST['game_name']}%"]; unset($_REQUEST['game_name']); } } if(isset($_REQUEST['server_name'])){ $map['server_name']=$_REQUEST['server_name']; unset($_REQUEST['server_name']); } $model = M('Server','tab_'); if($_REQUEST['type']==2) { $xlsCell = array( array('developer_account','开发者账号'), array('game_name','游戏名称'), array('server_name','区服名称'), array('server_version','运营平台'), array('show_status','显示状态'), array('start_time','开服时间'), ); $map['developers'] = array('NEQ',0); } else { $xlsCell = array( array('game_name','游戏名称'), array('server_name','区服名称'), array('server_version','运营平台'), array('show_status','显示状态'), array('start_time','开服时间'), ); $map['developers'] = 0; } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['start_time'] = date('Y-m-d H:i:s',$v['start_time']); $v['show_status'] = $v['show_status']==1?'已开启':'已关闭'; $v['developer_account'] = get_developer_account($v['developers']); $v['server_version'] = get_systems_name($v['server_version']); $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['start_time'] = date('Y-m-d H:i:s',$v['start_time']); $v['show_status'] = $v['show_status']==1?'已开启':'已关闭'; $v['server_version'] = get_systems_name($v['server_version']); $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 礼包列表 * @author 鹿文学 */ public function giftbag_list() { $xlsName = $_REQUEST['xlsname']; if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ $map['create_time'] =array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); }elseif(isset($_REQUEST['timestart'])){ $map['create_time']=array('egt',strtotime($_REQUEST['timestart'])); }elseif(isset($_REQUEST['timeend'])){ $map['create_time']=array('elt',strtotime($_REQUEST['timeend'])+24*60*60-1); } if(isset($_REQUEST['game_name'])){ if($_REQUEST['game_name']=='全部'){ }else{ $map['game_name']=$_REQUEST['game_name']; } } if(isset($_REQUEST['giftbag_name'])){ $map['giftbag_name']=array('like','%'.$_REQUEST['giftbag_name'].'%'); } if(isset($_REQUEST['status'])){ if($_REQUEST['status']=='全部'){ }else{ $map['status']=$_REQUEST['status']; } } if(isset($_REQUEST['giftbag_version'])){ if($_REQUEST['giftbag_version']=='全部'){ }else{ $map['giftbag_version']=$_REQUEST['giftbag_version']; } } if(isset($_REQUEST['developers'])){ $map['developers']=$_REQUEST['developers']; } $model = M('Giftbag','tab_'); if($_REQUEST['type']==2) { $xlsCell = array( array('developer_account','开发者账号'), array('game_name','游戏名称'), array('giftbag_name','礼包名称'), array('giftbag_version','运营平台'), array('novice_num','礼包总数'), array('surplus','剩余数量'), array('status','显示状态'), array('create_time','更新时间'), array('time','有效时间'), ); $map['developers'] = array('NEQ',0); } else { $xlsCell = array( array('game_name','游戏名称'), array('giftbag_name','礼包名称'), array('giftbag_version','运营平台'), array('novice_num','礼包总数'), array('surplus','剩余数量'), array('status','显示状态'), array('create_time','更新时间'), array('time','有效时间'), ); $map['developers'] = 0; } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('create_time desc') ->select(); $xlsData = []; if(is_array($data)){ if($_REQUEST['type']==2) { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['status'] = $v['status']==1?'已开启':'已关闭'; $v['developer_account'] = get_developer_account($v['developers']); $v['giftbag_version'] = get_systems_name($v['giftbag_version']); $v['time'] = set_show_time($v['start_time'],'date') .'至'.set_show_time($v['end_time'],'date','forever'); $v['surplus'] = arr_count($v['novice']); $xlsData[] = $v; } } else { foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['status'] = $v['status']==1?'已开启':'已关闭'; $v['giftbag_version'] = get_systems_name($v['giftbag_version']); $v['time'] = set_show_time($v['start_time'],'date') .'至'.set_show_time($v['end_time'],'date','forever'); $v['surplus'] = arr_count($v['novice']); $xlsData[] = $v; } } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 推广员列表 * @author 鹿文学 */ public function promote_list() { $xlsName = $_REQUEST['xlsname']; if($_REQUEST['type']==2) { $xlsCell = array( array('id','编号'), array('promote_account','推广员账号'), array('url_type','站点来源'), array('site_url','站点链接'), array('status','审核状态'), array('create_time','创建时间'), ); $model = M('SiteApply','tab_'); if(isset($_REQUEST['promote_id'])){ $map['promote_id']=$_REQUEST['promote_id']; } if(isset($_REQUEST['url_type'])){ $map['url_type']=$_REQUEST['url_type']; } if(isset($_REQUEST['status'])){ $map['status']=$_REQUEST['status']; } //为数据权限添加 setPowerPromoteIds($map); } else { $xlsCell = array( array('id','推广员ID'), array('account','推广员账号'), array('mobile_phone','手机号码'), array('balance_coin','平台币余额'), array('total_money','总流水'), array('create_time','注册时间'), array('last_login_time','最后登录时间'), array('promote_levels','渠道类型'), array('grand_account','所属会长'), array('business_affairs','商务专员'), array('status','状态'), array('ver_status','身份认证'), array('oa_associated','OA关联') ); $model = M('Promote','tab_'); if(isset($_REQUEST['promote_id'])){ $map['tab_promote.id']=$_REQUEST['promote_id']; } if(isset($_REQUEST['admin_id'])){ if($_REQUEST['admin_id']=="全部"){ }else{ $map['ba_id']=$_REQUEST['admin_id']; } } if (isset($_REQUEST['parent_id'])) { if ($_REQUEST['parent_id']=='全部') { unset($_REQUEST['parent_id']); } $zid=get_zi_promote_id($_REQUEST['parent_id']); if($zid){ $zid=$zid.','.$_REQUEST['parent_id']; }else{ $zid=$_REQUEST['parent_id']; } $map['tab_promote.id']=array('in',$zid); } if (I("promote_level")) { $map['level'] = I("promote_level"); } if(I('oa_associated',-1) != -1) { $map['oa_associated'] = I('oa_associated'); } if (I("ver_status")) { $map['ver_status'] = I("ver_status"); } if (I("ver_status")) { $map['tab_promote.ver_status'] = I("ver_status"); } if (I('status')) { $map['tab_promote.status'] = I('status'); } if (strlen(I('company_belong'))) { $map['company_belong'] = I("company_belong"); } if (!is_null(I('admin_uid', null))) { $map['admin_id'] = I('admin_uid'); } //为数据权限添加 setPowerPromoteIds($map, 'tab_promote.id'); } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $xlsData = []; // if(is_array($data)){ if($_REQUEST['type']==2) { $data=$model ->where($map) ->order('create_time desc') ->select(); foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['status'] = $v['status']==1?'已审核':'未审核'; $v['url_type'] = get_info_status($v['url_type'],24); $v['promote_account'] = get_promote_account($v['promote_id']); $xlsData[] = $v; } } else { // sum_promote_total_money() $xlsData = $model ->field("tab_promote.id,tab_promote.account,mobile_phone,balance_coin,total_money,tab_promote.create_time ,tab_promote.last_login_time,tab_business_affairs.account as business_affairs,tab_promote.status, REPLACE(substring_index(tab_promote.chain, '/', 2),'/','') as top_promote,sum(pay_amount) as pay_amount,tab_promote.level as promote_levels,tab_promote.ver_status,tab_promote.oa_associated") ->join("left join tab_business_affairs on ba_id = tab_business_affairs.id") ->join("left join tab_spend on tab_promote.id = tab_spend.promote_id and pay_status=1") ->where($map) ->order('create_time desc') ->group("tab_promote.id") ->select(false); $xlsData = M()->table("({$xlsData}) as a") ->field("a.id,a.account,a.mobile_phone,a.balance_coin,a.create_time,a.last_login_time, a.promote_levels,tab_promote.account as grand_account,a.business_affairs,a.status,pay_amount as total_money,a.ver_status,a.oa_associated") ->join("left join tab_promote on tab_promote.id = a.top_promote") ->order('a.id desc') ->select(); foreach($xlsData as $k => &$v) { $v['create_time'] = $v['create_time']?date('Y-m-d H:i',$v['create_time']):''; $v['last_login_time'] = $v['last_login_time']?date('Y-m-d H:i',$v['last_login_time']):'暂无登录'; if (!$v['business_affairs']) { $v['business_affairs'] = "暂无"; } if (!$v['grand_account']) { $v['grand_account'] = $v['account']; } $v['status'] = get_info_status($v['status'],3); // $v['business_affairs'] = get_business_affairs_account($v['ba_id']); // $v['grand_account'] = getTopPromote($v['id'])['id']; // $v['promote_levels'] = get_promote_levels($v['id']); switch ($v['ver_status']) { case '1': $v['ver_status'] = "成功"; break; case '2': $v['ver_status'] = "拒绝"; break; case '3': $v['ver_status'] = "正在审核"; break; case '4': $v['ver_status'] = "修改审核中"; break; default: $v['ver_status'] = '未认证'; } switch ($v['promote_levels']) { case '1': $v['promote_levels'] = "会长"; break; case '2': $v['promote_levels'] = "部门长"; break; case '3': $v['promote_levels'] = "组长"; break; case '4': $v['promote_levels'] = "组员"; break; default: $v['promote_levels'] = ''; } if ($v['oa_associated']==1) { $v['oa_associated'] = "关联"; } else { $v['oa_associated'] = "未关联"; } } } // } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 游戏分包列表 * @author 鹿文学 */ public function game_subpackage_list() { $xlsName = $_REQUEST['xlsname']; if(isset($_REQUEST['game_name'])){ if($_REQUEST['game_name']=='全部'){ unset($_REQUEST['game_name']); }else{ $map['game_id']=get_game_id($_REQUEST['game_name']); unset($_REQUEST['game_name']); } } if (is_numeric($_REQUEST['game_id']) && $_REQUEST['game_id']>0) { $map['game_id'] = $_REQUEST['game_id']; unset($_REQUEST['game_id']); } if (is_numeric($_REQUEST['promote_id']) && $_REQUEST['promote_id']>0) { $map['tab_apply.promote_id'] = $_REQUEST['promote_id']; unset($_REQUEST['promote_id']); } if(isset($_REQUEST['promote_account'])){ $map['account']=get_promote_id($_REQUEST['promote_account']); unset($_REQUEST['promote_account']); } if(isset($_REQUEST['status'])){ if($_REQUEST['status']=='全部'){ unset($_REQUEST['status']); }else{ $map['status']=$_REQUEST['status']; unset($_REQUEST['status']); } } if(isset($_REQUEST['enable_status'])){ if($_REQUEST['enable_status']=='全部'){ unset($_REQUEST['enable_status']); }elseif($_REQUEST['enable_status']==0){ //$map['dow_url'] = ''; $map['enable_status'] = $_REQUEST['enable_status']; unset($_REQUEST['enable_status']); }else{ //$map['dow_url']=array('neq',''); $map['enable_status'] = $_REQUEST['enable_status']; unset($_REQUEST['enable_status']); } } if(isset($_REQUEST['dow_status'])){ if($_REQUEST['dow_status']=='全部'){ unset($_REQUEST['dow_status']); }else{ $map['tab_apply.dow_status']=$_REQUEST['dow_status']; unset($_REQUEST['dow_status']); } } $model = M('Apply','tab_'); $xlsCell = array( array('promote_account','推广员账号'), array('game_name','游戏名称'), array('launch_count','投放平台'), array('apply_time','申请时间'), array('status','审核状态'), array('enable_status','打包状态'), array('dispose_time','审核时间'), array('dow_status','下载状态'), array('ratio','分成比例'), array('money','注册单价'), ); if($_REQUEST['type']==2) { $map['tab_apply.sdk_version']= 2; } else { $map['tab_apply.sdk_version']= 1; } $type = $_REQUEST['type'] || 1; $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; //为数据权限添加 setPowerPromoteIds($map); $data=$model ->field('tab_apply.*,tab_game.ratio as game_ratio,tab_game.money as game_money') ->join('LEFT JOIN tab_game ON tab_apply.game_id = tab_game.id') ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ $launchmodel = M('apply_launch','tab_'); foreach($data as $k => $v) { $v['apply_time'] = date('Y-m-d H:i',$v['apply_time']); $v['dispose_time'] = $v['dispose_time']>0?date('Y-m-d H:i:s',$v['dispose_time']):'--'; $v['status'] = get_info_status($v['status'],5); $v['promote_account'] = get_promote_name($v['promote_id']); $v['game_name'] = get_game_name($v['game_id']); $ratio = is_null($v['promote_ratio'])?$v['game_ratio']:$v['promote_ratio']; $ratio || $ratio = 0; $money = is_null($v['promote_money'])?$v['game_money']:$v['promote_money']; $money || $money = 0; $v['ratio']=$ratio; $v['money']=$money; if($type==2) { $v['dow_status'] = $v['dow_status']==1?'已开启':'已关闭'; }else{ $v['dow_status'] = empty($v['pack_url'])?'已关闭':($v['dow_status']==1?'已开启':'已关闭'); } $v['enable_status'] = $v['enable_status']==1?'打包成功':($v['enable_status']==2?'准备打包':($v['enable_status']==3?'打包中':($v['enable_status']==-1?'打包失败':'未打包'))); $v['launch_count']=0; $v['launch_count'] = $launchmodel->where(['apply_id'=>$v['id']])->count(); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 游戏盒子分包列表 * @author 鹿文学 */ public function app_subpackage_list() { $xlsName = $_REQUEST['xlsname']; "" == I('status') || $map['status'] = I('status'); "" == I('promote_id') || $map['promote_id'] = I('promote_id'); "" == I('enable_status') || $map['enable_status'] = I('enable_status'); $model = M('app_apply','tab_'); $xlsCell = array( array('promote_account','推广员账号'), array('app_name','APP名称'), array('apply_time','申请时间'), array('status','审核状态'), array('enable_status','打包状态'), array('dispose_account','审核人员'), array('dispose_time','审核时间'), ); if($_REQUEST['type']==2) { $map['app_version'] = 2; } else { $map['app_version'] = 1; } $type = $_REQUEST['type'] || 1; $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('apply_time desc') ->select(); $xlsData = []; if(is_array($data)){ $launchmodel = M('apply_launch','tab_'); foreach($data as $k => $v) { $v['apply_time'] = date('Y-m-d H:i',$v['apply_time']); $v['dispose_time'] = $v['dispose_time']>0?date('Y-m-d H:i:s',$v['dispose_time']):'--'; $v['status'] = get_info_status($v['status'],5); $v['promote_account'] = get_promote_name($v['promote_id']); $v['dispose_account'] = $v['dispose_id']>0?get_admin_nickname($v['dispose_id']):'--'; $v['app_name'] = $v['app_version']==1?$v['app_name'].'(安卓)':$v['app_name'].'(IOS)'; $v['enable_status'] = $v['enable_status']==1?'已打包':($v['enable_status']==2?'准备打包':($v['enable_status']==3?'打包中':($v['enable_status']==-1?'打包失败':'未打包'))); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 推广补链 * @author 鹿文学 */ public function mend_list() { $xlsName = $_REQUEST['xlsname']; $model = M('user','tab_'); // $xlsCell = array( // array('account','玩家账号'), // array('register_time','注册时间'), // array('login_time','最后登录时间'), // array('register_type','注册来源'), // array('register_ip','注册IP'), // array('login_time','上次登录'), // array('top_promote','所属推广员'), // ); $xlsCell = array( '玩家账号','注册时间','最后登录时间','注册来源','注册IP','上次登录','所属推广员', ); if(isset($_REQUEST['account'])){ if ($_REQUEST['account']=='全部') { unset($_REQUEST['account']); } $map['tab_user.account']=array('like','%'.$_REQUEST['account'].'%'); unset($_REQUEST['account']); } $map['register_type'] = array('in','(0,1,2,3,4,5,6,7)'); $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 //为数据权限添加 setPowerPromoteIds($map); $accessNum=$model ->join("left join tab_promote on tab_promote.id=tab_user.promote_id") ->field("tab_user.id,tab_user.account,tab_user.register_time,tab_user.login_time,tab_user.register_type ,tab_user.register_ip, tab_promote.parent_name as parent_name, tab_promote.account as promote_account") ->where($map) ->order('tab_user.id desc') ->count(); $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); $lastId = 0; for($i = 1; $i <= $pages; $i++) { // REPLACE(substring_index(tab_promote.chain, '/', 2),'/','') $xlsData=$model ->join("left join tab_promote on tab_promote.id=tab_user.promote_id") ->field("tab_user.id,tab_user.account,tab_user.register_time,tab_user.login_time,tab_user.register_type ,tab_user.register_ip,tab_user.login_time as last_login_time, tab_promote.parent_name as parent_name, tab_promote.account as promote_account,tab_user.id as top_promote") ->where($map) ->limit(($i-1)*$perSize ,$perSize) ->order('tab_user.id desc') ->select(); foreach($xlsData as $key => $value) { unset($value['id']); $value['register_time'] = date('Y-m-d H:i:s',$value['register_time']); $value['login_time'] = $value['login_time']>0?date('Y-m-d H:i:s',$value['login_time']):'暂无登录'; $value['last_login_time'] = $value['last_login_time']>0?date('Y-m-d H:i:s',$value['last_login_time']):'暂无登录'; $value['register_type'] = get_registertype($value['register_type']); $value['top_promote'] = $value['parent_name']?$value['promote_account'].'['.$value['parent_name'].']':$value['promote_account']; if (!$value['promote_account']) { $value['top_promote'] = "官方渠道"; } if($value['parent_name'] == "官方渠道") { $value['top_promote'] = $value['promote_account']; } unset($value['promote_account']); unset($value['parent_name']); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); // $data = M()->table("({$data}) as a") // ->field("a.account,a.register_time,a.login_time,a.register_type,a.register_ip,a.top_promote,a.promote_account") // ->join("left join tab_promote on a.top_promote=tab_promote.id") // ->order("a.id desc") // ->select(false); // var_dump($data);die(); // $xlsData = []; // if(is_array($data)){ // // foreach($data as $k => $v) { // // $v['register_time'] = date('Y-m-d H:i:s',$v['register_time']); // $v['login_time'] = $v['login_time']>0?date('Y-m-d H:i:s',$v['login_time']):'暂无登录'; // // $v['register_type'] = get_registertype($v['register_type']); // // $promote = get_parent_promoteto($v['promote_id']); // // $v['top_promote'] = $promote?($v['promote_account'] . get_parent_promoteto($v['promote_id'])):get_promote_name($v['promote_id']); // // $xlsData[] = $v; // // } // // // } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 补链记录 * @author 鹿文学 */ public function mend_record_list() { $xlsName = $_REQUEST['xlsname']; $model = M('Mend','tab_'); $xlsCell = array( array('user_account','玩家账号'), array('promote_account','补链前渠道'), array('promote_account_to','补链后渠道'), array('remark','备注'), array('create_time','补链时间'), array('op_account','操作人员'), ); if(isset($_REQUEST['account'])){ if ($_REQUEST['account']=='全部') { unset($_REQUEST['account']); } $map['user_account']=array('like','%'.$_REQUEST['account'].'%'); } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['promote_account'] = get_promote_name($v['promote_id']); $v['promote_account_to'] = get_promote_name($v['promote_id_to']); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 平台币转移记录 * @author 鹿文学 */ public function promote_coin_transfer_record_list() { $xlsName = $_REQUEST['xlsname']; $model = M('PromoteCoin','tab_'); $xlsCell = array( array('promote_account','一级推广员'), array('sub_promote_account','二级推广员'), array('num','转移数量'), array('create_time','转移时间'), ); $map['type'] = 2; $map['source_id'] = ['neq',0]; if(isset($_REQUEST['source_id'])) {$map['source_id'] = $_REQUEST['source_id'];} if(isset($_REQUEST['promote_id'])) {$map['promote_id'] = $_REQUEST['promote_id'];} $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; //为数据权限添加 setPowerPromoteIds($map); $data = $model->where($map) ->order('id desc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['create_time'] = date('Y-m-d H:i',$v['create_time']); $v['promote_account'] = get_promote_name($v['promote_id']); $v['sub_promote_account'] = get_promote_name($v['source_id']); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 角色权限 * @author 鹿文学 */ public function auth_manager() { $xlsName = $_REQUEST['xlsname']; $model = M('AuthGroup'); $xlsCell = array( array('title','用户组'), array('description','详情'), array('status','状态'), ); $map['module'] = 'admin'; $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id asc') ->select(); $xlsData = []; if(is_array($data)){ foreach($data as $k => $v) { $v['description'] = $v['description']?mb_strimwidth($v['description'],0,60,"...","utf-8"):'空'; $v['status']= get_status_title($v['status']); $xlsData[] = $v; } } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 行为日志 * @author 鹿文学 */ public function actionlog() { $xlsName = $_REQUEST['xlsname']; $model = M('ActionLog'); $xlsCell = array( array('id','编号'), array('remark','行为'), array('nickname','管理员账号'), array('create_time','行为时间'), array('action_ip','行为IP'), ); $map['status'] = array('gt', -1); $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('id desc') ->select(); int_to_string($data); $xlsData = []; foreach ($data as $k=>$v){ $model_id = get_document_field($v['model'],"name","id"); $v['model_id'] = $model_id ? $model_id : 0; $v['nickname'] = get_nickname($v['user_id']); $v['create_time'] = time_format($v['create_time']); $v['action_ip'] = long2ip($v['action_ip']); $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** * 站内通知 * @author 鹿文学 */ public function msg_lists() { $xlsName = $_REQUEST['xlsname']; $model = M('Msg','tab_'); $xlsCell = array( array('id','ID'), array('content','通知内容'), array('create_time','通知时间'), array('status','状态'), ); $map['user_id'] = session('user_auth.uid'); $map['status'] = array('neq','-1'); if(isset($_REQUEST['status'])){ if($_REQUEST['status']=='未读'){ $map['status']=2; }elseif($_REQUEST['status']=='已读'){ $map['status']=1; } } $page = intval($_REQUEST['p']); $page = $page?$page:1; $row = $_REQUEST['row']?$_REQUEST['row']:10; $data=$model ->where($map) ->order('status desc,id') ->select(); int_to_string($data); $xlsData = []; foreach ($data as $k=>$v){ $v['status'] = get_info_status($v['status'],13); $v['create_time'] = set_show_time($v['create_time']); $xlsData[] = $v; } $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function spend_list() { $xlsName = $_REQUEST['xlsname']; // $xlsCell = array( // array('pay_order_number', "订单号"), // array('pay_time', "充值时间"), // array('promote_account', L('Subordinate_channel')), // array('parent_id', "上级推广员"), // array('user_account', "玩家账号"), // array('game_name', "游戏名称"), // array('server_name', L('Game_area_clothing')), // array('game_player_name', "角色名"), // array('spend_ip', "充值ip"), // array('pay_amount', "应付金额"), // array('cost', "实付金额"), // array('pay_way', "充值方式"), // array('promote_id', '商务专员'), // array('is_check','对账状态') // ); $xlsCell = array( "订单号", "充值时间", L('Subordinate_channel'), "上线推广员", "玩家账号", "游戏名称", L('Game_area_clothing'), "角色名", "充值ip", "应付金额", "实付金额", "充值方式", '商务专员', '对账状态' ); if (isset($_REQUEST['game_name'])) { if ($_REQUEST['game_name'] == '全部') { unset($_REQUEST['game_name']); } else { $map['game_name'] = $_REQUEST['game_name']; unset($_REQUEST['game_name']); } } if (!empty($_REQUEST['server_id'])) { $map['server_name'] = $_REQUEST['server_id']; unset($_REQUEST['server_id']); } if (!empty($_REQUEST['pay_order_number'])) { $map['pay_order_number'] = array('like', '%' . $_REQUEST['pay_order_number'] . '%'); unset($_REQUEST['pay_order_number']); } if (isset($_REQUEST['pay_way'])) { $map['pay_way'] = get_pay_way_map($_REQUEST['pay_way']); unset($_REQUEST['pay_way']); } if (isset($_REQUEST['user_account'])) { $map['user_account'] = array('like', '%' . $_REQUEST['user_account'] . '%'); unset($_REQUEST['user_account']); } if (isset($_REQUEST['spend_ip'])) { $map['spend_ip'] = array('like', '%' . $_REQUEST['spend_ip'] . '%'); unset($_REQUEST['spend_ip']); } if (isset($_REQUEST['time-start']) && isset($_REQUEST['time-end'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['time-start']), strtotime($_REQUEST['time-end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['time-start']); unset($_REQUEST['time_end']); } elseif (isset($_REQUEST['time-start'])) { $map['pay_time'] = ['GT', strtotime(I('time-start'))]; unset($_REQUEST['time-start']); } elseif (isset($_REQUEST['time-end'])) { $map['pay_time'] = ['LT', strtotime(I('time-end')) + 86399]; unset($_REQUEST['time-end']); } if (isset($_REQUEST['start']) && isset($_REQUEST['end'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['start']), strtotime($_REQUEST['end']) + 24 * 60 * 60 - 1)); unset($_REQUEST['start']); unset($_REQUEST['end']); } elseif (isset($_REQUEST['start'])) { $map['pay_time'] = ['GT', strtotime(I('start'))]; unset($_REQUEST['start']); } elseif (isset($_REQUEST['end'])) { $map['pay_time'] = ['LT', strtotime(I('end')) + 86399]; unset($_REQUEST['end']); } if (isset($_REQUEST['timeStart']) && isset($_REQUEST['timeEnd'])) { $map['pay_time'] = array('BETWEEN', array(strtotime($_REQUEST['timeStart']), strtotime($_REQUEST['timeEnd']) + 24 * 60 * 60 - 1)); unset($_REQUEST['timeStart']); unset($_REQUEST['timeEnd']); } elseif (isset($_REQUEST['timeStart'])) { $map['pay_time'] = ['GT', strtotime(I('timeStart'))]; unset($_REQUEST['timeStart']); } elseif (isset($_REQUEST['timeEnd'])) { $map['pay_time'] = ['LT', strtotime(I('timeEnd')) + 86399]; unset($_REQUEST['timeEnd']); } if (isset($_REQUEST['promote_name'])) { if ($_REQUEST['promote_name'] == '全部') { unset($_REQUEST['promote_name']); } else if ($_REQUEST['promote_name'] == '自然注册') { $map['promote_id'] = array("lte", 0); unset($_REQUEST['promote_name']); } else { $map['promote_id'] = get_promote_id($_REQUEST['promote_name']); unset($_REQUEST['promote_name']); if (!empty(I('parent_id')) && $map['promote_id']) { if (I('parent_id') == $map['promote_id']) { } else { $parent_id = I('parent_id'); $pro = M('promote', 'tab_')->field('id')->where("id={$map['promote_id']} and chain like '%/{$parent_id}/%'")->select(); if (!$pro) { $map['promote_id'] = array('eq', 999999999); } } } else { $pro = M('promote', 'tab_')->field('id')->where("chain like '%/{$map['promote_id']}/%'")->select(); $pro_ids = array_column($pro, 'id'); $pro_ids[] = $map['promote_id']; if (!empty($pro_ids)) { $map['promote_id'] = ['in', $pro_ids]; } else { $map['promote_id'] = array('eq', 999999999); } } } } else { if (!empty(I('parent_id'))) { $parent_id = I('parent_id'); $pro = M('promote', 'tab_')->field('id')->where("chain like '%/{$parent_id}/%'")->select(); $pro_ids = array_column($pro, 'id'); $pro_ids[] = I('parent_id'); if (!empty($pro_ids)) { $map['promote_id'] = ['in', $pro_ids]; } else { $map['promote_id'] = array('eq', 999999999); } } else { $map['promote_id'] = array("gt", 0); } } if (isset($_REQUEST['ba_id'])) { $all_promote_id = array_column(get_admin_promotes($_REQUEST['ba_id'], 'ba_id'), 'id'); if (empty($all_promote_id)) { $all_promote_id[] = -1; } $map['promote_id'] = array($map['promote_id'], array('in', implode(',', $all_promote_id)), 'and'); } // var_dump(1);die(); $map['tab_spend.pay_status'] = 1; $map['tab_spend.promote_id'] = $map['promote_id']; unset($map['promote_id']); //为数据权限添加 setPowerPromoteIds($map, 'tab_spend.promote_id'); $csvFileName = $xlsName . '.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="' . $csvFileName . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum =D('Spend') // 查询条件 ->where($map) /* 默认通过id逆序排列 */ ->order('tab_spend.id desc') /* 执行查询 */ ->count(); $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); $lastId = 0; for($i = 1; $i <= $pages; $i++) { $xlsData = D('Spend') ->field("tab_spend.pay_order_number,tab_spend.pay_time,promote_account,parent_id,user_account,game_name,server_name,game_player_name, spend_ip,pay_amount,cost,pay_way,tab_spend.promote_id,is_check,ba_id, REPLACE(substring_index(tab_promote.chain, '/', 2),'/','') as top_promote,tab_business_affairs.account") ->join("left join tab_promote on tab_spend.promote_id = tab_promote.id") ->join("left join tab_business_affairs on tab_promote.ba_id = tab_business_affairs.id") // 查询条件 ->where($map) ->limit(($i-1)*$perSize ,$perSize) /* 默认通过id逆序排列 */ ->order('tab_spend.id desc') /* 执行查询 */ ->select(false); // $xlsCell = array( // array('pay_order_number', "订单号"), // array('pay_time', "充值时间"), // array('promote_account', L('Subordinate_channel')), // array('parent_id', "上级推广员"), // array('user_account', "玩家账号"), // array('game_name', "游戏名称"), // array('server_name', L('Game_area_clothing')), // array('game_player_name', "角色名"), // array('spend_ip', "充值ip"), // array('pay_amount', "应付金额"), // array('cost', "实付金额"), // array('pay_way', "充值方式"), // array('promote_id', '商务专员'), // array('is_check','对账状态') // ); $xlsData = M()->table("({$xlsData}) as a") ->field("a.pay_order_number,a.pay_time,a.promote_account,tab_promote.account as parent_id, a.user_account,a.game_name,a.server_name,a.game_player_name,a.spend_ip,a.pay_amount,a.cost, a.pay_way,a.account,a.is_check") ->join("left join tab_promote on a.top_promote=tab_promote.id") ->select(); foreach ($xlsData as $key => &$value) { if (!$value['account']) { $value['account'] = "暂无"; } // $xlsData[$key]['parent_id'] = get_top_promote($value['promote_id'], $value['parent_id']); $xlsData[$key]['pay_way'] = get_pay_way($value['pay_way']); // $xlsData[$key]['promote_id'] = get_promote_business_account($value['promote_id']); $xlsData[$key]['is_check'] = get_info_status($value['is_check'], 37); $xlsData[$key]['pay_time'] = date('Y-m-d H:i:s', $value['pay_time']); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); // $this->exportExcel($xlsName, $xlsCell, $xlsData); } function exportFinanceIndex() { $xlsName = '月结统计导出'; $xlsCell = array( array('count_date','月份'), array('cash_count','游戏现金流水'), array('balance_coin_deposit','平台币收入'), array('inside_cash_count','内冲流水'), array('bind_coin_count','内充支出'), array('balance_coin_count','平台币支出'), array('all_count','总流水'), ); $map = []; if(!empty(I('count_date'))){ $map['count_date']=I('count_date'); } // if (!empty(I('game_id'))) { // $map['game_id']=I('game_id'); // } // if (!empty(I('collaborate_id'))) { // $map['collaborate_id']=I('collaborate_id'); // } // // if (empty(I('game_id'))) { // $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count, // sum(inside_cash_count) as inside_cash_count,sum(cash_count+balance_coin_count+inside_cash_count) as all_cash_count"; // $allField = "cash_count+balance_coin_count+inside_cash_count"; // $InsideField = "inside_cash_count"; // } else { // $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count, // sum(bind_coin_count) as inside_cash_count,sum(cash_count+balance_coin_count+bind_coin_count) as all_cash_count"; // $allField = "cash_count+balance_coin_count+bind_coin_count"; // $InsideField = "bind_coin_count"; // } // $group = "count_date"; // $order = "id DESC"; // $xlsData = D("spend_count")->getSpendCountData($map,$field,$group,$order); // // $sumCash = D("spend_count")->sumSpendCountField($map,"cash_count"); // $sumBalance = D("spend_count")->sumSpendCountField($map,"balance_coin_count"); // $sumInside = D("spend_count")->sumSpendCountField($map,$InsideField); // $sumAll = D("spend_count")->sumSpendCountField($map,$allField); $order = "id DESC"; $xlsData = M('spend_month_count','tab_') ->field("cash_count,balance_coin_count,inside_cash_count,all_count,count_date,balance_coin_deposit,bind_coin_count") ->where($map) ->order($order) ->select(); $sumData = M('spend_month_count','tab_') ->field("sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,sum(inside_cash_count) as inside_cash_count,sum(all_count) as all_count,count_date,sum(balance_coin_deposit) as balance_coin_deposit,sum(bind_coin_count) as bind_coin_count") ->where($map) ->order($order) ->find(); $sumData = [['count_date'=>'总计', 'cash_count'=>$sumData['cash_count'], 'balance_coin_deposit'=>$sumData['balance_coin_deposit'], 'inside_cash_count'=>$sumData['inside_cash_count'], 'bind_coin_count'=>$sumData['bind_coin_count'], 'balance_coin_count'=>$sumData['balance_coin_count'], 'all_count'=>$sumData['all_count']]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } function exportGameFinance() { $month = I("count_date"); $xlsName = $month.'月结统计导出'; $xlsCell = array( array('game_name','游戏'), array('partner_name','合作方'), array('cash_count','游戏现金流水'), array('balance_coin_count','平台币支出'), array('inside_cash_count','公会内充支出'), array('all_cash_count','总流水'), ); $map = []; if(!empty(I('count_date'))){ $map['count_date']=I('count_date'); } if(!empty(I('root_id'))||I('root_id')=='0') { $root_id = I('root_id'); if ($root_id == '0') { $map['_string'] = "promote_id = {$root_id}"; } else if($root_id){ $map['_string'] = "promote_id = {$root_id} or chain like '%/{$root_id}/%'"; } } if (!empty(I('root_name'))) { $map['promote_account'] = array('like','%'.I("root_name").'%'); } $game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id'); if ($game_ids) { $map['game_id'] = ['in', $game_ids]; } if (!empty(I('partner_id'))) { $map['partner_id']=I('partner_id'); } if (I('sign') == 2&&empty(I('root_id'))) { $map['_string'] = "parent_id >0 or root_id>0"; } if (I('sign') == 3&&empty(I('root_id'))) { $map['_string'] = "parent_id >0 and root_id>0"; } // var_dump($map);die(); if(!empty(I('parent_id'))) { $parent_id = I('parent_id'); $map['_string'] = "promote_id = {$parent_id} or chain like '%/{$parent_id}/%'"; } if (!empty(I('promote_id'))) { $promote_id = I('promote_id'); $map['_string'] = "promote_id = {$promote_id}"; } $map['inside_cash_count'] = ['neq',0]; $insideData = D("spend_count")->getSpendCountData($map,"game_id,inside_cash_count as count","promote_id,count_date"); unset($map['inside_cash_count']); //内充流水与绑定流水数据 $insideDataSum = []; foreach ($insideData as $key => $value) { if (isset($insideDataSum[$value['game_id']])) { $insideDataSum[$value['game_id']] = $insideDataSum[$value['game_id']] + $value['count']; } else { $insideDataSum[$value['game_id']] = $value['count']; } } $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count, sum(inside_cash_count) as inside_cash_count,sum(cash_count+balance_coin_count) as all_cash_count,game_id,game_name,partner_name"; $group = "game_id"; $order = "id DESC"; $xlsData = D("spend_count")->getSpendCountData($map,$field,$group,$order); foreach ($xlsData as $key => $value) { $xlsData[$key]['inside_cash_count'] = number_format($insideDataSum[$value['game_id']],2,'.',''); $xlsData[$key]['all_cash_count'] = number_format($insideDataSum[$value['game_id']]+$xlsData[$key]['all_cash_count'],2,'.',''); } $sumCash = D("spend_count")->sumSpendCountField($map,"cash_count"); $sumBalance = D("spend_count")->sumSpendCountField($map,"balance_coin_count"); $sumInside = number_format(array_sum($insideDataSum),2,'.',''); $sumAll = D("spend_count")->sumSpendCountField($map,"cash_count+balance_coin_count") + array_sum($insideDataSum); $sumData = [['game_name'=>'总计', 'cash_count'=>$sumCash, 'balance_coin_count'=>$sumBalance, 'inside_cash_count'=>$sumInside, 'all_cash_count'=>$sumAll]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } /** *充值-》财务管理-》游戏统计-》导出 */ public function exportGameStatistics() { $month = I("count_date"); $xlsName = $month . '游戏统计导出'; $xlsCell = array( array('game_name','游戏'), array('game_type_name','游戏类型'), array('partner_name','合作公司'), array('cash_count','游戏现金金额'), array('balance_coin_count','平台币直充支出'), array('inside_cash_count','内充支出'), array('all_cash_count','游戏内充值合计'), ); $map = []; $game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id'); if ($game_ids) { $map['s.game_id'] = ['in', $game_ids]; } if (!empty(I('partner_id'))) { $map['g.partner_id'] = I('partner_id'); } if (!empty(I('timestart'))) { $timestart = strtotime(I('timestart')); $map['_string'] = "s.pay_time >= {$timestart}"; } if (!empty(I('timeend'))) { $timeend = strtotime(I('timeend') . ' 23:59:59'); if (!empty($map['_string'])) { $map['_string'] .= " and "; } $map['_string'] .= " s.pay_time < {$timeend}"; } if (!empty(I('game_type_id'))) { $map['g.game_type_id'] = I('game_type_id'); } $xlsData = D("spend")->gameStatistics($map); foreach ($xlsData as $key => $value) { $xlsData[$key]['all_cash_count'] = $value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count']; } $totalData = D("spend")->totalGameStatistics($map); $sumCash = $totalData['cash_count']; $sumBalance = $totalData['balance_coin_count']; $sumInside = $totalData['inside_cash_count']; $sumAll = $sumCash + $sumBalance + $sumInside; $sumData = [['game_name'=>'总计', 'cash_count'=>$sumCash, 'balance_coin_count'=>$sumBalance, 'inside_cash_count'=>$sumInside, 'all_cash_count'=>$sumAll]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function gameStatisticsDetail() { $game_name = I("game_name"); $xlsName = $game_name . '游戏订单查看'; $xlsCell = array( array('pay_order_number','支付订单号'), array('extend','游戏订单号'), array('pay_time','充值时间'), array('user_account','玩家账号'), array('game_name','游戏名称'), array('promote_account','所属推广员'), array('spend_ip','充值ip'), array('server_name','游戏区服'), array('game_player_name','角色名称'), array('cost','订单金额'), array('pay_amount','实付金额'), array('pay_way','充值方式'), ); if (isset($_REQUEST['pay_way'])) { $map['pay_way'] = $_REQUEST['pay_way']; } if (!empty($_REQUEST['pay_order_number'])) { $map['pay_order_number'] = $_REQUEST['pay_order_number']; } if (!empty(I('partner_id'))&&empty(I("game_id"))) { $wherePartner = I('partner_id'); $gameId = M("game","tab_")->field("id")->where("partner_id={$wherePartner}")->select(); $gameId = implode(',',array_column($gameId,'id')); $map['game_id'] = ['in',$gameId]; } if (!empty(I('timestart'))) { $timestart = strtotime(I('timestart')); $map['_string'] = "pay_time >= {$timestart}"; } if (!empty(I('timeend'))) { $timeend = strtotime(I('timeend') . ' 23:59:59'); if (!empty($map['_string'])) { $map['_string'] .= " and "; } $map['_string'] .= " pay_time < {$timeend}"; } $map['pay_game_status'] = 1; if (!empty(I("game_id"))) { $map['game_id'] = I("game_id"); } if (!empty(I('user_account'))) { $map['user_account'] = array('like','%'.I("user_account").'%'); } if (!empty(I('user_nickname'))) { $map['game_player_name'] = array('like',I("user_nickname").'%'); } $field = "pay_order_number,FROM_UNIXTIME(pay_time) as pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,pay_amount,cost,pay_way,extend"; $group = ""; $order = "pay_time DESC"; $xlsData = D('spend')->getSpendData($map,$field,$group,$order); // dd(D("spend")->_sql()); foreach($xlsData as $key => $value) { $xlsData[$key]['pay_way'] = getPayType($value['pay_way']); } $totalData = D("spend")->totalGameStatistics($map, false); $sumCash = $totalData['cash_count'] ?? 0; $sumBalance = $totalData['balance_coin_count'] ?? 0; $sumInside = $totalData['inside_cash_count'] ?? 0; $sumAll = $sumCash + $sumBalance + $sumInside; $sumData = [['pay_order_number'=>'总计:' . $sumAll, 'extend'=>'现金金额:' . $sumCash, 'pay_time'=>'平台币:' . $sumBalance, 'user_account'=>'绑币:' . $sumInside]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function coinDetail() { $xlsCell = array( array('pay_order_number','支付订单号'), array('pay_time','充值时间'), array('user_account','玩家账号'), array('game_name','游戏名称'), array('server_name','游戏区服'), array('game_player_name','角色名称'), array('cost','订单金额'), array('pay_amount','实付金额'), array('pay_way','充值方式'), ); $map = array(); if (isset($_REQUEST['pay_way'])) { $map['pay_way'] = $_REQUEST['pay_way']; } $game_name = I("game_name"); if (!empty($_REQUEST['pay_order_number'])) { $map['pay_order_number'] = $_REQUEST['pay_order_number']; } if (!empty(I('partner_id'))&&empty(I("game_id"))) { $wherePartner = I('partner_id'); $gameId = M("game","tab_")->field("id")->where("partner_id={$wherePartner}")->select(); $gameId = implode(',',array_column($gameId,'id')); $map['tab_spend.game_id'] = ['in',$gameId]; } if (!empty(I('timestart'))) { $timestart = strtotime(I('timestart')); $map['_string'] = "pay_time > {$timestart}"; } if (!empty(I('timeend'))) { $timeend = strtotime(I('timeend')); $map['_string'] .= " and pay_time < {$timeend}"; } if (!empty(I("promote_id"))) { $promote_id[] = I("promote_id"); } if (!empty(I("root_id"))) { $root_id = I("root_id"); $promote_id = $this->getPromoteList($root_id); array_push($promote_id, $root_id); } if ($_REQUEST['root_id']=='0') { $map['tab_spend.promote_id'] = $_REQUEST['root_id']; } $promote_id = implode(',',$promote_id); if ($promote_id) { $map['tab_spend.promote_id'] = ['in',$promote_id]; } $map['pay_status'] = 1; if (!empty(I("game_id"))) { $map['tab_spend.game_id'] = I("game_id"); } if (!empty(I('user_account'))) { $map['tab_spend.user_account'] = array('like','%'.I("user_account").'%'); } if (!empty(I('user_nickname'))) { $map['tab_spend.game_player_name'] = array('like',I("user_nickname").'%'); } $field = "pay_order_number,FROM_UNIXTIME(pay_time) as pay_time,tab_spend.user_account, tab_spend.user_nickname,tab_spend.game_name,tab_spend.promote_account,spend_ip,tab_spend.server_name, game_player_name,pay_amount,cost,pay_way"; $group = ""; $order = "pay_time DESC"; $join = false; if ($map['pay_way'] ==-1) {//绑定币 $xlsCell[] = array('bind_balance','绑定币余额'); $xlsName = $game_name . '内充支出明细'; $field2 = $field . ',bind_balance'; $join = 'left join tab_user_play as p on p.user_id = tab_spend.user_id and tab_spend.game_id=p.game_id'; } elseif ($map['pay_way'] ==0) {//平台币 $xlsCell[] = array('balance','平台币余额'); $xlsName = $game_name . '平台币直充明细'; $field2 = $field . ',balance'; $join = 'left join tab_user as u on u.id = tab_spend.user_id'; } $xlsData = D('spend')->getSpendData($map, $field2, $group, $order, 0, 0, $join); foreach($xlsData as $key => $value) { $xlsData[$key]['pay_way'] = getPayType($value['pay_way']); } $map['pay_game_status'] = 1; $total_cost = D('spend')->sumSpend($map, 'cost'); $total_pay_amount = D('spend')->sumSpend($map, 'pay_amount'); $sumData = [['pay_order_number'=>'总计', 'cost'=> $total_cost, 'pay_amount'=> $total_pay_amount]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } function gameFinanceDetail() { // set_time_limit(0); // ini_set('memory_limit', '512M'); $month = I("game_name"); $xlsName = $month.'充值流水'; $xlsCell = array( array('pay_order_number','支付订单号'), array('extend','游戏订单号'), array('pay_time','充值时间'), array('user_account','玩家账号'), array('game_name','游戏名称'), array('promote_account','所属推广员'), array('spend_ip','充值ip'), array('server_name','游戏区服'), array('game_player_name','角色名称'), array('cost','订单金额'), array('pay_amount','实付金额'), array('pay_way','充值方式'), ); if (!empty(I("promote_id"))) { $promote_id[] = I("promote_id"); } if (!empty(I("root_id"))) { $root_id = I("root_id"); $promote_id = $this->getPromoteList($root_id); array_push($promote_id,$root_id); } if ($_REQUEST['root_id']=='0') { $map['promote_id'] = $_REQUEST['root_id']; } if (!empty(I("parent_id"))) { $parent_id = I("parent_id"); $promote_id = $this->getPromoteList($parent_id); array_push($promote_id,$parent_id); } $promote_id = implode(',',$promote_id); if ($promote_id) { $map['promote_id'] = ['in',$promote_id]; } if (!empty(I('partner_id'))&&empty(I("game_id"))) { $wherePartner = I('partner_id'); $gameId = M("game","tab_")->field("id")->where("partner_id={$wherePartner}")->select(); $gameId = implode(',',array_column($gameId,'id')); $map['game_id'] = ['in',$gameId]; } if (!empty(I("count_date"))) { $month = I("count_date"); $tarry = explode('-',$month); $startTime=mktime(0,0,0,$tarry[1],1,$tarry[0]); $endTime =mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1; $map['pay_time'] = array('between',array($startTime,$endTime)); } $map['pay_status'] = 1; if (!empty(I("game_id"))) { $map['game_id'] = I("game_id"); } if (!empty(I('user_account'))) { $map['user_account'] = array('like','%'.I("user_account").'%'); } if (!empty(I('user_nickname'))) { $map['user_nickname'] = array('like',I("user_nickname").'%'); } $field = "pay_order_number,FROM_UNIXTIME(pay_time) as pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,pay_amount,cost,pay_way,extend"; $group = ""; $order = "pay_time DESC"; for($start = $startTime;$start<$endTime;$start=$start+86400) { $map['pay_time'] = array('between',array($start,$start+86400)); $xlsData1 = D('spend')->getSpendData($map,$field,$group,$order); if ($xlsData1) { $xlsData[date('m-d',$start)] = $xlsData1; } } foreach($xlsData as $key => $value) { foreach ($value as $k => $v) { $xlsData[$key][$k]['pay_way'] = getPayType($v['pay_way']); $xlsData[$key][$k]['extend'] = "'".$v['extend']; } } // dump($xlsData);die(); $map['pay_time'] = array('between',array($startTime,$endTime)); $sum = D('spend')->sumSpend($map,'pay_amount'); $xlsData['10-'] = [['pay_order_number'=>'总计', 'pay_way'=>$sum]]; // $xlsData = array_merge($xlsData,$sumData); // dump($xlsData);die(); $this->exportNewExcel($xlsName, $xlsCell, $xlsData); } public function exportNewExcel($expTitle, $expCellName, $expTableData) { $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称 // $fileName = session('user_auth.username').date('_YmdHis');//or $xlsTitle 文件名称可根据自己情况设定 $fileName = $expTitle; $cellNum = count($expCellName); $dataNum = count(current($expTableData)); Vendor("PHPExcel.PHPExcel"); $objPHPExcel = new \PHPExcel(); $cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'); $objPHPExcel->getActiveSheet(0)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格 $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', $expTitle); $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->setTitle(key($expTableData)); for ($i = 0; $i < $cellNum; $i++) { $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]); } for ($i = 0; $i < $dataNum; $i++) { for ($j = 0; $j < $cellNum; $j++) { $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j] . ($i + 3), current($expTableData)[$i][$expCellName[$j][0]]); } } // var_dump($expTableData);die(); unset($expTableData[key($expTableData)]); $sheetNum = 1; foreach($expTableData as $key => $value) { $dataNum = count($value); $objPHPExcel->createSheet(); if ($key==0) { break; } if ($key == '10-') { $objPHPExcel->setActiveSheetIndex($sheetNum)->setTitle('总计'); } else { $objPHPExcel->setActiveSheetIndex($sheetNum)->setTitle($key); } $objPHPExcel->getActiveSheet($sheetNum)->mergeCells('A1:' . $cellName[$cellNum - 1] . '1');//合并单元格 $objPHPExcel->setActiveSheetIndex($sheetNum)->setCellValue('A1', $expTitle); $objPHPExcel->setActiveSheetIndex($sheetNum)->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); for ($i = 0; $i < $cellNum; $i++) { $objPHPExcel->setActiveSheetIndex($sheetNum)->setCellValue($cellName[$i] . '2', $expCellName[$i][1]); } for ($i = 0; $i < $dataNum; $i++) { for ($j = 0; $j < $cellNum; $j++) { $objPHPExcel->getActiveSheet($sheetNum)->setCellValue($cellName[$j] . ($i + 3), $value[$i][$expCellName[$j][0]]); } } $sheetNum++; } //die(); ob_end_clean();//清除缓冲区,避免乱码 header('pragma:public'); header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"'); header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit; } function getPromoteList($root_id = 0) { $data = M('promote','tab_') ->field("id") ->where("chain like '%/{$root_id}/%'") ->select(); $handleData = []; foreach ($data as $key => $value) { array_push($handleData,$data[$key]['id']); } return $handleData; } function exportGetRootUser() { //获取所有数据 if (!empty(I("count_date"))) { $map['count_date'] = I("count_date"); } $xlsName = '会长月结统计'; $xlsCell = array( array('promote_account','会长渠道'), array('cash_count','游戏现金流水'), array('balance_coin_count','平台币支出'), array('inside_cash_count','公会内充发放'), array('bind_coin_count','公会内充支出'), array('all_count','总流水'), ); if (!empty(I("root_name"))) { $map['promote_account']=['like','%'.I("root_name").'%']; } // $map['chain'] = "/"; $map['level'] = ['elt',1]; $xlsData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->group('promote_id') ->select(); $sumData = M('spend_user_count','tab_') ->field('sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->find(); $sumData = [['promote_account'=>'总计', 'cash_count'=>$sumData['cash_count'], 'balance_coin_count'=>$sumData['balance_coin_count'], 'inside_cash_count'=>$sumData['inside_cash_count'], 'bind_coin_count'=>$sumData['bind_coin_count'], 'all_count'=>$sumData['all_count'], ]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } public function exportMiniterUser() { if (!empty(I("count_date")) ) { $month = I("count_date"); $map['count_date'] =$month; } $parentData = []; if (!empty(I("root_id"))) { $root_id = I("root_id"); $parentData = $this->getParentSpendData($root_id,$month,2); $map['chain'] =['like','%/'.$root_id.'/%']; $map['level'] = 2; } else if(!empty(I("sign"))){ $map['parent_id'] = ['neq',0]; $map['root_id'] = ['eq',0]; } else { if (I("root_id") == 0) { $root_id = I("root_id"); $map['promote_id'] = $root_id; } } if (!empty(I("root_name"))) { $rootname = I("root_name"); $map['promote_account'] =['like','%'.$rootname.'%']; } $xlsName = '组长月结统计'; $xlsCell = array( array('promote_account','会长渠道'), array('cash_count','游戏现金流水'), array('balance_coin_count','平台币支出'), array('inside_cash_count','公会内充发放'), array('bind_coin_count','公会内充支出'), array('all_count','总流水'), ); $xlsData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->group('promote_id') ->select(); if (empty(I("root_name"))) { $xlsData = array_merge($parentData,$xlsData); } $sumData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->find(); if (empty(I("root_name"))) { $sumData['cash_count'] = number_format($sumData['cash_count'] + $parentData[0]['cash_count'], 2, '.', ''); $sumData['balance_coin_count'] = number_format($sumData['balance_coin_count'] + $parentData[0]['balance_coin_count'], 2, '.', ''); $sumData['inside_cash_count'] = number_format($sumData['inside_cash_count'] + $parentData[0]['inside_cash_count'], 2, '.', ''); $sumData['all_count'] = number_format($sumData['all_count'] + $parentData[0]['all_count'], 2, '.', ''); $sumData['bind_coin_count'] = number_format($sumData['bind_coin_count'] + $parentData[0]['bind_coin_count'], 2, '.', ''); } $sumData = [['promote_account'=>'总计', 'cash_count'=>$sumData['cash_count'], 'balance_coin_count'=>$sumData['balance_coin_count'], 'inside_cash_count'=>$sumData['inside_cash_count'], 'bind_coin_count'=>$sumData['bind_coin_count'], 'all_count'=>$sumData['all_count'], ]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } function exportGetParentUser() { //获取所有数据 if (!empty(I("count_date")) ) { $month = I("count_date"); $map['count_date'] =$month; } $parentData = []; if (!empty(I("parent_id"))) { $root_id = I("parent_id"); $parentData = $this->getParentSpendData($root_id,$month,3); $map['chain'] =['like','%/'.$root_id.'/%']; $map['level'] = 3; } else if(!empty(I("sign"))){ $map['parent_id'] = ['neq',0]; $map['root_id'] = ['eq',0]; } else { if (I("root_id") == 0) { $root_id = I("root_id"); $map['promote_id'] = $root_id; } } if (!empty(I("root_name"))) { $map['promote_account']=['like','%'.I("root_name").'%']; } $xlsName = '组长月结统计'; $xlsCell = array( array('promote_account','会长渠道'), array('cash_count','游戏现金流水'), array('balance_coin_count','平台币支出'), array('inside_cash_count','公会内充发放'), array('bind_coin_count','公会内充支出'), array('all_count','总流水'), ); //获取数据 // $map['parent_id'] =$root_id; $xlsData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->group('promote_id') ->select(); if (empty(I("root_name"))) { $xlsData = array_merge($parentData, $xlsData); } $sumData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->find(); if (empty(I("root_name"))) { $sumData['cash_count'] = number_format($sumData['cash_count'] + $parentData[0]['cash_count'], 2, '.', ''); $sumData['balance_coin_count'] = number_format($sumData['balance_coin_count'] + $parentData[0]['balance_coin_count'], 2, '.', ''); $sumData['inside_cash_count'] = number_format($sumData['inside_cash_count'] + $parentData[0]['inside_cash_count'], 2, '.', ''); $sumData['all_count'] = number_format($sumData['all_count'] + $parentData[0]['all_count'], 2, '.', ''); $sumData['bind_coin_count'] = number_format($sumData['bind_coin_count'] + $parentData[0]['bind_coin_count'], 2, '.', ''); } $sumData = [['promote_account'=>'总计', 'cash_count'=>$sumData['cash_count'], 'balance_coin_count'=>$sumData['balance_coin_count'], 'inside_cash_count'=>$sumData['inside_cash_count'], 'bind_coin_count'=>$sumData['bind_coin_count'], 'all_count'=>$sumData['all_count'], ]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } function exportGetPromoteUser() { //获取所有数据 if (!empty(I("count_date")) && !empty(I("parent_id"))) { $month = I("count_date"); $map['count_date'] =$month; } $parentData = []; if (!empty(I("parent_id"))) { $parent_id = I("parent_id"); $parentData = $this->getParentSpendData($parent_id,$month,4); $map['chain'] =['like','%/'.$parent_id.'/%']; $map['level'] = 4; } if (!empty(I('sign'))) { $map['parent_id'] = ['neq',0]; if (!empty(I('root_id'))) { $map['root_id'] = I('root_id'); } else { $map['root_id'] = ['neq',0]; } } $xlsName = '推广员月结统计'; $xlsCell = array( array('promote_account','会长渠道'), array('cash_count','游戏现金流水'), array('balance_coin_count','平台币支出'), array('inside_cash_count','公会内充发放'), array('bind_coin_count','公会内充支出'), array('all_count','总流水'), ); //获取数据 $xlsData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->group('promote_id') ->select(); $xlsData = array_merge($parentData,$xlsData); $sumData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map) ->find(); $sumData['cash_count'] = number_format($sumData['cash_count']+$parentData[0]['cash_count'],2,'.',''); $sumData['balance_coin_count'] = number_format($sumData['balance_coin_count']+$parentData[0]['balance_coin_count'],2,'.',''); $sumData['inside_cash_count'] = number_format($sumData['inside_cash_count']+$parentData[0]['inside_cash_count'],2,'.',''); $sumData['all_count'] = number_format($sumData['all_count']+$parentData[0]['all_count'],2,'.',''); $sumData['bind_coin_count'] = number_format($sumData['bind_coin_count']+$parentData[0]['bind_coin_count'],2,'.',''); $sumData = [['promote_account'=>'总计', 'cash_count'=>$sumData['cash_count'], 'balance_coin_count'=>$sumData['balance_coin_count'], 'inside_cash_count'=>$sumData['inside_cash_count'], 'bind_coin_count'=>$sumData['bind_coin_count'], 'all_count'=>$sumData['all_count'], ]]; $xlsData = array_merge($xlsData,$sumData); $this->exportExcel($xlsName, $xlsCell, $xlsData); } function getParentSpendData($root_id,$date,$level=2) { $data = []; if (!$root_id) { $this->error('数据错误'); } else { $map = []; if ($root_id) { $map['promote_id'] = $root_id; } if ($date) { $map['count_date'] = $date; } $data = M('spend_user_count','tab_') ->field('promote_id,promote_account, sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,sum(inside_cash_count) as inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map)->select(); // dump($data); $map1['chain'] = ['like','%/'.$data[0]['promote_id'].'/%']; $map1['count_date'] = $date; $map1['level'] = $level; $sunData = M('spend_user_count','tab_') ->field('promote_id,promote_account, sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,sum(inside_cash_count) as inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count') ->where($map1)->find(); // echo M('spend_user_count','tab_')->_sql(); // dump($sunData); //die(); $data[0]['cash_count'] = number_format($data[0]['cash_count']-$sunData['cash_count'],2,'.',''); $data[0]['balance_coin_count'] = number_format($data[0]['balance_coin_count']-$sunData['balance_coin_count'],2,'.',''); $data[0]['inside_cash_count'] = number_format($data[0]['inside_cash_count']-$sunData['inside_cash_count'],2,'.',''); $data[0]['all_count'] = number_format($data[0]['all_count']-$sunData['all_count'],2,'.',''); $data[0]['bind_coin_count'] = number_format($data[0]['bind_coin_count']-$sunData['bind_coin_count'],2,'.',''); // $map['inside_cash_count'] = ['neq',0]; // $insideData = D("spend_count")->getSpendCountData($map,"promote_id,inside_cash_count as count","promote_id,count_date"); // unset($map['bind_coin_count']); // //内充流水与绑定流水数据 // $insideDataSum = 0; // foreach ($insideData as $key => $value) { // if (isset($insideDataSum)) { // $insideDataSum = $insideDataSum + $value['count']; // } else { // $insideDataSum = $value['count']; // } // } } // if (!$data[0]['cash_count']&&!$data[0]['balance_coin_count']&&!$data[0]['inside_cash_count']&&!$data[0]['all_count']) { // $promoteData = M('promote','tab_')->field('account as promote_account')->where("id={$root_id}")->find(); // // $data[0]['promote_id'] = $root_id; // $data[0]['promote_account'] = $promoteData['promote_account']; // $data[0]['cash_count'] = number_format(0.00,2,'.',''); // $data[0]['balance_coin_count'] = number_format(0.00,2,'.',''); // $data[0]['inside_cash_count'] = number_format(0.00,2,'.',''); // $data[0]['all_count'] = number_format(0.00,2,'.',''); // } // $data[0]['inside_cash_count'] = number_format($insideDataSum,2,'.',''); // $data[0]['all_count'] = number_format($insideDataSum+$data[0]['all_count'],2,'.',''); // var_dump($data);die(); return $data; } /** * 推广补链 * @author 鹿文学 */ public function Support_list() { $xlsName = $_REQUEST['xlsname']; $model = M('user','tab_'); $xlsCell = array( '一级渠道','玩家账号','游戏名称','区服','角色名','申请额度','扶持类型','备注','申请时间','可用额度','实际发放额度','状态' ); if(I('promote_id')){ $map['promote_id']=I('promote_id'); } if(I('game_id')){ $map['game_id']=I('game_id'); } if(!empty(I('apply_type')) || I('apply_type')==='0'){ $map['apply_type']=I('apply_type'); } // if(!empty(I('apply_status')) || I('apply_status')==='0'){ $map['apply_status']=I('apply_status'); } $csvFileName = $xlsName.'.csv'; //设置好告诉浏览器要下载excel文件的headers header('Content-Description: File Transfer'); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="'. $csvFileName .'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $fp = fopen('php://output', 'a');//打开output流 mb_convert_variables('GBK', 'UTF-8', $xlsCell); fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 $accessNum=M('test_resource','tab_')->where($map)->count(); $perSize = 5000;//每次查询的条数 $pages = ceil($accessNum / $perSize); for($i = 1; $i <= $pages; $i++) { /* 获取频道列表 */ $xlsData = M('test_resource','tab_') ->field('promote_account,user_account,game_name,server_name,role_name, apply_resource,apply_type,apply_remark,create_time,id as max_quota,verify_resource,apply_status') ->where($map) ->order('id desc') ->select(); foreach($xlsData as $key => $value) { $value['create_time'] = date("Y-m-d H:i:s", $value['create_time']); $value['max_quota'] = max_quota($value['game_id'],$value['promote_id']); $value['apply_type'] = $value['apply_type']==0?'新增扶持':'后续扶持'; if($value['apply_status'] == 1) { $value['apply_status'] = '拒绝'; } else if ($value['apply_status'] == 2) { $value['apply_status'] = '通过'; } else { $value['apply_status'] = '待审核'; } mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } fclose($fp); exit(); } public function excelUpStreamTemplate() { excelUpStreamTemplate(); } public function excelDownStreamTemplate() { excelDownStreamTemplate(); } }