<?php
namespace Admin\Controller;
class FinancePromoteController extends AdminController
{
public function _initialize(Type $var = null)
{
parent::_initialize();
// echo "< pre > ";
}
public function index($p=1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
//排序
if(!array_key_exists("time_start",$_REQUEST)){
$this->redirect(ACTION_NAME, array('time_start' => date('Y-m-d',strtotime('-30 day')),"time_end"=>date('Y-m-d')));
}
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);
}
//时间
$istimeselect = false;
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$istimeselect = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$istimeselect = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$istimeselect = ['LT', strtotime($_REQUEST['time_end']) + 86399];
}
$senddata = [];
//获取各会长的充值方式
$cash = self::getJoinPromoteData([],$istimeselect);
foreach($cash as $k=>$v){
$senddata[$v['p_id']] = $v;
}
//内冲
$inside = self::getJoinPromoteData([],$istimeselect,"promote_coin");
foreach($inside as $k=>$v){
if(array_key_exists($v['p_id'],$senddata)){
$senddata[$v['p_id']]['inside_cash_count']= $v['pay_amount']-$v['back_amount'];
}else{
$v['inside_cash_count'] = $v['pay_amount']-$v['back_amount'];
unset($v['pay_amount']);
unset($v['back_amount']);
$senddata[$v['p_id']] = $v;
};
}
if(array_key_exists(0,$senddata) || $_REQUEST['promote_id']==0){
$pmap['status']=1;
if($istimeselect){
$pmap['create_time'] = $istimeselect;
}
$admininside = M("provide_user p","tab_")->field("sum(amount) amount")->where($pmap)->find();
if($admininside['amount'] >0){
$senddata[0]['inside_cash_count']= $admininside['amount'];
}
}
$data = [];
$count =array(
"cash_count"=>0,
"balance_coin_count"=>0,
"bind_coin_count"=>0,
"inside_cash_count"=>0,
);
foreach($senddata as $k=>$v){
if(empty($v['company_name'])) $v['company_name']= "万盟天下科技";
if(!array_key_exists('cash_count',$v)) $v['cash_count']=0;
if(!array_key_exists('balance_coin_count',$v)) $v['balance_coin_count']=0;
if(!array_key_exists('bind_coin_count',$v)) $v['bind_coin_count']=0;
if(!array_key_exists('inside_cash_count',$v)) $v['inside_cash_count']=0;
$v['promote_account'] = get_promote_name($v['p_id']);
$v['allcount'] = $v['cash_count']-0+$v['balance_coin_count']+$v['bind_coin_count'];
$count['cash_count'] += $v['cash_count'];
$count['balance_coin_count'] += $v['balance_coin_count'];
$count['bind_coin_count'] += $v['bind_coin_count'];
$count['inside_cash_count'] += $v['inside_cash_count'];
$count['all_count'] += $v['allcount'];
$data[] = $v;
}
$data = my_sort($data, $data_order_type, (int)$data_order);
if(isset($_REQUEST['export'])){
data2csv($data,'公会统计',array(
"company_name"=>"推广公司",
"promote_account"=>"会长渠道",
"cash_count"=>"游戏现金金额",
"balance_coin_count"=>"平台币直充支出",
"bind_coin_count"=>"内充支出",
"inside_cash_count"=>"平台币内充",
"allcount"=>"渠道游戏内充值合计"
));
}
$pagecount = count($data);
$page = set_pagination($pagecount, $row);
if ($page) {
$this->assign('_page', $page);
}
$size = $row;
$data = array_slice($data, ($arraypage - 1) * $size, $size);
$this->assign('list_data', $data);
$this->assign('all_count', $count);
$this->meta_title = '公会统计';
$this->display();
# code...
}
private function getJoinPromoteData($map,$istimeselect,$type="spend")
{
// setPowerPromoteIds($map,"s.promote_id");
if ($_REQUEST['promote_id'] != '') {
if ($_REQUEST['promote_id'] == 0) {
$map['s.promote_id'] = 0;
} else {
$promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select();
if ($promoter_ids) {
$map['s.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))];
}
}
}
if($type == "spend"){
if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type'])) {
$map["s.game_id"] = array("in",implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) );
}
if($istimeselect){
$map['s.pay_time']=$istimeselect;
}
$map['s.pay_status']=1;
$field= "SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count,
SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as bind_coin_count,
IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id,
IFNULL(company_id,0) company_id,company_name";
return M()
->table("tab_spend s")
->field($field)
->where($map)
->join("tab_promote promote ON s.promote_id = promote.id","left")
->join("tab_promote_company company ON promote.company_id = company.id","left")
->group('p_id')
->select();
}else{
if($istimeselect){
$map['s.create_time']=$istimeselect;
}
$map['s.status']=1;
$map['s.source_id']=0;
$field= "SUM(CASE WHEN s.type = 1 THEN num ELSE 0 END) as pay_amount,SUM(CASE WHEN s.type = 2 THEN num ELSE 0 END) as back_amount,IFNULL(if(substring_index(substring_index(`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(`chain`,'/',2),'/',-1)),0) p_id";
return M("promote_coin s","tab_")
->field($field)
->where($map)
->join("tab_promote promote ON s.promote_id = promote.id","left")
->group('p_id')
->select();
}
}
//渠道查看
public function promoteUser($p = 0)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$istimeselect = false;
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$istimeselect = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$istimeselect = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$istimeselect = ['LT', strtotime($_REQUEST['time_end']) + 86399];
}
$senddata = [];
//获取各会长的现金充值
$cash = self::promoteUserData([],$istimeselect);
foreach($cash as $k=>$v){
$senddata[$v['promote_id']] = $v;
}
$inside = self::promoteUserData([],$istimeselect,"promote_coin");
foreach($inside as $k=>$v){
if(array_key_exists($v['promote_id'],$senddata)){
$senddata[$v['promote_id']]['inside_cash_count']= $v['pay_amount'];
}else{
$v['inside_cash_count'] = $v['pay_amount'];
unset($v['pay_amount']);
$senddata[$v['promote_id']] = $v;
};
}
if(array_key_exists(0,$senddata) || $_REQUEST['promote_id']==0){
$pmap['status']=1;
if($istimeselect){
$pmap['create_time'] = $istimeselect;
}
$admininside = M("provide_user p","tab_")->field("sum(amount) amount")->where($pmap)->find();
if($admininside['amount'] >0){
$senddata[0]['inside_cash_count']= $admininside['amount'];
}
}
$count = count($senddata);
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);
}
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$data = [];
$allcount =array(
"cash_count"=>0,
"balance_coin_count"=>0,
"bind_coin_count"=>0,
"inside_cash_count"=>0,
);
foreach($senddata as $k=>$v){
if(empty($v['company_name'])) $v['company_name']= "万盟天下科技";
if(empty($v['promote_account'])) $v['promote_account']= "官方渠道";
if(!array_key_exists('cash_count',$v)) $v['cash_count']=0;
if(!array_key_exists('balance_coin_count',$v)) $v['balance_coin_count']=0;
if(!array_key_exists('bind_coin_count',$v)) $v['bind_coin_count']=0;
if(!array_key_exists('inside_cash_count',$v)) $v['inside_cash_count']=0;
$v['allcount'] = $v['cash_count']-0+$v['balance_coin_count']+$v['bind_coin_count'];
$allcount['cash_count'] += $v['cash_count'];
$allcount['balance_coin_count'] += $v['balance_coin_count'];
$allcount['bind_coin_count'] += $v['bind_coin_count'];
$allcount['inside_cash_count'] += $v['inside_cash_count'];
$allcount['all_count'] += $v['allcount'];
$data[] = $v;
}
$data = my_sort($data, $data_order_type, (int)$data_order);
if(isset($_REQUEST['export'])){
data2csv($data,'渠道统计',array(
"company_name"=>"推广公司",
"promote_account"=>"推广员账号",
"cash_count"=>"游戏现金金额",
"balance_coin_count"=>"平台币直充支出",
"bind_coin_count"=>"内充支出",
"inside_cash_count"=>"平台币内充",
"allcount"=>"渠道游戏内充值合计"
));
}
$size = $row;
$data = array_slice($data, ($arraypage - 1) * $size, $size);
$this->assign('all_count', $allcount);
$this->assign('list_data', $data);
$this->meta_title = '渠道统计';
$this->display();
// dump($senddata);
}
private function promoteUserData($map,$istimeselect,$type="spend")
{
// setPowerPromoteIds($map,"s.promote_id");
if ($_REQUEST['promote_id'] != '') {
if ($_REQUEST['promote_id'] == 0) {
$map['s.promote_id'] = 0;
} else {
$promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select();
if ($promoter_ids) {
$map['s.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))];
}
}
}
if ($type == "spend") {
if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type'])) {
$map["s.game_id"] = array("in",implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) );
}
if($istimeselect){
$map['s.pay_time']=$istimeselect;
}
$map['s.pay_status']=1;
$field= "SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count,
SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as bind_coin_count,
IFNULL(company_id,0) company_id,company_name,promote_id,promote.account promote_account";
return M()
->table("tab_spend s")
->field($field)
->where($map)
->join("tab_promote promote ON s.promote_id = promote.id", "left")
->join("tab_promote_company company ON promote.company_id = company.id", "left")
->group('promote_id')
->select();
}else{
if($istimeselect){
$map['s.create_time']=$istimeselect;
}
$map['s.status']=1;
$map['s.source_id']=0;
$map['s.type']=1;
$field= "sum(num) pay_amount,promote_id";
return M("promote_coin s","tab_")
->field($field)
->where($map)
->join("tab_promote promote ON s.promote_id = promote.id","left")
->group('promote_id')
->select();
}
# code...
}
/**
*游戏统计
*/
public function gameStatistics($p = 1) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row = $_REQUEST['row'] ?? 10;
$map = [];
if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type'])) {
$map["s.game_id"] = array("in",implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) );
}
if (!empty(I('partner_id'))) {
$map['g.partner_id'] = I('partner_id');
}
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$map['s.pay_time'] = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$map['s.pay_time'] = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$map['s.pay_time'] = ['LT', strtotime($_REQUEST['time_end']) + 86399];
}
//判断是否有推广员
$level = 1;
if ($_REQUEST['promote_id'] != '') {
if ($_REQUEST['promote_id'] != 0){
$level = M('promote', 'tab_')->field('level')->where(array('id' => $_REQUEST['promote_id']))->find()['level'];
}
if ($_REQUEST['promote_id'] == 0 || $_REQUEST['promote_type'] == 2) {
$map['s.promote_id'] = $_REQUEST['promote_id'];
} else {
$promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select();
if ($promoter_ids) {
$map['s.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))];
}
}
}
$this->assign('promote_level', $level);
//游戏统计列表
$data =self::gameStatisticsData($map, $row, $p);
if(isset($_REQUEST['export'])){
$data =self::gameStatisticsData($map);
}else {
$data =self::gameStatisticsData($map, $row, $p);
}
foreach ($data as $key => & $value) {
$value['cash_count']?:0;
$value['balance_coin_count']?:0;
$value['inside_cash_count']?:0;
$value['all_cash_count'] = $value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count'];
if(!$value['partner_name']) $value['partner_name'] = "无";
if(!$value['game_name']) $value['game_name'] = "无";
}
if (isset($_REQUEST['export'])) {
data2csv($data,'游戏统计', array(
"partner_name"=>"合作公司",
"game_name"=>"游戏",
"cash_count"=>"游戏现金金额",
"balance_coin_count"=>"平台币直充支出",
"inside_cash_count"=>"内充支出",
"all_cash_count"=>"游戏内充值合计"
));
}
$allData = self::gameStatisticsData($map);//列表总数
$count = count($allData);
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);//分页
}
//统计合计
$totalData = self::totalGameStatisticsData($map);
$sumCash = $totalData['cash_count'];
$sumBalance = $totalData['balance_coin_count'];
$sumInside = $totalData['inside_cash_count'];
$sumAll = $sumCash + $sumBalance + $sumInside;
$this->assign('sumCash', $sumCash);
$this->assign('sumBalance', $sumBalance);
$this->assign('sumInside', $sumInside);
$this->assign('sumAll', $sumAll);
$this->assign('data',$data);
$this->meta_title = '游戏统计';
$this->display();
}
//游戏订单详情
public function gameStatisticsDetail($p = 1) {
set_time_limit(0);
if(isset($_REQUEST['game_id'])){
//转化为名称和类型,重新请求
$game = M("game","tab_")->field("relation_game_name,sdk_version")->where(" id = {$_REQUEST['game_id']} ")->find();
if($game === false){
$this->error("参数错误");
}
$_GET['game_name'] = $game['relation_game_name'];
$_GET['game_type'] = $game['sdk_version'];
unset($_GET['game_id']);
$this->redirect(ACTION_NAME, I('get.'));
}
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 (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type']) || isset($_REQUEST['partner_id'])) {
$map["game_id"] = array("in",implode(',', array_column(getGameidByPartnerNameType($_REQUEST['partner_id'],$_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) );
}
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$map['pay_time'] = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$map['pay_time'] = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$map['pay_time'] = ['LT', strtotime($_REQUEST['time_end']) + 86399];
}
//判断是否有推广员
if ($_REQUEST['promote_id'] != '') {
if ($_REQUEST['promote_id'] == 0 || $_REQUEST['promote_type'] == 2) {
$map['promote_id'] = $_REQUEST['promote_id'];
} else {
$promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select();
if ($promoter_ids) {
$map['promote_id'] = ['in', implode(',', array_column($promoter_ids, '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'];
}
$promote_id = implode(',',$promote_id);
if ($promote_id) {
$map['promote_id'] = ['in',$promote_id];
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$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['game_player_name'] = array('like',I("user_nickname").'%');
}
$field = "pay_order_number,FROM_UNIXTIME(pay_time) as pay_time,user_account,user_nickname,game_name,promote_account,spend_ip,server_name,game_player_name,pay_amount,cost,pay_way";
$group = "";
$order = "pay_time DESC";
if(isset($_REQUEST['export'])){
$data = D('spend')->getSpendData($map,$field,$group,$order);
}else {
$data = D('spend')->getSpendData($map,$field,$group,$order,$page,$row);
}
foreach($data as $key => $value) {
$data[$key]['pay_way'] = getPayType($value['pay_way']);
}
if (isset($_REQUEST['export'])) {
data2csv($data,'游戏订单查看', array(
"pay_order_number"=>"支付订单号",
"pay_time"=>"充值时间",
"user_account"=>"玩家账号",
"game_name"=>"游戏名称",
"promote_account"=>"所属推广员",
"spend_ip"=>"充值ip",
"server_name"=>"游戏区服",
"game_player_name"=>"角色名称",
"cost"=>"订单金额",
"pay_amount"=>"实付金额",
"pay_way"=>"充值方式",
));
}
$totalData = self::totalGameStatisticsData($map, false);
$sumCash = $totalData['cash_count'] ?? 0;
$sumBalance = $totalData['balance_coin_count'] ?? 0;
$sumInside = $totalData['inside_cash_count'] ?? 0;
$sumAll = $sumCash + $sumBalance + $sumInside;
$this->assign('sumCash', $sumCash);
$this->assign('sumBalance', $sumBalance);
$this->assign('sumInside', $sumInside);
$this->assign('sumAll', null_to_0($sumAll));
$count = D("spend")->getSpendData($map,$field,$group,$order);
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '游戏订单查看';
$this->assign('data',$data);
$from = I('from', '');
$this->display($from);
}
private function gameStatisticsData($map, $row = 0, $page = 1)
{
$map['s.pay_status']=1;
$query = M("spend","tab_")->alias("s")
->field("s.game_id,s.game_name,p.partner as partner_name,
SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count,
SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as inside_cash_count")
->join('LEFT JOIN tab_game as g ON s.game_id=g.id')
->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id')
->where($map)
->group('s.game_id');
if ($row != 0) {
$query = $query->page($page,$row);
}
$data = $query->select();
// dump($data);die();
return $data;
}
private function totalGameStatisticsData($map, $join = true)
{
$query = M("spend","tab_")->alias("s")
->field("SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END) as cash_count,
SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END) as balance_coin_count,
SUM(CASE WHEN pay_way = -1 THEN pay_amount ELSE 0 END) as inside_cash_count");
if ($join) {
$query = $query->join('LEFT JOIN tab_game as g ON s.game_id=g.id')
->join('LEFT JOIN tab_partner as p ON g.partner_id=p.id');
}
$data = $query->where(['s.pay_status' => 1])
->where($map)
->find();
return $data;
}
//游戏弹框详情
public function gameCoinDetail($p = 1) {
set_time_limit(0);
if (isset($_REQUEST['pay_way'])) {
$map['pay_way'] = $_REQUEST['pay_way'];
$this->assign('pay_way', $map['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['tab_spend.game_id'] = ['in',$gameId];
// }
if (!empty(I("game_id"))) {
$map['tab_spend.game_id'] = I("game_id");
}
if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type']) || isset($_REQUEST['partner_id'])) {
$map["tab_spend.game_id"] = array("in",implode(',', array_column(getGameidByPartnerNameType($_REQUEST['partner_id'],$_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) );
}
// if (isset($_REQUEST['game_name']) || isset($_REQUEST['game_type'])) {
// $map["tab_spend.game_id"] = array("in",implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) );
// }
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$map['pay_time'] = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$map['pay_time'] = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$map['pay_time'] = ['LT', strtotime($_REQUEST['time_end']) + 86399];
}
if ($_REQUEST['promote_id'] != '') {
if ($_REQUEST['promote_id'] == 0 || $_REQUEST['promote_type'] == 2) {
$map['tab_spend.promote_id'] = $_REQUEST['promote_id'];
} else {
$promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select();
if ($promoter_ids) {
$map['tab_spend.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))];
}
}
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map['pay_status'] = 1;
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) {//绑定币
$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) {//平台币
$field2 = $field . ',balance';
$join = 'left join tab_user as u on u.id = tab_spend.user_id';
}
if(isset($_REQUEST['export'])){
$data = D('spend')->getSpendData($map, $field2, $group, $order,0,0, $join);
}else {
$data = D('spend')->getSpendData($map, $field2, $group, $order, $page, $row, $join);
}
foreach($data as $key => $value) {
$data[$key]['pay_way'] = getPayType($value['pay_way']);
}
if (isset($_REQUEST['export'])) {
$field = array(
"pay_order_number"=>"支付订单号",
"pay_time"=>"充值时间",
"user_account"=>"玩家账号",
"game_name"=>"游戏名称",
"server_name"=>"游戏区服",
"game_player_name"=>"角色名称",
"cost"=>"订单金额",
"pay_amount"=>"实付金额",
"pay_way"=>"充值方式"
);
if ($map['pay_way'] ==-1) {
$field["bind_balance"] = "绑定币余额";
$title = "内充支出明细";
} elseif ($map['pay_way'] ==0) {
$field["balance"] = "平台币余额";
$title = "平台币直充明细";
}
data2csv($data,$title,$field);
}
$count = D("spend")->getSpendData($map,$field,$group,$order);
$count = count($count);
$page = set_pagination($count,$row);
// $map['pay_game_status'] = 1;
$total_cost = D('spend')->sumSpend($map, 'cost');//订单金额合计
$total_pay_amount = D('spend')->sumSpend($map, 'pay_amount');//实付金额合计
$this->assign('total_cost', $total_cost);
$this->assign('total_pay_amount', $total_pay_amount);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '游戏订单查看';
$this->assign('data',$data);
$this->display();
}
//平台币内充弹框
public function insideCoinDetail($p = 1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
//时间
$istimeselect = false;
if (isset($_REQUEST['time_start']) & & isset($_REQUEST['time_end'])) {
$istimeselect = ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]];
} elseif (isset($_REQUEST['time_start'])) {
$istimeselect = ['GT', strtotime($_REQUEST['time_start'])];
} elseif (isset($_REQUEST['time_end'])) {
$istimeselect = ['LT', strtotime($_REQUEST['time_end']) + 86399];
}
//是否是官方渠道
$isgf = false;
if ($_REQUEST['promote_id'] != '') {
if($_REQUEST['promote_id'] == 0){
$isgf = true;
}
$map['s.promote_id'] = $_REQUEST['promote_id'];
}
//检索
if (isset($_REQUEST['sn'])) {
$pmap['order_number'] = array("LIKE","%".$_REQUEST['sn']."%");
$map['sn'] = array("LIKE","%".$_REQUEST['sn']."%");
}
if (isset($_REQUEST['type'])) {
if($_REQUEST['type'] == 2){
$pmap['op_id'] =0;//肯定false
}
$map['s.type'] =$_REQUEST['type'];
}
//
$senddata = [];
$count =0;
$total_cost = 0;
if($isgf){
$pmap['status']=1;
if($istimeselect){
$pmap['create_time'] = $istimeselect;
}
$admincount = M("provide_user p","tab_")->field("sum(amount) amount,count(*) count")->where($pmap)->find();
$count = $admincount["count"]?:0;
$total_cost = $admincount["amount"]?:0;
if($count >0){
$admininside = M("provide_user p","tab_")
->field("order_number,user_account,amount,balance,create_time")
->join("left join tab_user as u on u.id = p.user_id")
->where($pmap);
if(isset($_REQUEST['export'])){
$admininside = $admininside->select();
}else {
$admininside = $admininside->page($page, $row)->select();
}
foreach ($admininside as $k => $v) {
$temp = [
"sn"=>$v['order_number'],
"op_type"=>"收入",
"op_sty"=>"后台发放玩家",
"account"=>"管理员",
"op_num"=>$v['amount'],
"balance_coin"=>$v['balance']?:'0.00',
"mark"=>"后台发放平台币",
"create_time"=>date("Y-m-d H:i:s",$v['create_time'])
];
$senddata[] = $temp;
}
}
}else{
if($istimeselect){
$map['s.create_time']=$istimeselect;
}
$map['s.status']=1;
$map['s.source_id']=0;
$ininsidecount = M("promote_coin s","tab_")
->field("SUM(CASE WHEN s.type = 1 THEN num ELSE 0 END) as pay_amount,SUM(CASE WHEN s.type = 2 THEN num ELSE 0 END) as back_amount,count(*) count")
->where($map)
->find();
$count = $ininsidecount["count"]?:0;
$total_cost = ($ininsidecount["pay_amount"]-$ininsidecount["back_amount"]);
if ($count >0) {
$field= "num,sn,promote.balance_coin,account,s.type,remark,s.create_time";
$ininside = M("promote_coin s", "tab_")
->field($field)
->where($map)
->join("tab_promote promote ON s.promote_id = promote.id", "left");
if(isset($_REQUEST['export'])){
$ininside = $ininside->select();
}else {
$ininside = $ininside->page($page, $row)->select();
}
foreach ($ininside as $k => $v) {
$temp = [
"sn"=>$v['sn'],
"op_type"=>($v['type'] == 1) ? "收入":"支出",
"op_sty"=>($v['type'] == 1) ? "后台发放":"后台回收",
"account"=>"管理员",
"op_num"=>$v['num']?:'0.00',
"balance_coin"=>$v['balance_coin'],
"mark"=>$v["remark"]?:"后台发放平台币",
"create_time"=>date("Y-m-d H:i:s",$v['create_time'])
];
$senddata[] = $temp;
}
}
}
//
if (isset($_REQUEST['export'])) {
$field = array(
"sn"=>"流水号",
"op_type"=>"操作类型",
"op_sty"=>"操作方式",
"account"=>"对手账号类型",
"op_num"=>"平台币数量",
"balance_coin"=>"平台币余额",
"mark"=>"交易说明",
"create_time"=>"交易时间"
);
data2csv($senddata,"平台币内充明细",$field);
}
$this->assign('total_cost', $total_cost);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->assign('data',$senddata);
$this->display();
}
}