diff --git a/Application/Home/Controller/DownloadController.class.php b/Application/Home/Controller/DownloadController.class.php index 07e77e5e9..5110df893 100644 --- a/Application/Home/Controller/DownloadController.class.php +++ b/Application/Home/Controller/DownloadController.class.php @@ -48,6 +48,7 @@ class DownloadController extends BaseController { $cellNum = count($expCellName); $dataNum = count($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');//合并单元格 @@ -57,10 +58,11 @@ class DownloadController extends BaseController { $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]]); - } + 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"'); @@ -2356,34 +2358,35 @@ class DownloadController extends BaseController { } public function withdrawDtlExcelInfo($id,$map) { - $xlsName = "提现记录"; - $xlsCell = array( - array('pay_order_number','充值订单号'), - array('game_name','游戏'), - array('sdk_version','平台'), - array('user_account','玩家账号'), - array('pay_amount','订单总额'), - array('cash_base','现金分成基数'), - array('selle_ratio','现金分成比例'), - array('platform_base','平台币分成基数'), - array('selle_ratio','平台币分成比例'), - array('bind_base','绑定币分成基数'), - array('selle_ratio','绑定币分成比例'), - array('pay_way_name','现金支付通道'), - array('income','收益'), - array('status','订单状态'), - array('pay_time','充值时间'), - ); - $spendModel = M('spend', 'tab_'); - $withdrawId = $map['withdraw_id']; - $withdraw = M('withdraw', 'tab_')->field('promote_id,status')->where(array('id' => $withdrawId))->find(); + $xlsName = "提现记录"; + $xlsCell = array( + '充值订单号', + '游戏', + '平台', + '玩家账号', + '订单总额', + '充值时间', + '收益', + '现金支付通道', + '现金分成基数', + '现金分成比例', + '平台币分成基数', + '平台币分成比例', + '绑定币分成基数', + '绑定币分成比例', + '订单状态', + ); + $xlsCell1 = $xlsCell; + $spendModel = M('spend', 'tab_'); + $withdrawId = $map['withdraw_id']; + $withdraw = M('withdraw', 'tab_')->field('promote_id,status')->where(array('id' => $withdrawId))->find(); $data = $spendModel - ->field('id,pay_order_number,game_name,sdk_version,user_account,pay_amount,pay_way,selle_ratio,pay_time') + ->field('pay_order_number,game_name,sdk_version,user_account,pay_amount,pay_way,selle_ratio,pay_time') ->where($map) ->order('id desc') ->select(); - if (!empty($data)) { - foreach ($data as &$list) { + if (!empty($data)) { + foreach ($data as $key => &$list) { $list['income'] = bcmul($list['pay_amount'], bcdiv($list['selle_ratio'], 100, 2), 2); $list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']); switch ($list['pay_way']) { @@ -2401,27 +2404,54 @@ class DownloadController extends BaseController { }else { $list['cash_base'] = 0; } - + $list['cash_selle_ratio'] = $list['selle_ratio']; if($list['pay_way'] == 0) { - $list['platform_base'] = $list['pay_amount']; + $list['platform_base'] = $list['pay_amount']; }else { $list['platform_base'] = 0; } - - if($list['pay_way'] == -1) { - $list['bind_base'] = $list['pay_amount']; + $list['platform_selle_ratio'] = $list['selle_ratio']; + + if($list['pay_way'] == -1) { + $list['bind_base'] = $list['pay_amount']; }else { $list['bind_base'] = 0; } - + $list['bind_selle_ratio'] = $list['selle_ratio']; + $list['status'] = FinanceController::$withdrawStatus[$withdraw['status']]; - - - } - } - $xlsData = $data; - $this->exportExcel($xlsName, $xlsCell, $xlsData,$id); - } + unset($list['pay_way']); + unset($list['selle_ratio']); + } + } + $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('gb2312', 'UTF-8', $xlsCell); + fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中 + $accessNum = '100000';//从数据库获取总量,假设是十万 + $accessNum = count($data)?:0 ; + + $perSize = 5000;//每次查询的条数 + $pages = ceil($accessNum / $perSize); + for($i = 1; $i <= $pages - 1; $i++) { + foreach($data as $value) { + mb_convert_variables('GBK', 'UTF-8', $value); + fputcsv($fp, $value); + } + unset($data); + ob_flush(); + flush(); + } + fclose($fp); + + } public function withdrawRecordExcelInfo($id,$map) { $xlsName = "提现记录";