You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1584 lines
68 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Admin\Controller;
use Org\Util\Date;
use Sdk\Controller\AgeController;
use User\Api\MemberApi as MemberApi;
use Org\WeixinSDK\Weixin;
class PayChannelController extends ThinkController
{
public function index($p = 0) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map = [];
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$coinMap['tab_deposit.create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$bindMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$spreadMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$coinMap['tab_deposit.create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$bindMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$spreadMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$coinMap['tab_deposit.create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$bindMap['create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$offcialmap['create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$spreadMap['create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
}
if (!empty($_REQUEST['game_id'])) {
$map['game_id'] = $_REQUEST['game_id'];
$bindMap['game_id'] = $_REQUEST['game_id'];
$coinMap['game_id'] = $_REQUEST['game_id'];
}
$map['pay_status'] = $coinMap['pay_status'] = 1;
$map['pay_way'] = array('egt',1);
// setPowerPromoteIds($map,'promote_id');
//游戏币计算
$data = M('spend','tab_')
->field("game_name,sum(pay_amount) as pay_amount,game_id")
->where($map)
->group('game_id')
->order('pay_amount desc')
->select();
//平台币充值金额计算
$coinMap['pay_source'] = 2;
$coinMap['extend'] = array('eq','');
$coinMap['tab_deposit.pay_way'] = array('egt',1);
// setPowerPromoteIds($coinMap,'tab_deposit.promote_id');
$coinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->field("tab_pay_info.game_name,0 as pay_amount,sum(tab_deposit.pay_amount) as platform_coin,0 as test_coin,tab_pay_info.game_id")
->where($coinMap)
->group("game_id")
->select();
// unset($coinMap['game_id']);
//平台币充值
$coinSum = M('deposit','tab_')
->where($coinMap)
->sum('tab_deposit.pay_amount');
$data = array_merge($data,$coinData);
$data = $this->unique_multi_array($data,'game_id');
//将平台币导入游戏数据中
$handleCoinData = [];
foreach($coinData as $key => $value) {
$handleCoinData[$value['game_id']] = $value['platform_coin'];
}
//测试数据汇总计算
$testData = M('spend','tab_')
->field("sum(pay_amount) as test_coin,game_name,game_id")
->join("inner join tab_test_white_list on tab_spend.user_id=tab_test_white_list.user_id")
->where($map)
->group('game_id')
->select();
//测试平台币充值金额计算
$testCoinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("sum(tab_deposit.pay_amount) as test_coin,tab_pay_info.game_name,tab_pay_info.game_id")
->where($coinMap)
->group("game_id")
->select();
// var_dump($testCoinData);die();
$handleTestData = [];
foreach($testData as $key => $value) {
$handleTestData[$value['game_id']] = $value['test_coin'];
}
$handleTestCoinData = [];
foreach($testCoinData as $key => $value) {
$handleTestCoinData[$value['game_id']] = $value['test_coin'];
}
foreach ($data as $key => $value) {
$data[$key]['platform_coin'] = $handleCoinData[$value['game_id']]?$handleCoinData[$value['game_id']]:0;
$data[$key]['test_coin'] = $handleTestData[$value['game_id']]?$handleTestData[$value['game_id']]:0;
$data[$key]['test_platform_coin'] = $handleTestCoinData[$value['game_id']]?$handleTestCoinData[$value['game_id']]:0;
}
$superMap = $map;
// unset($superMap['promote_id']);
//超级签数据
$superSignData = M('game_supersign','tab_')
->field("0 as game_name,sum(pay_price) as pay_amount,0 as platform_coin,0 as test_coin")
->where($superMap)
->find();
$testSuperSignCost = M('game_supersign','tab_')
->join("inner join tab_test_white_list on tab_game_supersign.user_id=tab_test_white_list.user_id")
->where($superMap)
->sum('pay_price');
$superSignData['test_coin'] = $testSuperSignCost?$testSuperSignCost:0;
$superSignData['sum'] = $superSignData['pay_amount']?$superSignData['pay_amount']:0;
$superSignData['pay_amount'] = $superSignData['pay_amount'] - $superSignData['test_coin'];
// var_dump($testSuperSignCost);die();
$this->assign('superSignData',$superSignData);
//官网数据
$offcialmap['pay_status'] = 1;
$offcialmap['pay_way'] = array('egt',1);
$offcialmap['pay_source'] = 0;
// setPowerPromoteIds($offcialmap,'promote_id');
$offcialData = M('deposit','tab_')
->field("id as game_name,sum(pay_amount) as pay_amount,0 as platform_coin,0 as test_coin")
->where($offcialmap)
->find();
$offcialTestCost = M('deposit','tab_')
->join("inner join tab_test_white_list on tab_deposit.user_id=tab_test_white_list.user_id")
->where($offcialmap)
->sum('pay_amount');
$offcialData['test_coin'] = $offcialTestCost?$offcialTestCost:0;
$bindMap['pay_status'] = 1;
$bindMap['pay_way'] = array('egt',1);
// setPowerPromoteIds($bindMap,'promote_id');
$bindRechargeData = M('bind_recharge','tab_')
->field('sum(real_amount) as pay_amount')
->where(array($bindMap))
->find();
$bindRechargeData['pay_amount'] = $bindRechargeData['pay_amount']?$bindRechargeData['pay_amount']:0;
$offcialData['sum'] = $offcialData['pay_amount']+$bindRechargeData['pay_amount'];
$offcialData['pay_amount'] = $offcialData['pay_amount']+$bindRechargeData['pay_amount']-$offcialData['test_coin'];
$this->assign('offcialData',$offcialData);
$spreadMap['order_status'] = array('egt',1);
$spreadMap['pay_way'] = array('egt',1);
// setPowerPromoteIds($spreadMap,'promote_id');
//推广后台
$spreadData = M("coin_pay_order","tab_")
->field("0 as game_name,sum(pay_amount) as pay_amount,0 as platform_coin,id as test_coin")
->where($spreadMap)
->find();
$spreadData['pay_amount'] = $spreadData['pay_amount']?$spreadData['pay_amount']:0;
$spreadData['sum'] = $spreadData['pay_amount'];
$this->assign('spreadData',$spreadData);
$channelData = $this->getPayChannel($map);
$payTypeData['支付宝支付金额'] = 0;
$payTypeData['微信支付金额'] = 0;
$payTypeData['快捷支付金额'] = 0;
$payTypeData['其他支付金额'] = 0;
foreach($channelData as $key => $value) {
if ($value['pay_way']==1 || $value['pay_way']==9 ) {
$payTypeData['支付宝支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if ($value['pay_way']==2 || $value['pay_way']==3 ) {
$payTypeData['微信支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if ($value['pay_way']==15) {
$payTypeData['快捷支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if($value['pay_way']){
$payTypeData['其他支付金额'] += number_format($value['pay_amount'],2,'.','');
}
}
$this->assign('payTypeData',$payTypeData);
foreach($channelData as $key=>$value) {
$channelData[$key]['pay_amount'] = number_format($value['pay_amount'],2,'.','');
$channelData[$key]['pay_way'] = get_pay_way($value['pay_way']);
if (!$value['pay_way']) {
unset($channelData[$key]);
}
}
$count = count($data);
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$sumData['game'] = '汇总';
$sumData['pay_amount'] = 0;
$sumData['platform_coin'] = 0;
$sumData['test_coin'] = 0;
$sumData['test_platform_coin'] = 0;
foreach ($data as $key => $value) {
$data[$key]['pay_amount'] = $value['pay_amount'] - $value['test_coin'];
$data[$key]['platform_coin'] = $value['platform_coin'] - $value['test_platform_coin'];
$data[$key]['test_coin'] = $value['test_coin'] + $value['test_platform_coin'];
$data[$key]['sum'] = $value['pay_amount'] + $value['platform_coin'];
if($_REQUEST['export'] == 1) {
unset($data[$key]['game_id'] );
unset($data[$key]['test_platform_coin']);
}
//汇总计算
$sumData['pay_amount'] += $value['pay_amount'] - $value['test_coin'];
$sumData['platform_coin'] += $handleCoinData[$value['game_id']]?$handleCoinData[$value['game_id']]:0;
$sumData['test_coin'] += $handleTestData[$value['game_id']]?$handleTestData[$value['game_id']]:0;
$sumData['test_platform_coin'] +=$handleTestCoinData[$value['game_id']]?$handleTestCoinData[$value['game_id']]:0;
}
//汇总数据
if ($_REQUEST['game_id']) {
$sumData['platform_coin'] = $sumData['platform_coin'] - $sumData['test_platform_coin'];
$sumData['test_coin'] = $sumData['test_coin']+$sumData['test_platform_coin'];
$sumData['sum'] = $sumData['pay_amount'] +$sumData['test_coin'] + $sumData['platform_coin'];
} else {
$sumData['pay_amount'] = $sumData['pay_amount'] + $superSignData['pay_amount'] + $bindRechargeData['pay_amount'];
$sumData['platform_coin'] = $sumData['platform_coin'] - $sumData['test_platform_coin'] +
$offcialData['pay_amount'] + $spreadData['pay_amount'];
$sumData['test_coin'] = $sumData['test_coin']+$offcialTestCost+$testSuperSignCost+$sumData['test_platform_coin'];
$sumData['sum'] = $sumData['pay_amount'] +$sumData['test_coin'] + $sumData['platform_coin'];
$coinSum = $coinSum + $offcialData['pay_amount'] + $spreadData['pay_amount']+$offcialTestCost;
}
if($_REQUEST['export'] == 1) {
$title = array('产品名称','游戏现金金额','平台币直冲金额','测试金额','支付渠道内合计');
$superSignData['game_name'] = '超级签';
$offcialData['game_name'] = '官网';
$spreadData['game_name'] = '推广后台';
$superSignData['platform_coin'] = '0';
$offcialData['platform_coin'] = '0';
$spreadData['platform_coin'] = '0';
$spreadData['test_coin'] = '0';
//充值方式统计
$payTypeDataExport['game_name'] = '充值方式统计';
foreach($payTypeData as $key => $value) {
if ($value) {
$payTypeDataExport['pay_amount'] .= $key.''.$value." ";
}
}
$payTypeDataExport['pay_amount'] .= "平台币直充总金额(2019.12.18号以前的不显示在列表中,此项也不计入充值方式统计)".
($coinSum);
$channelDataExport['game_name'] = '支付渠道';
foreach($channelData as $key => $value) {
if ($value) {
$channelDataExport['pay_amount'] .= $value['pay_way'].''.$value['pay_amount']." ";
}
}
unset($sumData['test_platform_coin']);
if ($_REQUEST['game_id']) {
unset($superSignData);
unset($offcialData);
unset($spreadData);
}
db2csv(array_merge(array_merge(array_merge(array_merge(
array_merge(array_merge(
array_merge($data,[0=>$superSignData]),[0=>$offcialData])),[0=>$spreadData],[0=>$sumData])),[0=>$payTypeDataExport]),[0=>$channelDataExport]),'支付渠道统计导出',$title);
}
$this->meta_title = "支付渠道统计";
$size = $row;//每页显示的记录数
$data = array_slice($data, ($arraypage - 1) * $size, $size);
//平台币直充金额,下面列表
$this->assign('coinSum',$coinSum);
$this->assign('sumData',$sumData);
$this->assign('channelData',$channelData);
$this->assign('listdata',$data);
//统计总额和比例
$this->assign('channelData2',$channelData);
$moneyAllCount = array_sum(array_column($channelData, 'pay_amount'));
$this->assign('moneyAllCount',$moneyAllCount);
$this->display();
}
protected function unique_multi_array($array, $key)
{
$temp_array = [];
$i = 0;
$key_array = [];
foreach ($array as $val) {
if (!in_array($val[$key], $key_array)) {
$key_array[$i] = $val[$key];
$temp_array[$i] = $val;
}
$i++;
}
return $temp_array;
}
public function getPayChannel($map) {
//支付
//游戏订单渠道
$channelData = M('spend','tab_')
->field('sum(pay_amount) as pay_amount,pay_way')
->where($map)
->group('pay_way')
->select(false);
//超级签数据
$superSignDataPay = M('game_supersign','tab_')
->field("sum(pay_price) as pay_amount,pay_way")
->where($map)
->group('pay_way')
->select(false);
//推广后台充值数据
$spreadMap['order_status'] = array('egt',1);
$spreadMap['pay_way'] = array('egt',1);
if($map['pay_time']) {
$spreadMap['create_time'] = $map['pay_time'];
}
// $spreadMap['promote_id'] = $map['promote_id'];
//推广后台
$spreadDataPay = M("coin_pay_order","tab_")
->field("sum(pay_amount) as pay_amount,pay_way")
->where($spreadMap)
->select(false);
if ($map['pay_time']) {
$map['create_time'] = $map['pay_time'];
unset($map['pay_time']);
}
//充值平台币数据
$depositData = M('deposit','tab_')
->field('sum(pay_amount) as pay_amount,pay_way')
->where($map)
->group('pay_way')
->select(false);
if ($_REQUEST['game_id']) {
if ($map['pay_way']) {
$map['tab_deposit.pay_way'] = $map['pay_way'];
unset($map['pay_way']);
}
if ($map['create_time']) {
$map['tab_deposit.create_time'] = $map['create_time'];
unset($map['create_time']);
}
$map['tab_deposit.pay_source'] = 2;
$map['tab_pay_info.extend'] = '';
$depositData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->field('sum(pay_amount) as pay_amount,tab_deposit.pay_way as pay_way')
->where($map)
->group('tab_deposit.pay_way')
->select(false);
// var_dump($depositData);die();
}
$bindMap['pay_status'] = 1;
$bindMap['pay_way'] = array('egt',1);
if($_REQUEST['game_id']) {
$bindMap['game_id'] =$_REQUEST['game_id'];
}
if ($map['pay_time']) {
$bindMap['create_time'] = $map['pay_time'];
}
// $bindMap['promote_id'] = $map['promote_id'];
$bindRechargeData = M('bind_recharge','tab_')
->field('sum(real_amount) as pay_amount,pay_way')
->where($bindMap)
->select(false);
if(!$_REQUEST['game_id']) {
$sql = "{$channelData} UNION ALL {$depositData} UNION ALL {$superSignDataPay} UNION ALL {$spreadDataPay} UNION ALL {$bindRechargeData}";
} else {
$sql = "{$channelData} UNION ALL {$depositData}";
}
//将语句整合起来查询
$channelData = "select sum(pay_amount) as pay_amount,pay_way from ({$sql})t group by pay_way;";
// var_dump($channelData);die();
$channelData = M()->query($channelData);
return $channelData;
}
public function gameDetail($p=1) {
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map = [];
$coinMap = [];
$model = 'spend';
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$coinMap['tab_deposit.create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$spreadMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$coinMap['tab_deposit.create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$spreadMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$coinMap['tab_deposit.create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$spreadMap['create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
}
if (!empty($_REQUEST['pay_order_number'])) {
$map['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
$coinMap['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
$spreadMap['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
$offcialmap['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
}
if (!empty($_REQUEST['user_account'])) {
$map['user_account'] = array('like',"{$_REQUEST['user_account']}%");
$coinMap['tab_deposit.user_account'] = array('like',"{$_REQUEST['user_account']}%");
}
$coinMap['tab_deposit.pay_way'] =$spreadMap['pay_way']=$map['pay_way'] = array('egt',1);
$offcialmap['pay_way'] = array('egt',1);
if (!empty($_REQUEST['pay_way']) || $_REQUEST['pay_way']=='0') {
if ($_REQUEST['pay_way']=="2") {
$_REQUEST['pay_way'] = ['in', '2,3,4'];
}
$map['pay_way'] = $_REQUEST['pay_way'];
$coinMap['tab_deposit.pay_way'] = $_REQUEST['pay_way'];
$spreadMap['pay_way'] = $_REQUEST['pay_way'];
$offcialmap['pay_way'] = $_REQUEST['pay_way'];
}
$_REQUEST['game_id']?$map['game_id'] = $_REQUEST['game_id']:false;
$_REQUEST['game_id']?$coinMap['game_id'] = $_REQUEST['game_id']:false;
$map['pay_status'] = 1;
$_REQUEST['model']?$model= $_REQUEST['model']:false;
$page = $p ? $p : 1; //默认显示第一页数据
// setPowerPromoteIds($map,'promote_id');
// setPowerPromoteIds($coinMap,'tab_deposit.promote_id');
$spendData = M('spend','tab_')
->field("pay_order_number,pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,cost,pay_amount,pay_way")
->where($map)
->select(false);
// var_dump($spendData);die();
$coinMap['pay_status'] = 1;
$coinMap['pay_source'] = 2;
$coinMap['extend'] = '';
$coinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->field("pay_order_number,tab_deposit.create_time as pay_time,tab_deposit.user_account,tab_pay_info.game_name,tab_deposit.promote_account,
tab_deposit.pay_ip as spend_ip,tab_pay_info.server_name,tab_pay_info.game_player_name,
tab_deposit.pay_amount as cost,tab_deposit.pay_amount,tab_deposit.pay_way")
->where($coinMap)
->select(false);
$spreadMap['order_status'] = array('egt',1);
// setPowerPromoteIds($spreadMap,'promote_id');
// $spreadMap['pay_way'] = array('egt',1);
$coin_pay_order = M('coin_pay_order','tab_')
->field("pay_order_number,create_time as pay_time,promote_account,pay_amount,real_amount as cost,pay_way")
->where($spreadMap)
->select(false);
//官网数据
$offcialmap['pay_status'] = 1;
$offcialmap['pay_source'] = 0;
// setPowerPromoteIds($offcialmap,'promote_id');
$offcialData = M('deposit','tab_')
->field("pay_order_number,create_time as pay_time,user_account,promote_account,pay_ip as spend_ip,pay_amount as cost,pay_amount,pay_way")
->where($offcialmap)
->select(false);
if ($map['user_account']) {
$map['account'] = $map['user_account'];
unset($map['user_account']);
}
if ($map['pay_order_number']){
$map['order_id'] = $map['pay_order_number'];
unset($map['pay_order_number']);
}
// unset($map['promote_id']);
//超级签数据
$superSignData = M('game_supersign','tab_')
->field("order_id as pay_order_number,pay_time,tab_user.account as user_account,tab_user.promote_account,pay_price as cost,pay_price as pay_amount,pay_way")
->join('inner join tab_user on tab_user.id=tab_game_supersign.user_id')
->where($map)
->select(false);
if ($model == 'spend') {
$unionSql = "{$spendData} UNION ALL {$coinData}";
} elseif($model == 'coin_pay_order') {
$unionSql = "{$coin_pay_order}";
} elseif($model == 'deposit') {
$unionSql = "{$offcialData}";
} elseif($model == 'game_supersign') {
$unionSql = "{$superSignData}";
}
$page = ($page-1) * $row;
$sql = "select * from ({$unionSql})t order by pay_time DESC limit {$page},{$row};";
$data = M()->query($sql);
foreach ($data as $key => $value) {
$data[$key]['pay_time'] = date('Y-m-d H:i:s',$value['pay_time']);
}
$sql = "select count(1) as count from ({$unionSql})t;";
$count = M()->query($sql);
$count = $count[0]['count'];
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
//总计金额逻辑
if ($model == 'spend') {
$unionSql = "{$spendData}";
} elseif($model == 'coin_pay_order') {
$unionSql = "{$coin_pay_order}";
} elseif($model == 'deposit') {
$unionSql = "{$offcialData}";
} elseif($model == 'game_supersign') {
$unionSql = "{$superSignData}";
}
$sql = "select sum(pay_amount) as pay_amount,pay_way from ({$unionSql})t group by pay_way;";
$sumData = M()->query($sql);
$sumAllData['pay_amount'] = 0;
$sumAllData['platform_amount'] = 0;
if ($model == 'spend') {
$sumAllData['platform_amount'] = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->where($coinMap)
->sum('tab_deposit.pay_amount');
}
$sumAllData['platform_amount'] = $sumAllData['platform_amount']?$sumAllData['platform_amount']:0;
foreach ($sumData as $key => $value) {
if ($value['pay_way']>=1) {
if($model == 'deposit'||$model == 'coin_pay_order') {
$sumAllData['platform_amount'] += $value['pay_amount'];
} else {
$sumAllData['pay_amount'] += $value['pay_amount'];
}
}
}
$this->meta_title = "游戏订单查看";
$sumAllData['sum'] = $sumAllData['bind_amount']+$sumAllData['platform_amount']+$sumAllData['pay_amount'];
// var_dump($sumAllData);die();
$this->assign('sumAllData',$sumAllData);
$this->assign('data',$data);
$this->display();
}
public function export_gameDatail() {
$xlsName = $_REQUEST['xlsname'];
$map = [];
$coinMap = [];
$model = 'spend';
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$coinMap['tab_pay_info.create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$spreadMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$coinMap['tab_pay_info.create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$spreadMap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$coinMap['tab_pay_info.create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$spreadMap['create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
$offcialmap['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
}
if (!empty($_REQUEST['pay_order_number'])) {
$map['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
$coinMap['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
$spreadMap['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
$offcialmap['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
}
if (!empty($_REQUEST['user_account'])) {
$map['user_account'] = array('like',"{$_REQUEST['user_account']}%");
$coinMap['tab_deposit.user_account'] = array('like',"{$_REQUEST['user_account']}%");
}
$coinMap['tab_deposit.pay_way'] =$spreadMap['pay_way']=$map['pay_way'] = array('egt',1);
$offcialmap['pay_way'] = array('egt',1);
if (!empty($_REQUEST['pay_way']) || $_REQUEST['pay_way']=='0') {
$map['pay_way'] = $_REQUEST['pay_way'];
$coinMap['tab_deposit.pay_way'] = $_REQUEST['pay_way'];
$spreadMap['pay_way'] = $_REQUEST['pay_way'];
$offcialmap['pay_way'] = $_REQUEST['pay_way'];
}
$_REQUEST['game_id']?$map['game_id'] = $_REQUEST['game_id']:false;
$_REQUEST['game_id']?$coinMap['game_id'] = $_REQUEST['game_id']:false;
$map['pay_status'] = 1;
// setPowerPromoteIds($map,'promote_id');
// setPowerPromoteIds($coinMap,'tab_deposit.promote_id');
// $_REQUEST['model']?$model= $_REQUEST['model']:false;
if ($_REQUEST['model']) {
$model= $_REQUEST['model'];
}
$spendData = M('spend','tab_')
->field("pay_order_number,pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,cost,pay_amount,pay_way")
->where($map)
->select(false);
// var_dump($spendData);die();
$coinMap['pay_status'] = 1;
$coinMap['pay_source'] = 2;
$coinMap['extend'] = '';
$coinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->field("pay_order_number,tab_deposit.create_time as pay_time,tab_deposit.user_account,tab_pay_info.game_name,tab_deposit.promote_account,
tab_deposit.pay_ip as spend_ip,tab_pay_info.server_name,tab_pay_info.game_player_name,
tab_deposit.pay_amount as cost,tab_deposit.pay_amount,tab_deposit.pay_way")
->where($coinMap)
->select(false);
$spreadMap['order_status'] = array('egt',1);
// setPowerPromoteIds($spreadMap,'promote_id');
$coin_pay_order = M('coin_pay_order','tab_')
->field("pay_order_number,create_time as pay_time,promote_account,pay_amount as cost,real_amount as pay_amount,pay_way")
->where($spreadMap)
->select(false);
//官网数据
$offcialmap['pay_status'] = 1;
$offcialmap['pay_source'] = 0;
// setPowerPromoteIds($offcialmap,'promote_id');
$offcialData = M('deposit','tab_')
->field("pay_order_number,create_time as pay_time,user_account,promote_account,pay_ip as spend_ip,pay_amount as cost,pay_amount,pay_way")
->where($offcialmap)
->select(false);
if ($map['user_account']) {
$map['account'] = $map['user_account'];
unset($map['user_account']);
}
if ($map['pay_order_number']){
$map['order_id'] = $map['pay_order_number'];
unset($map['pay_order_number']);
}
// unset($map['promote_id']);
//超级签数据
$superSignData = M('game_supersign','tab_')
->field("order_id as pay_order_number,pay_time,tab_user.account as user_account,tab_user.promote_account,pay_price as cost,pay_price as pay_amount,pay_way")
->join('inner join tab_user on tab_user.id=tab_game_supersign.user_id')
->where($map)
->select(false);
if ($model == 'spend') {
$xlsCell = array('支付订单号', '充值时间', '玩家账号', '游戏名称', '所属推广员', '充值ip', '游戏区服', '角色名称', '订单金额', '实付金额', '充值方式');
$unionSql = "{$spendData} UNION ALL {$coinData}";
} elseif($model == 'coin_pay_order') {
$xlsCell = array('支付订单号', '充值时间', '所属推广员', '订单金额', '实付金额', '充值方式');
$unionSql = "{$coin_pay_order}";
} elseif($model == 'deposit') {
$xlsCell = array('支付订单号', '充值时间', '玩家账号', '所属推广员', '充值ip', '订单金额', '实付金额', '充值方式');
$unionSql = "{$offcialData}";
} elseif($model == 'game_supersign') {
$xlsCell = array('支付订单号', '充值时间', '玩家账号', '所属推广员', '订单金额', '实付金额', '充值方式');
$unionSql = "{$superSignData}";
}
$sql = "select count(1) as count from ({$unionSql})t;";
$count = M()->query($sql);
$accessNum = $count[0]['count'];
$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++) {
$page = ($i-1)*$perSize;
$sql = "select * from ({$unionSql})t order by pay_time DESC limit {$page},{$perSize};";
$xlsData = M()->query($sql);
foreach ($xlsData as $k => $v) {
$v['pay_time'] = date('Y-m-d H:i:s',$v['pay_time']);
$v['pay_way'] = get_pay_way($v['pay_way']);
$xlsData[] = $v;
mb_convert_variables('GBK', 'UTF-8', $v);
fputcsv($fp, $v);
}
unset($xlsData);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
//总计金额逻辑
if ($model == 'spend') {
$unionSql = "{$spendData}";
} elseif($model == 'coin_pay_order') {
$unionSql = "{$coin_pay_order}";
} elseif($model == 'deposit') {
$unionSql = "{$offcialData}";
} elseif($model == 'game_supersign') {
$unionSql = "{$superSignData}";
}
$sql = "select sum(pay_amount) as pay_amount,pay_way from ({$unionSql})t group by pay_way;";
$sumData = M()->query($sql);
$sumAllData['pay_amount'] = 0;
$sumAllData['platform_amount'] = 0;
if ($model == 'spend') {
$sumAllData['platform_amount'] = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->where($coinMap)
->sum('tab_deposit.pay_amount');
}
$sumAllData['platform_amount'] = $sumAllData['platform_amount']?$sumAllData['platform_amount']:0;
foreach ($sumData as $key => $value) {
if ($value['pay_way']>=1) {
if($model == 'deposit'||$model == 'coin_pay_order') {
$sumAllData['platform_amount'] += $value['pay_amount'];
} else {
$sumAllData['pay_amount'] += $value['pay_amount'];
}
}
}
$sumAllData['sum'] = $sumAllData['bind_amount']+$sumAllData['platform_amount']+$sumAllData['pay_amount'];
$sumDatas['pay_order_number'] = "总计";
$sumDatas['pay_time'] = "累计充值:{$sumAllData['sum']} 现金:{$sumAllData['pay_amount']} 平台币:{$sumAllData['platform_amount']}";
mb_convert_variables('GBK', 'UTF-8',$sumDatas);
fputcsv($fp, $sumDatas);
exit();
}
public function testDetail($p=1) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map = [];
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
}
if (!empty($_REQUEST['pay_order_number'])) {
$map['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
}
if (!empty($_REQUEST['order_number'])) {
$map['order_number'] = array('like',"{$_REQUEST['order_number']}%");
}
if (!empty($_REQUEST['user_account'])) {
$map['user_account'] = array('like',"{$_REQUEST['user_account']}%");
}
$map['pay_status'] = $coinMap['tab_deposit.pay_status'] = 1;
$map['pay_way'] = array('egt',1);
$model = $_REQUEST['model']?$_REQUEST['model']:'spend';
$data = [];
if ($model == 'spend') {
if ($_REQUEST['game_id']) {
$map['game_id'] = $_REQUEST['game_id'];
}
// setPowerPromoteIds($map,'promote_id');
$data = M('spend','tab_')
->field("pay_order_number,order_number,user_account,pay_time,game_name,server_name,game_player_name,cost,pay_amount,pay_way as pay_type,pay_way,pay_game_status")
->join('inner join tab_test_white_list on tab_spend.user_id=tab_test_white_list.user_id')
->where($map)
// ->order('tab_spend.id DESC')
->select(false);
if ($map['user_account']) {
$map['tab_deposit.user_account'] = $map['user_account'];
}
$coinMap = $map;
$coinMap['tab_deposit.pay_status'] = 1;
$coinMap['tab_deposit.pay_way'] = $map['pay_way'];
unset($coinMap['pay_status']);
unset($coinMap['pay_way']);
if ($map['pay_time']) {
$coinMap['tab_deposit.create_time'] = $map['pay_time'];
unset($coinMap['pay_time']);
}
// unset($coinMap['promote_id']);
// setPowerPromoteIds($coinMap,'tab_deposit.promote_id');
$coinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("pay_order_number,tab_deposit.order_number,tab_deposit.user_account,tab_deposit.create_time as pay_time,
tab_pay_info.game_name,tab_pay_info.server_name,tab_pay_info.game_player_name,tab_deposit.pay_amount as cost,
tab_deposit.pay_amount,tab_deposit.pay_way as pay_type,tab_deposit.pay_way,'' as pay_game_status")
->where($coinMap)
->select(false);
$page = ($page-1) * $row;
$count = "select count(*) as count from ({$data} UNION ALL {$coinData})t;";
$data = "select * from ({$data} UNION ALL {$coinData})t limit {$page},{$row};";
$data = M()->query($data);
$count = M()->query($count);
$count = $count[0]['count'];
foreach ($data as $key => $value) {
if(!$value['order_number']) {
$data[$key]['order_number'] = '无';
}
$data[$key]['pay_time'] = Date('Y-m-d H:i:s',$value['pay_time']);
$data[$key]['pay_type'] = get_pay_way($value['pay_type']);
if ($value['pay_way']==1 || $value['pay_way']==9 ) {
$data[$key]['pay_way'] = '支付宝';
} else if ($value['pay_way']==2 || $value['pay_way']==3 ) {
$data[$key]['pay_way'] = '微信支付';
} else if ($value['pay_way']==15) {
$data[$key]['pay_way'] = '快捷支付';
} else if($value['pay_way']){
$data[$key]['pay_way'] = '其他支付';
}
if ($value['pay_game_status'] == '0') {
$data[$key]['pay_game_status'] = '失败';
} else if ($value['pay_game_status'] == 1) {
$data[$key]['pay_game_status'] = '成功';
} else if ($value['pay_game_status'] == 2) {
$data[$key]['pay_game_status'] = '已退款';
} else if (!$value['pay_game_status']) {
$data[$key]['pay_game_status'] = '无';
}
}
$field = "sum(cost) as cost,sum(pay_amount) as pay_amount,pay_way";
$coinDataSum = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("sum(tab_deposit.pay_amount) as cost,sum(tab_deposit.pay_amount) as pay_amount,tab_deposit.pay_way")
->where($coinMap)
->find();
$coinDataSumSql = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("sum(tab_deposit.pay_amount) as cost,sum(tab_deposit.pay_amount) as pay_amount,tab_deposit.pay_way")
->where($coinMap)
->group('pay_way')
->select(false);
} elseif($model == 'game_supersign') {
if ($map['pay_order_number']) {
$map['order_id'] = $map['pay_order_number'];
unset($map['pay_order_number']);
}
if ($map['user_account']) {
$map['account'] = $map['user_account'];
unset($map['user_account']);
}
if ($_REQUEST['game_id']) {
$map['game_id'] = $_REQUEST['game_id'];
}
$map['tab_game_supersign.pay_status'] = $map['pay_status'];
unset($map['pay_status']);
$data = M('game_supersign','tab_')
->field("order_id as pay_order_number,trade_id as order_number,account as user_account,pay_time,game_name,pay_price as cost,pay_price as pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_game_supersign.user_id=tab_test_white_list.user_id')
->join('left join tab_game on tab_game_supersign.game_id= tab_game.id')
->page($page, $row)
->where($map)
->order('tab_game_supersign.id DESC')
->select();
foreach($data as $key => $value) {
$data[$key]['pay_time'] = Date('Y-m-d H:i:s',$value['pay_time']);
$data[$key]['pay_type'] = get_pay_way($value['pay_type']);
if ($value['pay_way']==1 || $value['pay_way']==9 ) {
$data[$key]['pay_way'] = '支付宝';
} else if ($value['pay_way']==2 || $value['pay_way']==3 ) {
$data[$key]['pay_way'] = '微信支付';
} else if ($value['pay_way']==15) {
$data[$key]['pay_way'] = '快捷支付';
} else if($value['pay_way']){
$data[$key]['pay_way'] = '其他支付';
}
}
$count = M('game_supersign','tab_')
->field("order_id as pay_order_number,trade_id as order_number,account as user_account,pay_time,game_name,pay_price as cost,pay_price as pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_game_supersign.user_id=tab_test_white_list.user_id')
->join('left join tab_game on tab_game_supersign.game_id= tab_game.id')
->where($map)
->order('tab_game_supersign.id DESC')
->count();
$field = "sum(pay_price) as cost,sum(pay_price) as pay_amount,pay_way";
} elseif($model == 'deposit') {
$map['pay_source'] = 0;
if ($map['pay_time']) {
$map['create_time'] = $map['pay_time'];
unset($map['pay_time']);
}
// setPowerPromoteIds($map,'tab_deposit.promote_id');
$data = M('deposit','tab_')
->field("pay_order_number,order_number,user_account,create_time as pay_time,pay_amount as cost,pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_deposit.user_id=tab_test_white_list.user_id')
->where($map)
->page($page, $row)
->order('tab_deposit.id DESC')
->select();
foreach($data as $key => $value) {
$data[$key]['pay_time'] = Date('Y-m-d H:i:s',$value['pay_time']);
$data[$key]['pay_type'] = get_pay_way($value['pay_type']);
if ($value['pay_way']==1 || $value['pay_way']==9 ) {
$data[$key]['pay_way'] = '支付宝';
} else if ($value['pay_way']==2 || $value['pay_way']==3 ) {
$data[$key]['pay_way'] = '微信支付';
} else if ($value['pay_way']==15) {
$data[$key]['pay_way'] = '快捷支付';
} else if($value['pay_way']){
$data[$key]['pay_way'] = '其他支付';
}
}
$count = M('deposit','tab_')
->field("pay_order_number,order_number,user_account,create_time as pay_time,pay_amount as cost,pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_deposit.user_id=tab_test_white_list.user_id')
->where($map)
->order('tab_deposit.id DESC')
->count();
$field = "sum(pay_amount) as cost,sum(pay_amount) as pay_amount,pay_way";
}
$sumAllData = M($model,'tab_')
->field($field)
->join('inner join tab_test_white_list on tab_'.$model.'.user_id=tab_test_white_list.user_id')
->where($map)
->find();
$sumData = M($model,'tab_')
->field($field)
->join('inner join tab_test_white_list on tab_'.$model.'.user_id=tab_test_white_list.user_id')
->where($map)
->group('pay_way')
->select(false);
if ($model == 'spend') {
$sumData = "{$sumData} union all {$coinDataSumSql}";
$sumAllData['pay_amount'] += $coinDataSum['pay_amount'];
$sumAllData['cost'] += $coinDataSum['cost'];
}
$this->assign('sumAllData',$sumAllData);
$sumData = "select cost,sum(pay_amount) as pay_amount,pay_way from ({$sumData})t group by pay_way";
$sumData = M()->query($sumData);
$payTypeData['支付宝支付金额'] = 0;
$payTypeData['微信支付金额'] = 0;
$payTypeData['快捷支付金额'] = 0;
$payTypeData['其他支付金额'] = 0;
foreach($sumData as $key => $value) {
if ($value['pay_way']==1 || $value['pay_way']==9 ) {
$payTypeData['支付宝支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if ($value['pay_way']==2 || $value['pay_way']==3 ) {
$payTypeData['微信支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if ($value['pay_way']==15) {
$payTypeData['快捷支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if($value['pay_way']){
$payTypeData['其他支付金额'] += number_format($value['pay_amount'],2,'.','');
}
}
$this->assign('payTypeData',$payTypeData);
foreach($sumData as $key=>$value) {
$sumData[$key]['pay_amount'] = number_format($value['pay_amount'],2,'.','');
$sumData[$key]['pay_way'] = get_pay_way($value['pay_way']);
if (!$value['pay_way']) {
unset($sumData[$key]);
}
}
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$this->meta_title = "测试统计";
$this->assign('sumData',$sumData);
$this->assign('data',$data);
$this->display();
}
public function export_testDetail() {
$xlsName = $_REQUEST['xlsname'];
$map = [];
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['pay_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
}
if (!empty($_REQUEST['pay_order_number'])) {
$map['pay_order_number'] = array('like',"{$_REQUEST['pay_order_number']}%");
}
if (!empty($_REQUEST['order_number'])) {
$map['order_number'] = array('like',"{$_REQUEST['order_number']}%");
}
if (!empty($_REQUEST['user_account'])) {
$map['user_account'] = array('like',"{$_REQUEST['user_account']}%");
}
$map['pay_status'] = $coinMap['tab_deposit.pay_status'] = 1;
$map['pay_way'] = array('egt',1);
$model = $_REQUEST['model']?$_REQUEST['model']:'spend';
$data = [];
$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流
$perSize = 50000;//每次查询的条数
if ($model == 'spend') {
$xlsCell = array('支付订单号', 'cp订单号', '测试账号', '充值时间', '游戏名称', '游戏区服',
'角色名称', '订单金额', ' 实付金额 ', '充值方式', '支付渠道', '游戏通知状态',);
mb_convert_variables('GBK', 'UTF-8', $xlsCell);
fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
if ($_REQUEST['game_id']) {
$map['game_id'] = $_REQUEST['game_id'];
}
// setPowerPromoteIds($map,'promote_id');
$data = M('spend','tab_')
->field("pay_order_number,order_number,user_account,pay_time,game_name,server_name,game_player_name,cost,pay_amount,pay_way as pay_type,pay_way,pay_game_status")
->join('inner join tab_test_white_list on tab_spend.user_id=tab_test_white_list.user_id')
->where($map)
// ->order('tab_spend.id DESC')
->select(false);
if ($map['user_account']) {
$map['tab_deposit.user_account'] = $map['user_account'];
}
$coinMap = $map;
$coinMap['tab_deposit.pay_status'] = 1;
$coinMap['tab_deposit.pay_way'] = $map['pay_way'];
unset($coinMap['pay_status']);
unset($coinMap['pay_way']);
if($map['pay_time']) {
$coinMap['tab_deposit.create_time'] = $map['pay_time'];
unset($coinMap['pay_time']);
}
// unset($coinMap['promote_id']);
// setPowerPromoteIds($coinMap,'tab_deposit.promote_id');
$coinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("pay_order_number,tab_deposit.order_number,tab_deposit.user_account,tab_deposit.create_time as pay_time,
tab_pay_info.game_name,tab_pay_info.server_name,tab_pay_info.game_player_name,tab_deposit.pay_amount as cost,
tab_deposit.pay_amount,tab_deposit.pay_way as pay_type,tab_deposit.pay_way,'' as pay_game_status")
->where($coinMap)
->select(false);
$count = "select count(*) as count from ({$data} UNION ALL {$coinData})t;";
$count = M()->query($count);
$accessNum = $count[0]['count'];
$pages = ceil($accessNum / $perSize);
for($i = 1; $i <= $pages; $i++) {
$page = ($i - 1) * $perSize;
$data = "select * from ({$data} UNION ALL {$coinData})t limit {$page},{$perSize};";
$data = M()->query($data);
foreach ($data as $key => $value) {
$value['pay_order_number'] = "'".$value['pay_order_number'];
$value['order_number'] = "'".$value['order_number'];
if (!$value['order_number']) {
$data[$key]['order_number'] = '无';
}
$value['pay_time'] = Date('Y-m-d H:i:s', $value['pay_time']);
$value['pay_type'] = get_pay_way($value['pay_type']);
if ($value['pay_way'] == 1 || $value['pay_way'] == 9) {
$value['pay_way'] = '支付宝';
} else if ($value['pay_way'] == 2 || $value['pay_way'] == 3) {
$value['pay_way'] = '微信支付';
} else if ($value['pay_way'] == 15) {
$value['pay_way'] = '快捷支付';
} else if ($value['pay_way']) {
$value['pay_way'] = '其他支付';
}
if ($value['pay_game_status'] == '0') {
$value['pay_game_status'] = '失败';
} else if ($value['pay_game_status'] == 1) {
$value['pay_game_status'] = '成功';
} else if ($value['pay_game_status'] == 2) {
$value['pay_game_status'] = '已退款';
} else if (!$value['pay_game_status']) {
$value['pay_game_status'] = '无';
}
mb_convert_variables('GBK', 'UTF-8', $value);
fputcsv($fp, $value);
}
unset($data);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
$field = "sum(cost) as cost,sum(pay_amount) as pay_amount,pay_way";
$coinDataSum = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("sum(tab_deposit.pay_amount) as cost,sum(tab_deposit.pay_amount) as pay_amount,tab_deposit.pay_way")
->where($coinMap)
->find();
$coinDataSumSql = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("inner join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->field("sum(tab_deposit.pay_amount) as cost,sum(tab_deposit.pay_amount) as pay_amount,tab_deposit.pay_way")
->where($coinMap)
->group('pay_way')
->select(false);
} elseif($model == 'game_supersign') {
$xlsCell = array('支付订单号', '测试账号', '充值时间', '游戏名称',
'订单金额', ' 实付金额 ', '充值方式', '支付渠道',);
mb_convert_variables('GBK', 'UTF-8', $xlsCell);
fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
if ($map['pay_order_number']) {
$map['order_id'] = $map['pay_order_number'];
unset($map['pay_order_number']);
}
if ($map['user_account']) {
$map['account'] = $map['user_account'];
unset($map['user_account']);
}
if ($_REQUEST['game_id']) {
$map['game_id'] = $_REQUEST['game_id'];
}
$map['tab_game_supersign.pay_status'] = $map['pay_status'];
unset($map['pay_status']);
$accessNum = M('game_supersign','tab_')
->field("order_id as pay_order_number,trade_id as order_number,account as user_account,pay_time,game_name,pay_price as cost,pay_price as pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_game_supersign.user_id=tab_test_white_list.user_id')
->join('left join tab_game on tab_game_supersign.game_id= tab_game.id')
->where($map)
->order('tab_game_supersign.id DESC')
->count();
$pages = ceil($accessNum / $perSize);
for($i = 1; $i <= $pages; $i++) {
$page = ($i - 1) * $perSize;
$data = M('game_supersign', 'tab_')
->field("order_id as pay_order_number,account as user_account,pay_time,game_name,pay_price as cost,pay_price as pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_game_supersign.user_id=tab_test_white_list.user_id')
->join('left join tab_game on tab_game_supersign.game_id= tab_game.id')
->where($map)
->limit($page ,$perSize)
->order('tab_game_supersign.id DESC')
->select();
foreach ($data as $key => $value) {
$value['pay_order_number'] = "'".$value['pay_order_number'];
$value['pay_time'] = Date('Y-m-d H:i:s', $value['pay_time']);
$value['pay_type'] = get_pay_way($value['pay_type']);
if ($value['pay_way'] == 1 || $value['pay_way'] == 9) {
$value['pay_way'] = '支付宝';
} else if ($value['pay_way'] == 2 || $value['pay_way'] == 3) {
$value['pay_way'] = '微信支付';
} else if ($value['pay_way'] == 15) {
$value['pay_way'] = '快捷支付';
} else if ($value['pay_way']) {
$value['pay_way'] = '其他支付';
}
mb_convert_variables('GBK', 'UTF-8', $value);
fputcsv($fp, $value);
}
unset($data);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
$field = "pay_price as cost,sum(pay_price) as pay_amount,pay_way";
} elseif($model == 'deposit') {
$xlsCell = array('支付订单号', 'cp订单号', '测试账号', '充值时间', '订单金额', ' 实付金额 ', '充值方式', '支付渠道');
mb_convert_variables('GBK', 'UTF-8', $xlsCell);
fputcsv($fp, $xlsCell);//将数据格式化为CSV格式并写入到output流中
$map['pay_source'] = 0;
if ($map['pay_time']) {
$map['create_time'] = $map['pay_time'];
unset($map['pay_time']);
}
// setPowerPromoteIds($map,'tab_deposit.promote_id');
$accessNum = M('deposit','tab_')
->field("pay_order_number,order_number,user_account,create_time as pay_time,pay_amount as cost,pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_deposit.user_id=tab_test_white_list.user_id')
->where($map)
->order('tab_deposit.id DESC')
->count();
$pages = ceil($accessNum / $perSize);
for($i = 1; $i <= $pages; $i++) {
$page = ($i - 1) * $perSize;
$data = M('deposit', 'tab_')
->field("pay_order_number,order_number,user_account,create_time as pay_time,pay_amount as cost,pay_amount,pay_way as pay_type,pay_way")
->join('inner join tab_test_white_list on tab_deposit.user_id=tab_test_white_list.user_id')
->where($map)
->limit($page ,$perSize)
->order('tab_deposit.id DESC')
->select();
foreach ($data as $key => $value) {
$value['pay_order_number'] = "'".$value['pay_order_number'];
$value['order_number'] = "'".$value['order_number'];
$value['pay_time'] = Date('Y-m-d H:i:s', $value['pay_time']);
$value['pay_type'] = get_pay_way($value['pay_type']);
if ($value['pay_way'] == 1 || $value['pay_way'] == 9) {
$value['pay_way'] = '支付宝';
} else if ($value['pay_way'] == 2 || $value['pay_way'] == 3) {
$value['pay_way'] = '微信支付';
} else if ($value['pay_way'] == 15) {
$value['pay_way'] = '快捷支付';
} else if ($value['pay_way']) {
$value['pay_way'] = '其他支付';
}
mb_convert_variables('GBK', 'UTF-8', $value);
fputcsv($fp, $value);
}
unset($data);//释放变量的内存
//刷新输出缓冲到浏览器
ob_flush();
flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。
}
$field = "pay_amount as cost,sum(pay_amount) as pay_amount,pay_way";
}
$sumAllData = M($model,'tab_')
->field($field)
->join('inner join tab_test_white_list on tab_'.$model.'.user_id=tab_test_white_list.user_id')
->where($map)
->find();
$sumData = M($model,'tab_')
->field($field)
->join('inner join tab_test_white_list on tab_'.$model.'.user_id=tab_test_white_list.user_id')
->where($map)
->group('pay_way')
->select(false);
if ($model == 'spend') {
$sumData = "{$sumData} union all {$coinDataSumSql}";
$sumAllData['pay_amount'] += $coinDataSum['pay_amount'];
$sumAllData['cost'] += $coinDataSum['cost'];
}
$sumData = "select cost,sum(pay_amount) as pay_amount,pay_way from ({$sumData})t group by pay_way";
$sumData = M()->query($sumData);
$payTypeData['支付宝支付金额'] = 0;
$payTypeData['微信支付金额'] = 0;
$payTypeData['快捷支付金额'] = 0;
$payTypeData['其他支付金额'] = 0;
foreach($sumData as $key => $value) {
if ($value['pay_way']==1 || $value['pay_way']==9 ) {
$payTypeData['支付宝支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if ($value['pay_way']==2 || $value['pay_way']==3 ) {
$payTypeData['微信支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if ($value['pay_way']==15) {
$payTypeData['快捷支付金额'] += number_format($value['pay_amount'],2,'.','');
} else if($value['pay_way']){
$payTypeData['其他支付金额'] += number_format($value['pay_amount'],2,'.','');
}
}
foreach($sumData as $key=>$value) {
$sumData[$key]['pay_amount'] = number_format($value['pay_amount'],2,'.','');
$sumData[$key]['pay_way'] = get_pay_way($value['pay_way']);
if (!$value['pay_way']) {
unset($sumData[$key]);
}
}
//总计
if ($model == 'spend') {
$sumAllDataother['pay_order_number'] = '总计';
$sumAllDataother['order_number'] = '------';
$sumAllDataother['user_account'] = '------';
$sumAllDataother['pay_time'] = '------';
$sumAllDataother['game_name'] = '------';
$sumAllDataother['server_name'] = '------';
$sumAllDataother['game_player_name'] = '------';
$sumAllDataother['cost'] = $sumAllData['cost'];
$sumAllDataother['pay_amount'] = $sumAllData['pay_amount'];
$sumAllDataother['pay_type'] = '------';
$sumAllDataother['pay_way'] = '------';
$sumAllDataother['pay_game_status'] = '------';
} elseif($model == 'game_supersign') {
$sumAllDataother['pay_order_number'] = '总计';
$sumAllDataother['user_account'] = '------';
$sumAllDataother['pay_time'] = '------';
$sumAllDataother['game_name'] = '------';
$sumAllDataother['cost'] = $sumAllData['cost'];
$sumAllDataother['pay_amount'] = $sumAllData['pay_amount'];
$sumAllDataother['pay_type'] = '------';
$sumAllDataother['pay_way'] = '------';
} elseif($model == 'deposit') {
$sumAllDataother['pay_order_number'] = '总计';
$sumAllDataother['order_number'] = '------';
$sumAllDataother['user_account'] = '------';
$sumAllDataother['pay_time'] = '------';
$sumAllDataother['cost'] = $sumAllData['cost'];
$sumAllDataother['pay_amount'] = $sumAllData['pay_amount'];
$sumAllDataother['pay_type'] = '------';
$sumAllDataother['pay_way'] = '------';
}
mb_convert_variables('GBK', 'UTF-8',$sumAllDataother);
fputcsv($fp, $sumAllDataother);
$sumAllDataPay['pay_order_number'] = '充值方式合计';
$sumAllDataPay['order_number'] = '';
//支付渠道合计
foreach ($payTypeData as $key => $value) {
$sumAllDataPay['order_number'] .= $key.''.$value.' ';
}
mb_convert_variables('GBK', 'UTF-8',$sumAllDataPay);
fputcsv($fp, $sumAllDataPay);
//支付渠道
$sumDataPay['pay_order_number'] = '支付渠道';
$sumDataPay['order_number'] = '';
foreach ($sumData as $key => $value) {
$sumDataPay['order_number'] .= $value['pay_way'].''.$value['pay_amount'].' ';
}
mb_convert_variables('GBK', 'UTF-8',$sumDataPay);
fputcsv($fp, $sumDataPay);
}
function getGameList() {
if (I('partner_id')) {
$map['partner_id'] = I('partner_id');
}
if (I('sdk_type')) {
$map['sdk_version'] = I('sdk_type');
}
$data = M('game','tab_')->field("id,game_name")->where($map)->select();
$this->ajaxReturn($data,'json');
}
}