// +---------------------------------------------------------------------- namespace Admin\Controller; use User\Api\UserApi; use Com\Wechat; use Com\WechatAuth; /** * 后台用户控制器 * @author 麦当苗儿 */ class PayChannelIntentionController extends AdminController { public static $arr_pay_way = ['alipay'=>'支付宝','wxpay'=>'微信支付','sqpay'=>'双乾快捷支付','yeepay'=>'易宝支付']; public function index($p = 0) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 if (isset($_REQUEST['row'])) { $row = $_REQUEST['row']; } else { $row = 10; } $map = []; if ($_REQUEST['timestart']&&!$_REQUEST['timeend']) { $map['create_time'] = ['egt',strtotime($_REQUEST['timestart'])]; } if (!$_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['elt',strtotime($_REQUEST['timeend'])+86399]; } if ($_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]]; // $map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])]; } if ($_REQUEST['pay_type']) { $map['pay_ways'] = ['like',"%{$_REQUEST['pay_type']}"]; } $show_data = M('pay_channel_intention','tab_') ->field('id,group_concat(tab_pay_channel_intention.`pay_way` ORDER BY tab_pay_channel_intention.create_time ASC) as pay_ways,tab_pay_channel_intention.user_account, tab_pay_channel_intention.pay_amount,CASE WHEN is_submit = 0 THEN 2 ELSE pay_status END as pay_status,tab_pay_channel_intention.pay_order_number,max(create_time) m_time') // ->join('left join tab_spend on tab_pay_channel_intention.pay_order_number=tab_spend.pay_order_number') ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.create_time DESC') ->select(false); $show_data = M('pay_channel_intention','tab_') ->field("a.pay_amount,pay_ways,a.user_account,a.pay_order_number,tab_pay_channel_intention.create_time,CASE WHEN is_submit = 1 THEN tab_pay_channel_intention.pay_status ELSE 2 END as pay_status") ->join("left join ({$show_data}) as a on tab_pay_channel_intention.pay_order_number=a.pay_order_number and tab_pay_channel_intention.create_time=m_time") ->where('pay_ways is not null') // ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.id DESC') ->select(false); $show_data = M()->table('('.$show_data.') as a') ->select(false); $data = M()->table('('.$show_data.') as a') ->field('pay_ways,user_account,pay_status, SUM(if(pay_status=0,pay_amount,0)) fail_invest_amount, SUM(if(pay_status=1,pay_amount,0)) success_invest_amount, SUM(if(pay_status=2,pay_amount,0)) nothing_invest_amount, count(if(pay_status=0,pay_amount,null)) fail_invest_count, count(if(pay_status=1,pay_amount,null)) success_invest_count, count(if(pay_status=2,pay_amount,null)) nothing_invest_count,create_time') ->where($map) ->group('a.pay_ways,a.user_account,a.pay_status') ->select(false); // dump($data);die(); $count = M()->table('('.$data.') as a') ->field('pay_ways,sum(fail_invest_amount) fail_invest_amount') // ->where($map) ->group('a.pay_ways') ->select(false); // dump($count);die(); $data = M()->table('('.$data.') as a') ->field('pay_ways,sum(fail_invest_amount) fail_invest_amount,create_time, sum(success_invest_amount) success_invest_amount, sum(nothing_invest_amount) nothing_invest_amount, count(if(pay_status=0,fail_invest_count,NULL)) fail_invest_count, count(if(pay_status=1,success_invest_count,NULL)) success_invest_count, count(if(pay_status=2,nothing_invest_count,NULL)) nothing_invest_count') ->page($page,$row) ->where($map) ->group('a.pay_ways') ->select(); $sum = M()->table('('.$show_data.') as a') ->field('pay_ways,user_account,pay_status,create_time, SUM(if(pay_status=0,pay_amount,0)) fail_invest_amount, SUM(if(pay_status=1,pay_amount,0)) success_invest_amount, SUM(if(pay_status=2,pay_amount,0)) nothing_invest_amount, count(if(pay_status=0,pay_amount,null)) fail_invest_count, count(if(pay_status=1,pay_amount,null)) success_invest_count, count(if(pay_status=2,pay_amount,null)) nothing_invest_count') ->where($map) ->group('a.pay_ways,a.user_account,a.pay_status') ->select(false); $sum = M()->table('('.$sum.') as a') ->field('pay_ways,user_account,pay_status,create_time, SUM(if(pay_status=0,fail_invest_amount,0)) fail_invest_amount, SUM(if(pay_status=1,success_invest_amount,0)) success_invest_amount, SUM(if(pay_status=2,nothing_invest_amount,0)) nothing_invest_amount, count(if(pay_status=0,fail_invest_count,null)) fail_invest_count, count(if(pay_status=1,success_invest_count,null)) success_invest_count, count(if(pay_status=2,nothing_invest_count,null)) nothing_invest_count') ->group('a.user_account,a.pay_status') ->select(false); // dump($sum);die(); $sum = M()->table('('.$sum.') as a') ->field('pay_ways,sum(fail_invest_amount) fail_invest_amount, sum(success_invest_amount) success_invest_amount, sum(nothing_invest_amount) nothing_invest_amount, count(if(pay_status=0,fail_invest_count,NULL)) fail_invest_count, count(if(pay_status=1,success_invest_count,NULL)) success_invest_count, count(if(pay_status=2,nothing_invest_count,NULL)) nothing_invest_count') ->find(); // dump($sum);die(); $this->assign('sum',$sum); $count = M()->table('('.$count.') as a')->count(); $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page);//分页 } foreach($data as $key => $value) { $arr = explode(',',$data[$key]['pay_ways']); $data[$key]['pay_way'] = self::$arr_pay_way[end($arr)]; $data[$key]['pay_ways_ch'] = ''; foreach ($arr as $k=>$v) { $data[$key]['pay_ways_ch'] = $data[$key]['pay_ways_ch'].($k+1).','.self::$arr_pay_way[$v]; } } $this->assign('data',$data); $this->display(); } public function export_index() { $xlsName = '支付意向统计导出'; $xlsCell = array( "充值点击行为", "最终使用方式", '充值成功用户数', '充值成功金额(汇总)', '下单未支付用户数', '下单未支付用户数金额(汇总)', '充值失败用户数', '充值失败金额(汇总)' ); $map = []; if ($_REQUEST['timestart']&&!$_REQUEST['timeend']) { $map['create_time'] = ['egt',strtotime($_REQUEST['timestart'])]; } if (!$_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['elt',strtotime($_REQUEST['timeend'])+86399]; } if ($_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]]; // $map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])]; } if ($_REQUEST['pay_type']) { $map['pay_ways'] = ['like',"%{$_REQUEST['pay_type']}"]; } $show_data = M('pay_channel_intention','tab_') ->field('id,group_concat(tab_pay_channel_intention.`pay_way` ORDER BY tab_pay_channel_intention.create_time ASC) as pay_ways,tab_pay_channel_intention.user_account, tab_pay_channel_intention.pay_amount,CASE WHEN is_submit = 0 THEN 2 ELSE pay_status END as pay_status,tab_pay_channel_intention.pay_order_number,max(create_time) m_time') // ->join('left join tab_spend on tab_pay_channel_intention.pay_order_number=tab_spend.pay_order_number') ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.create_time DESC') ->select(false); $show_data = M('pay_channel_intention','tab_') ->field("a.pay_amount,pay_ways,a.user_account,a.pay_order_number,tab_pay_channel_intention.create_time,CASE WHEN is_submit = 1 THEN tab_pay_channel_intention.pay_status ELSE 2 END as pay_status") ->join("left join ({$show_data}) as a on tab_pay_channel_intention.pay_order_number=a.pay_order_number and tab_pay_channel_intention.create_time=m_time") ->where('pay_ways is not null') // ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.id DESC') ->select(false); $show_data = M()->table('('.$show_data.') as a') ->select(false); $data = M()->table('('.$show_data.') as a') ->field('pay_ways,user_account,pay_status, SUM(if(pay_status=0,pay_amount,0)) fail_invest_amount, SUM(if(pay_status=1,pay_amount,0)) success_invest_amount, SUM(if(pay_status=2,pay_amount,0)) nothing_invest_amount, count(if(pay_status=0,pay_amount,null)) fail_invest_count, count(if(pay_status=1,pay_amount,null)) success_invest_count, count(if(pay_status=2,pay_amount,null)) nothing_invest_count,create_time') ->where($map) ->group('a.pay_ways,a.user_account,a.pay_status') ->select(false); $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流中 $count = M()->table('('.$show_data.') as a') ->field('count(pay_amount) count') ->group('a.pay_ways') ->select(false); $accessNum = M()->table('('.$count.') as a')->count(); $perSize = 2000;//每次查询的条数 $pages = ceil($accessNum / $perSize); for($i = 1; $i <= $pages; $i++) { $xlsData = M()->table('('.$data.') as a') ->field('"" as pay_ways_ch,"" as pay_way,pay_ways,user_account, count(if(pay_status=1,success_invest_count,NULL)) success_invest_count, sum(success_invest_amount) success_invest_amount, count(if(pay_status=0,fail_invest_count,NULL)) fail_invest_count, sum(fail_invest_amount) fail_invest_amount, count(if(pay_status=2,nothing_invest_count,NULL)) nothing_invest_count, sum(nothing_invest_amount) nothing_invest_amount') ->limit(($i-1)*$perSize ,$perSize) // ->where($map) ->group('a.pay_ways') ->select(); // $xlsData = M()->table('('.$show_data.') as a') // ->field('"" as pay_ways_ch,"" as pay_way,pay_ways,user_account, // count(if(pay_status=1,pay_amount,null)) success_invest_count, // SUM(if(pay_status=1,pay_amount,0)) success_invest_amount, // count(if(pay_status=2,pay_amount,null)) nothing_invest_count, // SUM(if(pay_status=2,pay_amount,0)) nothing_invest_amount, // count(if(pay_status=0,pay_amount,null)) fail_invest_count, // SUM(if(pay_status=0,pay_amount,0)) fail_invest_amount') // ->limit(($i-1)*$perSize ,$perSize) // ->where($map) // ->group('a.pay_ways,a.user_account,a.pay_status') // ->select(); foreach($xlsData as $key =>$value) { $arr = explode(',',$value['pay_ways']); $value['pay_way'] = self::$arr_pay_way[end($arr)]; $value['pay_ways_ch'] = ''; foreach ($arr as $k=>$v) { $value['pay_ways_ch'] = $value['pay_ways_ch'].($k+1).','.self::$arr_pay_way[$v]; } unset($value['pay_ways']); unset($value['user_account']); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } $sum = M()->table('('.$show_data.') as a') ->field('pay_ways,user_account,pay_status,create_time, SUM(if(pay_status=0,pay_amount,0)) fail_invest_amount, SUM(if(pay_status=1,pay_amount,0)) success_invest_amount, SUM(if(pay_status=2,pay_amount,0)) nothing_invest_amount, count(if(pay_status=0,pay_amount,null)) fail_invest_count, count(if(pay_status=1,pay_amount,null)) success_invest_count, count(if(pay_status=2,pay_amount,null)) nothing_invest_count') ->where($map) ->group('a.pay_ways,a.user_account,a.pay_status') ->select(false); $sum = M()->table('('.$sum.') as a') ->field('pay_ways,user_account,pay_status,create_time, SUM(if(pay_status=0,fail_invest_amount,0)) fail_invest_amount, SUM(if(pay_status=1,success_invest_amount,0)) success_invest_amount, SUM(if(pay_status=2,nothing_invest_amount,0)) nothing_invest_amount, count(if(pay_status=0,fail_invest_count,null)) fail_invest_count, count(if(pay_status=1,success_invest_count,null)) success_invest_count, count(if(pay_status=2,nothing_invest_count,null)) nothing_invest_count') ->group('a.user_account,a.pay_status') ->select(false); $sum = M()->table('('.$sum.') as a') ->field('"汇总(检索时间内所有数据的统计)" pay_ways,"" other, count(if(pay_status=1,success_invest_count,NULL)) success_invest_count, sum(success_invest_amount) success_invest_amount, count(if(pay_status=0,fail_invest_count,NULL)) fail_invest_count, sum(fail_invest_amount) fail_invest_amount, count(if(pay_status=2,nothing_invest_count,NULL)) nothing_invest_count, sum(nothing_invest_amount) nothing_invest_amount ') ->find(); mb_convert_variables('GBK', 'UTF-8', $sum); fputcsv($fp, $sum); //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 fclose($fp); $getData = $_GET; unset($getData['id']); unset($getData['xlsname']); } public function detail($p = 0) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 if (isset($_REQUEST['row'])) { $row = $_REQUEST['row']; } else { $row = 10; } $map = []; if ($_REQUEST['pay_ways']) { $map['pay_ways'] = ['like',"%{$_REQUEST['pay_ways']}"]; } if ($_REQUEST['pay_way']) { $map['pay_ways'] = $_REQUEST['pay_way']; } $pay_type = end(explode(',',$_REQUEST['pay_way'])); if (!$_REQUEST['pay_way']&&$_REQUEST['pay_ways']) { $pay_type = $_REQUEST['pay_ways']; } if ($_REQUEST['pay_ways']) { $this->assign('pay_type',$pay_type); } if ($_REQUEST['user_account']) { $map['user_account'] = $_REQUEST['user_account']; } if ($_REQUEST['pay_status'] || $_REQUEST['pay_status'] == '0') { $map['pay_status'] = $_REQUEST['pay_status']; if ($_REQUEST['pay_status'] == 4) { $map['pay_status'] = 1; $map['pay_game_status'] = 1; } if ($_REQUEST['pay_status'] == 3) { $map['pay_status'] = 1; $map['pay_game_status'] = 0; } } if ($_REQUEST['timestart']&&!$_REQUEST['timeend']) { $map['create_time'] = ['egt',strtotime($_REQUEST['timestart'])]; } if (!$_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['elt',strtotime($_REQUEST['timeend'])+86399]; } if ($_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]]; // $map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])]; } // var_dump($map);die(); $data = M('pay_channel_intention','tab_') ->field('id,group_concat(tab_pay_channel_intention.`pay_way` ORDER BY tab_pay_channel_intention.create_time ASC) as pay_ways, count(if(tab_pay_channel_intention.pay_way="alipay",tab_pay_channel_intention.pay_way,null)) alipay, count(if(tab_pay_channel_intention.pay_way="wxpay",tab_pay_channel_intention.pay_way,null)) wxpay, count(if(tab_pay_channel_intention.pay_way="sqpay",tab_pay_channel_intention.pay_way,null)) sqshorcut, count(if(tab_pay_channel_intention.pay_way="yeepay",tab_pay_channel_intention.pay_way,null)) shorcut, tab_pay_channel_intention.user_account, tab_pay_channel_intention.pay_amount, tab_pay_channel_intention.pay_order_number,tab_pay_channel_intention.create_time,max(create_time) m_time') // ->join('left join tab_spend on tab_pay_channel_intention.pay_order_number=tab_spend.pay_order_number') ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.id DESC') ->select(false); $data = M('pay_channel_intention','tab_') ->field('a.*, CASE WHEN is_submit = 0 THEN 2 ELSE pay_status END as pay_status, CASE WHEN is_submit = 0 THEN 2 ELSE pay_game_status END as pay_game_status') ->join("left join ({$data}) as a on tab_pay_channel_intention.pay_order_number=a.pay_order_number and tab_pay_channel_intention.create_time=m_time") ->where('pay_ways is not null') ->select(false); // dump($data);die(); $count = M()->table('('.$data.') as a') ->field('id') ->where($map) ->count(); $data = M()->table('('.$data.') as a') ->page($page,$row) ->where($map) ->select(); $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page);//分页 } $sum = M('pay_channel_intention','tab_') ->field('group_concat(tab_pay_channel_intention.`pay_way` ORDER BY tab_pay_channel_intention.create_time ASC) as pay_ways, count(if(tab_pay_channel_intention.pay_way="alipay",tab_pay_channel_intention.pay_way,null)) alipay, count(if(tab_pay_channel_intention.pay_way="wxpay",tab_pay_channel_intention.pay_way,null)) wxpay, count(if(tab_pay_channel_intention.pay_way="sqpay",tab_pay_channel_intention.pay_way,null)) sqshorcut, count(if(tab_pay_channel_intention.pay_way="yeepay",tab_pay_channel_intention.pay_way,null)) shorcut, tab_pay_channel_intention.user_account, tab_pay_channel_intention.pay_amount, tab_pay_channel_intention.pay_order_number,tab_pay_channel_intention.create_time,max(create_time) m_time') // ->join('left join tab_spend on tab_pay_channel_intention.pay_order_number=tab_spend.pay_order_number') ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.create_time ASC') ->select(false); $sum = M('pay_channel_intention','tab_') ->field('a.*, CASE WHEN is_submit = 0 THEN 2 ELSE pay_status END as pay_status, CASE WHEN is_submit = 0 THEN 2 ELSE pay_game_status END as pay_game_status') ->join("left join ({$sum}) as a on tab_pay_channel_intention.pay_order_number=a.pay_order_number and tab_pay_channel_intention.create_time=m_time") ->where('pay_ways is not null') ->select(false); $sum = M()->table('('.$sum.') as a') ->field("sum(pay_amount) pay_amount,sum(alipay) alipay,sum(wxpay) wxpay,sum(sqshorcut) sqshorcut,sum(shorcut) shorcut") ->where($map) ->find(); foreach ($data as $key => $value) { $data[$key]['create_time'] = date('Y-m-d H:i:s',$data[$key]['create_time']); } $this->assign('data',$data); $this->assign('sum',$sum); $this->display(); } public function export_detail() { $xlsName = '支付意向统计详情导出'; $xlsCell = array( "用户", "充值金额", '支付宝', '微信', '易宝', '双乾快捷支付', '时间', '支付状态', '关联订单' ); $map = []; if ($_REQUEST['pay_ways']) { $map['pay_ways'] = $_REQUEST['pay_ways']; } if ($_REQUEST['user_account']) { $map['user_account'] = $_REQUEST['user_account']; } if ($_REQUEST['pay_status'] || $_REQUEST['pay_status'] == '0') { $map['pay_status'] = $_REQUEST['pay_status']; if ($_REQUEST['pay_status'] == 3) { $map['pay_status'] = 1; $map['pay_game_status'] = 1; } } if ($_REQUEST['timestart']&&!$_REQUEST['timeend']) { $map['create_time'] = ['egt',strtotime($_REQUEST['timestart'])]; } if (!$_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['elt',strtotime($_REQUEST['timeend'])+86399]; } if ($_REQUEST['timestart']&&$_REQUEST['timeend']) { $map['create_time'] = ['between',[strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+86399]]; // $map['create_time'] = ['elt',strtotime($_REQUEST['time_end'])]; } $data = M('pay_channel_intention','tab_') ->field('id,group_concat(tab_pay_channel_intention.`pay_way` ORDER BY tab_pay_channel_intention.create_time ASC) as pay_ways, count(if(tab_pay_channel_intention.pay_way="alipay",tab_pay_channel_intention.pay_way,null)) alipay, count(if(tab_pay_channel_intention.pay_way="wxpay",tab_pay_channel_intention.pay_way,null)) wxpay, count(if(tab_pay_channel_intention.pay_way="sqpay",tab_pay_channel_intention.pay_way,null)) sqshorcut, count(if(tab_pay_channel_intention.pay_way="yeepay",tab_pay_channel_intention.pay_way,null)) shorcut, tab_pay_channel_intention.user_account, tab_pay_channel_intention.pay_amount, tab_pay_channel_intention.pay_order_number,tab_pay_channel_intention.create_time,max(create_time) m_time') // ->join('left join tab_spend on tab_pay_channel_intention.pay_order_number=tab_spend.pay_order_number') ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.id DESC') ->select(false); $data = M('pay_channel_intention','tab_') ->field('a.*, CASE WHEN is_submit = 0 THEN 2 ELSE pay_status END as pay_status, CASE WHEN is_submit = 0 THEN 2 ELSE pay_game_status END as pay_game_status') ->join("left join ({$data}) as a on tab_pay_channel_intention.pay_order_number=a.pay_order_number and tab_pay_channel_intention.create_time=m_time") ->where('pay_ways is not null') ->select(false); $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()->table('('.$data.') as a') ->where($map) ->count(); $perSize = 2000;//每次查询的条数 $pages = ceil($accessNum / $perSize); for($i = 1; $i <= $pages; $i++) { $xlsData = M()->table('('.$data.') as a') ->field('user_account,pay_amount,alipay,wxpay,shorcut,sqshorcut,create_time,pay_status,pay_game_status,pay_order_number') ->where($map) ->limit(($i-1)*$perSize ,$perSize) ->select(); foreach($xlsData as $key =>$value) { if ($value['pay_status'] == 0) { $value['pay_status'] = '支付失败'; } else if($value['pay_status'] == 1) { $value['pay_status'] = '支付成功'; } else if($value['pay_status'] == 2) { $value['pay_status'] = '下单未支付'; } if ($value['pay_game_status'] == 0) { $value['pay_status'] .= '通知失败'; } else if($value['pay_game_status'] == 1) { $value['pay_status'] .= '通知成功'; } else if($value['pay_game_status'] == 2) { $value['pay_status'] .= '未通知'; } unset($value['pay_game_status']); $value['create_time'] = date('Y-m-d H:i:s',$value['create_time']); // var_dump($value);die(); mb_convert_variables('GBK', 'UTF-8', $value); fputcsv($fp, $value); } unset($xlsData);//释放变量的内存 //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 } $sum = M('pay_channel_intention','tab_') ->field('group_concat(tab_pay_channel_intention.`pay_way` ORDER BY tab_pay_channel_intention.create_time ASC) as pay_ways, count(if(tab_pay_channel_intention.pay_way="alipay",tab_pay_channel_intention.pay_way,null)) alipay, count(if(tab_pay_channel_intention.pay_way="wxpay",tab_pay_channel_intention.pay_way,null)) wxpay, count(if(tab_pay_channel_intention.pay_way="sqpay",tab_pay_channel_intention.pay_way,null)) sqshorcut, count(if(tab_pay_channel_intention.pay_way="yeepay",tab_pay_channel_intention.pay_way,null)) shorcut, tab_pay_channel_intention.user_account, tab_pay_channel_intention.pay_amount, tab_pay_channel_intention.pay_order_number,tab_pay_channel_intention.create_time,max(create_time) m_time') // ->join('left join tab_spend on tab_pay_channel_intention.pay_order_number=tab_spend.pay_order_number') ->group('tab_pay_channel_intention.pay_order_number') ->order('tab_pay_channel_intention.create_time ASC') ->select(false); $sum = M('pay_channel_intention','tab_') ->field('a.*, CASE WHEN is_submit = 0 THEN 2 ELSE pay_status END as pay_status, CASE WHEN is_submit = 0 THEN 2 ELSE pay_game_status END as pay_game_status') ->join("left join ({$sum}) as a on tab_pay_channel_intention.pay_order_number=a.pay_order_number and tab_pay_channel_intention.create_time=m_time") ->where('pay_ways is not null') ->select(false); $sum = M()->table('('.$sum.') as a') ->field("'汇总(检索时间内所有数据的统计)' as user_account,sum(pay_amount) pay_amount,sum(alipay) alipay,sum(wxpay) wxpay,sum(sqshorcut) sqshorcut,sum(shorcut) shorcut") ->where($map) ->find(); mb_convert_variables('GBK', 'UTF-8', $sum); fputcsv($fp, $sum); //刷新输出缓冲到浏览器 ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 fclose($fp); $getData = $_GET; unset($getData['id']); unset($getData['xlsname']); } }