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.

1728 lines
69 KiB
PHP

<?php
namespace Admin\Controller;
use OSS\Core\OssException;
use Base\Tool\AggregateClient;
class FinanceController extends ThinkController
{
function index($p = 1) {
//总流水查询
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
// var_dump($row);die();
$map = [];
if(!empty(I('count_date'))){
$map['count_date']=I('count_date');
}
// if (!empty(I('game_id'))) {
// $map['game_id']=I('game_id');
// }
// if (!empty(I('partner_id'))) {
// $map['partner_id']=I('collaborate_id');
// }
// $data = M("spend_count","tab_")
// ->field("count_date,cash_count,balance_coin_count,inside_cash_count,all_cash_count")
// ->where($map)
// ->page($page,$row)
// ->group("count_date")
// ->select();
// if (empty(I('game_id'))) {
// $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,
// sum(inside_cash_count) as inside_cash_count,sum(cash_count+balance_coin_count) as all_cash_count";
// $InsideField = "inside_cash_count";
// $map['inside_cash_count'] = ['neq',0];
// $insideData = D("spend_count")->getSpendCountData($map,"count_date,inside_cash_count as count","promote_id,count_date");
// unset($map['inside_cash_count']);
// } else {
// $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,
// sum(bind_coin_count) as inside_cash_count,sum(cash_count+balance_coin_count) as all_cash_count";
// $InsideField = "bind_coin_count";
// $map['bind_coin_count'] = ['neq',0];
// $insideData = D("spend_count")->getSpendCountData($map,"count_date,bind_coin_count as count","promote_id,count_date,game_id");
// unset($map['bind_coin_count']);
// }
// //内充流水与绑定流水数据
// $insideDataSum = [];
// foreach ($insideData as $key => $value) {
// if (isset($insideDataSum[$value['count_date']])) {
// $insideDataSum[$value['count_date']] = $insideDataSum[$value['count_date']] + $value['count'];
// } else {
// $insideDataSum[$value['count_date']] = $value['count'];
// }
// }
// var_dump($insideDataSum);
// var_dump(array_sum($insideDataSum));
// echo D("spend_count")->_sql();
// var_dump($insideData);die();
// $group = "count_date";
// $order = "id DESC";
// $data = D("spend_count")->getSpendCountData($map,$field,$group,$order,$page,$row);
//
// foreach ($data as $key => $value) {
// $data[$key]['all_cash_count'] = $value['all_cash_count'] + $insideDataSum[$value['count_date']];
// $data[$key]['inside_cash_count'] = $insideDataSum[$value['count_date']];
// }
//
// $sumCash = D("spend_count")->sumSpendCountField($map,"cash_count");
// $sumBalance = D("spend_count")->sumSpendCountField($map,"balance_coin_count");
// $sumInside = array_sum($insideDataSum);
// $allField = "cash_count+balance_coin_count";
// $sumAll = D("spend_count")->sumSpendCountField($map,$allField)+array_sum($insideDataSum);
//
// $count = D("spend_count")->getSpendCountData($map,$field,$group,'');
$order = "id DESC";
$data = M('spend_month_count','tab_')
->field("cash_count,balance_coin_count,inside_cash_count,all_count,count_date,balance_coin_deposit,bind_coin_count")
->where($map)
->page($page,$row)
->order($order)
->select();
$count = M('spend_month_count','tab_')
->field("cash_count,balance_coin_count,inside_cash_count,all_count,count_date")
->where($map)
->order($order)
->select();
$sumData = M('spend_month_count','tab_')
->field("sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,sum(inside_cash_count) as inside_cash_count,sum(all_count) as all_count,count_date,sum(balance_coin_deposit) as balance_coin_deposit,sum(bind_coin_count) as bind_coin_count")
->where($map)
->order($order)
->find();
// echo D("spend_count")->_sql();die();
$count = count($count);
$page = set_pagination($count,$row);
// var_dump($page);die();
if($page) {$this->assign('_page', $page);}
$this->meta_title = '月结统计';
// $this->assign('sumCash',$sumCash);
// $this->assign('sumBalance',$sumBalance);
// $this->assign('sumInside',$sumInside);
// $this->assign('sumAll',$sumAll);
$this->assign('sumData',$sumData);
$this->assign('data',$data);
$this->display();
}
function gameFinance($p = 1) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
}else{
$row = 10;
}
$map = [];
if(!empty(I('count_date'))){
$map['count_date']=I('count_date');
}
if (!empty(I('root_name'))) {
$map['promote_account'] = array('like','%'.I("root_name").'%');
}
$game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id');
if ($game_ids) {
$map['game_id'] = ['in', $game_ids];
}
if(!empty(I('root_id'))||I('root_id')=='0') {
$root_id = I('root_id');
if ($root_id == '0') {
$map['_string'] = "promote_id = {$root_id}";
} else if($root_id){
$map['_string'] = "promote_id = {$root_id} or chain like '%/{$root_id}/%'";
// $map['_string'] = "promote_id = {$root_id} or parent_id = {$root_id} or root_id = {$root_id}";
}
}
if (!empty(I('partner_id'))) {
$map['partner_id']=I('partner_id');
}
if (I('sign') == 2&&empty(I('root_id'))) {
$map['_string'] = "parent_id >0 or root_id>0";
}
if (I('sign') == 3&&empty(I('root_id'))) {
$map['_string'] = "parent_id >0 and root_id>0";
}
// var_dump($map);die();
if(!empty(I('parent_id'))) {
$parent_id = I('parent_id');
$map['_string'] = "promote_id = {$parent_id} or chain like '%/{$parent_id}/%'";
}
if (!empty(I('promote_id'))) {
$promote_id = I('promote_id');
$map['_string'] = "promote_id = {$promote_id}";
}
$map['inside_cash_count'] = ['neq',0];
$insideData = D("spend_count")->getSpendCountData($map,"game_id,inside_cash_count as count","promote_id,count_date");
unset($map['inside_cash_count']);
//内充流水与绑定流水数据
$insideDataSum = [];
foreach ($insideData as $key => $value) {
if (isset($insideDataSum[$value['game_id']])) {
$insideDataSum[$value['game_id']] = $insideDataSum[$value['game_id']] + $value['count'];
} else {
$insideDataSum[$value['game_id']] = $value['count'];
}
}
// var_dump($insideDataSum);die();
$field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,
sum(inside_cash_count) as inside_cash_count,sum(cash_count+balance_coin_count) as all_cash_count,game_name,game_id,partner_name";
$group = "game_id";
$order = "id DESC";
$data = D("spend_count")->getSpendCountData($map,$field,$group,$order,$page,$row);
foreach ($data as $key => $value) {
$data[$key]['inside_cash_count'] = number_format($insideDataSum[$value['game_id']],2,'.','');
$data[$key]['all_cash_count'] = number_format($insideDataSum[$value['game_id']]+$data[$key]['all_cash_count'],2,'.','');
}
$sumCash = D("spend_count")->sumSpendCountField($map,"cash_count");
$sumBalance = D("spend_count")->sumSpendCountField($map,"balance_coin_count");
$sumInside = number_format(array_sum($insideDataSum),2,'.','');
$sumAll = D("spend_count")->sumSpendCountField($map,"cash_count+balance_coin_count") + array_sum($insideDataSum);
$count = D("spend_count")->getSpendCountData($map,$field,$group,$order);
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '每月情况查看详情';
$this->assign('from',I('from'));
$this->assign('sumCash',$sumCash);
$this->assign('sumBalance',$sumBalance);
$this->assign('sumInside',$sumInside);
$this->assign('sumAll',$sumAll);
$this->assign('data',$data);
$this->display();
}
function gameFinanceDetail($p = 1) {
set_time_limit(0);
if (!empty(I("promote_id"))) {
$promote_id[] = I("promote_id");
}
if (!empty(I("root_id"))) {
$root_id = I("root_id");
$promote_id = $this->getPromoteList($root_id);
array_push($promote_id,$root_id);
}
if ($_REQUEST['root_id']=='0') {
$map['promote_id'] = $_REQUEST['root_id'];
}
if (!empty(I("parent_id"))) {
$parent_id = I("parent_id");
$promote_id = $this->getPromoteList($parent_id);
array_push($promote_id,$parent_id);
}
$promote_id = implode(',',$promote_id);
if ($promote_id) {
$map['promote_id'] = ['in',$promote_id];
}
if (!empty(I('partner_id'))&&empty(I("game_id"))) {
$wherePartner = I('partner_id');
$gameId = M("game","tab_")->field("id")->where("partner_id={$wherePartner}")->select();
$gameId = implode(',',array_column($gameId,'id'));
$map['game_id'] = ['in',$gameId];
}
// var_dump($map);die();
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
if (!empty(I("count_date"))) {
$month = I("count_date");
$tarry = explode('-',$month);
$startTime=mktime(0,0,0,$tarry[1],1,$tarry[0]);
$endTime =mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
$map['pay_time'] = array('between',array($startTime,$endTime));
}
$map['pay_status'] = 1;
if (!empty(I("game_id"))) {
$map['game_id'] = I("game_id");
}
if (!empty(I('user_account'))) {
$map['user_account'] = array('like','%'.I("user_account").'%');
}
if (!empty(I('user_nickname'))) {
$map['game_player_name'] = array('like',I("user_nickname").'%');
}
// var_dump($map);die();
$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";
$data = D('spend')->getSpendData($map,$field,$group,$order,$page,$row);
// echo D("spend")->_sql();die();
foreach($data as $key => $value) {
$data[$key]['pay_way'] = getPayType($value['pay_way']);
}
$sum = D('spend')->sumSpend($map,'pay_amount');
$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);
$this->assign('sum_amount',$sum);
$this->display();
}
//按月份获取会长统计
public function getRootUser($p = 1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
//获取所有数据
if (!empty(I("count_date"))) {
$map['count_date'] = I("count_date");
}
if (!empty(I("root_name"))) {
$map['promote_account']=['like','%'.I("root_name").'%'];
}
// $map['chain'] = "/";
$map['level'] = ['elt',1];
$subQueryAll = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->group('promote_id')
->page($page,$row)
->select();
$sumData = M('spend_user_count','tab_')
->field('sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->find();
$count = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count')
->where($map)
->group('promote_id')
->select();
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '会长流水';
$this->assign('sumData',$sumData);
$this->assign('data',$subQueryAll);
$this->display();
}
public function getMiniterUser($p = 1) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
if (!empty(I("count_date")) ) {
$month = I("count_date");
$map['count_date'] =$month;
}
$parentData = [];
if (!empty(I("root_id"))) {
$root_id = I("root_id");
if ($page == 1) {
$parentData = $this->getParentSpendData($root_id,$month,2);
}
$map['chain'] =['like','%/'.$root_id.'/%'];
$map['level'] = 2;
} else if(!empty(I("sign"))){
$map['parent_id'] = ['neq',0];
$map['root_id'] = ['eq',0];
} else {
if (I("root_id") == 0) {
$root_id = I("root_id");
$map['promote_id'] = $root_id;
}
}
if (!empty(I("root_name"))) {
$rootname = I("root_name");
$map['promote_account'] =['like','%'.$rootname.'%'];
}
$subQueryAll = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->group('promote_id')
->page($page,$row)
->select();
if (empty(I("root_name"))) {
$subQueryAll = array_merge($parentData,$subQueryAll);
}
$sumData = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->find();
if (empty(I("root_name"))) {
$sumData['cash_count'] = number_format($sumData['cash_count'] + $parentData[0]['cash_count'], 2, '.', '');
$sumData['balance_coin_count'] = number_format($sumData['balance_coin_count'] + $parentData[0]['balance_coin_count'], 2, '.', '');
$sumData['inside_cash_count'] = number_format($sumData['inside_cash_count'] + $parentData[0]['inside_cash_count'], 2, '.', '');
$sumData['all_count'] = number_format($sumData['all_count'] + $parentData[0]['all_count'], 2, '.', '');
$sumData['bind_coin_count'] = number_format($sumData['bind_coin_count'] + $parentData[0]['bind_coin_count'], 2, '.', '');
}
$count = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count')
->where($map)
->group('promote_id')
->select();
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '组长流水';
$this->assign('sumData',$sumData);
$this->assign('data',$subQueryAll);
$this->display();
}
public function getParentUser($p = 1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
if (!empty(I("count_date")) ) {
$month = I("count_date");
$map['count_date'] =$month;
}
$parentData = [];
if (!empty(I("parent_id"))) {
$root_id = I("parent_id");
if ($page == 1) {
$parentData = $this->getParentSpendData($root_id,$month,3);
}
$map['chain'] =['like','%/'.$root_id.'/%'];
$map['level'] = 3;
} else if(!empty(I("sign"))){
$map['parent_id'] = ['neq',0];
$map['root_id'] = ['eq',0];
} else {
if (I("parent_id") == 0) {
$root_id = I("parent_id");
$map['promote_id'] = $root_id;
}
}
if (!empty(I("root_name"))) {
$rootname = I("root_name");
$map['promote_account'] =['like','%'.$rootname.'%'];
}
$subQueryAll = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->group('promote_id')
->page($page,$row)
->select();
if (empty(I("root_name"))) {
$subQueryAll = array_merge($parentData,$subQueryAll);
}
$sumData = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->find();
if (empty(I("root_name"))) {
$sumData['cash_count'] = number_format($sumData['cash_count'] + $parentData[0]['cash_count'], 2, '.', '');
$sumData['balance_coin_count'] = number_format($sumData['balance_coin_count'] + $parentData[0]['balance_coin_count'], 2, '.', '');
$sumData['inside_cash_count'] = number_format($sumData['inside_cash_count'] + $parentData[0]['inside_cash_count'], 2, '.', '');
$sumData['all_count'] = number_format($sumData['all_count'] + $parentData[0]['all_count'], 2, '.', '');
$sumData['bind_coin_count'] = number_format($sumData['bind_coin_count'] + $parentData[0]['bind_coin_count'], 2, '.', '');
}
$count = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count')
->where($map)
->group('promote_id')
->select();
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '组长流水';
$this->assign('sumData',$sumData);
$this->assign('data',$subQueryAll);
$this->display();
}
public function getPromoteUser($p = 1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
if (!empty(I("count_date"))) {
$month = I("count_date");
$map['count_date'] =$month;
}
$parentData = [];
if (!empty(I("parent_id"))) {
$parent_id = I("parent_id");
if ($page == 1) {
$parentData = $this->getParentSpendData($parent_id,$month,4);
}
$map['chain'] =['like','%/'.$parent_id.'/%'];
$map['level'] = 4;
}
if (!empty(I('sign'))) {
$map['parent_id'] = ['neq',0];
if (!empty(I('root_id'))) {
$map['root_id'] = I('root_id');
} else {
$map['root_id'] = ['neq',0];
}
}
// var_dump($map);die();
// var_dump($map);die();
$subQueryAll = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->group('promote_id')
->page($page,$row)
->select();
$subQueryAll = array_merge($parentData,$subQueryAll);
$sumData = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)
->find();
$sumData['cash_count'] = number_format($sumData['cash_count']+$parentData[0]['cash_count'],2,'.','');
$sumData['balance_coin_count'] = number_format($sumData['balance_coin_count']+$parentData[0]['balance_coin_count'],2,'.','');
$sumData['inside_cash_count'] = number_format($sumData['inside_cash_count']+$parentData[0]['inside_cash_count'],2,'.','');
$sumData['all_count'] = number_format($sumData['all_count']+$parentData[0]['all_count'],2,'.','');
$sumData['bind_coin_count'] = number_format($sumData['bind_coin_count']+$parentData[0]['bind_coin_count'],2,'.','');
$count = M('spend_user_count','tab_')
->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count')
->where($map)
->group('promote_id')
->select();
$count = count($count);
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '推广员流水';
$sum = array_sum($sumData);
$this->assign('sumData',$sumData);
$this->assign('data',$subQueryAll);
$this->display();
# code...
}
function getPromoteList($root_id = 0) {
$data = M('promote','tab_')
->field("id")
->where("chain like '%/{$root_id}/%'")
->select();
$handleData = [];
foreach ($data as $key => $value) {
array_push($handleData,$data[$key]['id']);
}
return $handleData;
}
function 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("relation_game_name as game_name")->where($map)->group("relation_game_name")->select();
$this->ajaxReturn($data,'json');
}
function getParentSpendData($root_id,$date,$level=2) {
$data = [];
if (!$root_id) {
$this->error('数据错误');
} else {
$map = [];
if ($root_id) {
$map['promote_id'] = $root_id;
}
if ($date) {
$map['count_date'] = $date;
}
$data = M('spend_user_count','tab_')
->field('promote_id,promote_account, sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,sum(inside_cash_count) as inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map)->select();
// dump($data);
$map1['chain'] = ['like','%/'.$data[0]['promote_id'].'/%'];
$map1['count_date'] = $date;
$map1['level'] = $level;
$sunData = M('spend_user_count','tab_')
->field('promote_id,promote_account, sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count,sum(inside_cash_count) as inside_cash_count, sum(all_count) as all_count, sum(bind_coin_count) as bind_coin_count')
->where($map1)->find();
// echo M('spend_user_count','tab_')->_sql();
// dump($sunData);
//die();
$data[0]['cash_count'] = number_format($data[0]['cash_count']-$sunData['cash_count'],2,'.','');
$data[0]['balance_coin_count'] = number_format($data[0]['balance_coin_count']-$sunData['balance_coin_count'],2,'.','');
$data[0]['inside_cash_count'] = number_format($data[0]['inside_cash_count']-$sunData['inside_cash_count'],2,'.','');
$data[0]['all_count'] = number_format($data[0]['all_count']-$sunData['all_count'],2,'.','');
$data[0]['bind_coin_count'] = number_format($data[0]['bind_coin_count']-$sunData['bind_coin_count'],2,'.','');
// $map['inside_cash_count'] = ['neq',0];
// $insideData = D("spend_count")->getSpendCountData($map,"promote_id,inside_cash_count as count","promote_id,count_date");
// unset($map['bind_coin_count']);
// //内充流水与绑定流水数据
// $insideDataSum = 0;
// foreach ($insideData as $key => $value) {
// if (isset($insideDataSum)) {
// $insideDataSum = $insideDataSum + $value['count'];
// } else {
// $insideDataSum = $value['count'];
// }
// }
}
// if (!$data[0]['cash_count']&&!$data[0]['balance_coin_count']&&!$data[0]['inside_cash_count']&&!$data[0]['all_count']) {
// $promoteData = M('promote','tab_')->field('account as promote_account')->where("id={$root_id}")->find();
//
// $data[0]['promote_id'] = $root_id;
// $data[0]['promote_account'] = $promoteData['promote_account'];
// $data[0]['cash_count'] = number_format(0.00,2,'.','');
// $data[0]['balance_coin_count'] = number_format(0.00,2,'.','');
// $data[0]['inside_cash_count'] = number_format(0.00,2,'.','');
// $data[0]['all_count'] = number_format(0.00,2,'.','');
// }
// $data[0]['inside_cash_count'] = number_format($insideDataSum,2,'.','');
// $data[0]['all_count'] = number_format($insideDataSum+$data[0]['all_count'],2,'.','');
// var_dump($data);die();
return $data;
}
/**
*游戏统计
*/
public function gameStatistics($p = 1) {
if(!array_key_exists("timestart",$_REQUEST)){
$this->redirect(ACTION_NAME, array('timestart' => date('Y-m-d',strtotime('-30 day')),"timeend"=>date('Y-m-d')));
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row = $_REQUEST['row'] ?? 10;
$map = [];
$searchGameIds = null;
$game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id');
$gameWhere = [];
$testStrWhere = '1=1';
if ($game_ids) {
$gameWhere['id'] = ['in', $game_ids];
}
if (!empty(I('partner_id'))) {
$gameWhere['partner_id'] = I('partner_id');
}
if (!empty(I('timestart'))) {
$timestart = strtotime(I('timestart'));
$map['_string'] = "s.payed_time >= {$timestart}";
$testStrWhere .= " and pay_time >= {$timestart}";
}
if (!empty(I('timeend'))) {
$timeend = strtotime(I('timeend') . ' 23:59:59');
if (!empty($map['_string'])) {
$map['_string'] .= " and ";
}
$map['_string'] .= " s.payed_time <= {$timeend}";
$testStrWhere .= " and pay_time <= {$timeend}";
}
if (!empty(I('game_type_id'))) {
$gameWhere['game_type_id'] = I('game_type_id', 0);
}
$searchGameIds = M('game', 'tab_')->where($gameWhere)->getField('id', true);
$startTime = time();
D("spend")->addSubsiteWhere($map);
//游戏统计列表
if(isset($_REQUEST['export'])){
$data = D("spend")->gameStatistics($map,$searchGameIds, 0, 0);
}else{
$data = D("spend")->gameStatistics($map,$searchGameIds, $row, $p);
}
$gameIds = array_column($data, 'game_id');
$uniqueCodes = array_column($data, 'unique_code');
$uniqueCodes = array_filter($uniqueCodes, function($value) {
if ($value) {
return true;
}
return false;
});
$gameSets = M('game_set', 'tab_')->field(['game_id', 'pay_notify_url'])->select();
$gameSets = index_by_column('game_id', $gameSets);
$searchGameCodes = [];
$testList = [];
$testWhere = [
'game_id' => 0,
'_string' => $testStrWhere,
];
if (count($searchGameIds) > 0) {
$searchGameCodes = M('game', 'tab_')->where(['id' => ['in', $searchGameIds], 'unique_code' => ['neq', '']])->getField('unique_code', true);
$searchGameCodes = array_unique($searchGameCodes);
$testWhere['game_id'] = ['in', $searchGameIds];
$testRows = M('test_order', 'tab_')
->field(['game_id', 'sum(pay_amount) amount'])
->where($testWhere)
->group('game_id')
->select();
foreach ($testRows as $testRow) {
$testList[$testRow['game_id']] = round(floatval($testRow['amount']), 2);
}
}
$client = new AggregateClient();
$result = $client->api('game-data', [
'unique_codes' => $uniqueCodes,
'started_at' => I('timestart', ''),
'ended_at' => I('timeend', ''),
'search_games' => $searchGameCodes,
'device_type' => I("sdk_type", 0),
]);
$aggData = [];
$aggWmData = [];
$aggFailData = [];
$aggWmFailData = [];
$aggTotal = '0.00';
$aggWmTotal = '0.00';
$aggFailTotal = '0.00';
$aggWmFailTotal = '0.00';
if ($result['code'] == '0000') {
$aggData = $result['data']['records'] ?? [];
$aggWmData = $result['data']['wm_records'] ?? [];
$aggFailData = $result['data']['fail_records'] ?? [];
$aggWmFailData = $result['data']['wm_fail_records'] ?? [];
$aggTotal = $result['data']['total'] ?? '0.00';
$aggWmTotal = $result['data']['wm_total'] ?? '0.00';
$aggFailTotal = $result['data']['fail_total'] ?? '0.00';
$aggWmFailTotal = $result['data']['wm_fail_total'] ?? '0.00';
}
$endTime = time();
$exceptIds = getAggExceptIds($gameSets);
foreach ($data as $key => $value) {
$aggAmount = '0.00';
$aggWmAmount = '0.00';
$aggFailAmount = '0.00';
$aggWmFailAmount = '0.00';
$testAmount = '0.00';
$deviceType = $value['sdk_version'] == 1 ? 'android' : 'ios';
if ($value['unique_code']) {
if (isset($aggData[$value['unique_code']]) && isset($aggData[$value['unique_code']][$deviceType])) {
$aggAmount = number_format($aggData[$value['unique_code']][$deviceType], 2, '.', '');
}
if (isset($aggWmData[$value['unique_code']]) && isset($aggWmData[$value['unique_code']][$deviceType])) {
$aggWmAmount = number_format($aggWmData[$value['unique_code']][$deviceType], 2, '.', '');
}
if (isset($aggFailData[$value['unique_code']]) && isset($aggFailData[$value['unique_code']][$deviceType])) {
$aggFailAmount = number_format($aggFailData[$value['unique_code']][$deviceType], 2, '.', '');
}
if (isset($aggWmFailData[$value['unique_code']]) && isset($aggWmFailData[$value['unique_code']][$deviceType])) {
$aggWmFailAmount = number_format($aggWmFailData[$value['unique_code']][$deviceType], 2, '.', '');
}
}
if (isset($gameSets[$value['game_id']]) && isAggGame($gameSets[$value['game_id']]['pay_notify_url'])) {
$data[$key]['cash_count'] = $value['cash_count'] = 0;
$data[$key]['balance_coin_count'] = $value['balance_coin_count'] = 0;
$data[$key]['inside_cash_count'] = $value['inside_cash_count'] = 0;
$testAmount = $testList[$value['game_id']] ?? '0.00';
}
$data[$key]['all_cash_count'] = number_format($value['cash_count'] + $value['balance_coin_count'] + $value['inside_cash_count'],2,'.','');
$data[$key]['agg_amount'] = $aggAmount;
$data[$key]['agg_wm_amount'] = $aggWmAmount;
$data[$key]['agg_failed_amount'] = $aggFailAmount;
$data[$key]['agg_wm_failed_amount'] = $aggWmFailAmount;
$data[$key]['test_amount'] = $testAmount;
$data[$key]['sdk_version'] = $value['sdk_version'] == 1 ? "安卓" : "苹果";
}
if(isset($_REQUEST['export'])){
//操作日志
$GetData = $_GET;
unset($GetData['export']);
$dcop = array(
'partner_name'=>'合作公司',
'game_name'=>'游戏',
'sdk_version'=>'设备类型',
'game_type_name'=>'游戏类型',
'cash_count'=>'游戏现金金额',
'balance_coin_count'=>'平台币直充支出',
'inside_cash_count'=>'内充支出',
'all_cash_count'=>'游戏内充值合计',
'notice_fail_count'=>'联运通知失败合计',
'agg_wm_amount'=>'聚合万盟数据',
'agg_wm_failed_amount'=>'聚合万盟通知失败',
'test_amount'=>'聚合平台测试订单',
'agg_amount'=>'聚合其他渠道数据',
'agg_failed_amount'=>'聚合其他渠道通知失败订单'
);
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$GetData),'menu'=>"充值-财务管理-游戏统计-导出"]);
data2csv($data,"游戏统计",$dcop);
}
$count = count($searchGameIds);//列表总数
// $allData = D("spend")->gameStatistics($map);//列表总数
// $count = count($allData);
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);//分页
}
$this->checkListOrCountAuthRestMap($map,[]);
$testWhere['_string'] .= ' and game_id in(' . implode(',', $exceptIds) . ')';
$testAllAmount = M('test_order', 'tab_')->where($testWhere)->sum('pay_amount');
//统计合计
if (count($exceptIds) > 0) {
if (isset($map['_string'])) {
$map['_string'] .= " and s.game_id not in (" . implode(',', $exceptIds) . ")";
} else {
$map['_string'] = " s.game_id not in (" . implode(',', $exceptIds) . ")";
}
}
$totalData = D("spend")->totalGameStatistics($map,$searchGameIds);
$sumCash = $totalData['cash_count'];
$sumBalance = $totalData['balance_coin_count'];
$sumInside = $totalData['inside_cash_count'];
$sumNoticeFail = $totalData['notice_fail_count']? $totalData['notice_fail_count']:0;
$sumAll = $sumCash + $sumBalance + $sumInside;
$game_types = M("game_type", 'tab_')->field('id, type_name')->select();
$aggRate = round(($aggTotal + $aggWmTotal)/($sumAll + $aggTotal + $aggWmTotal) * 100, 2) . '%';
$allRate = round($sumAll/($sumAll + $aggTotal + $aggWmTotal) * 100, 2) . '%';
$this->assign('testAllAmount', $testAllAmount);
$this->assign('aggFailTotal', $aggFailTotal);
$this->assign('aggWmFailTotal', $aggWmFailTotal);
$this->assign('aggRate', $aggRate);
$this->assign('allRate', $allRate);
$this->assign('aggWmTotal', $aggWmTotal);
$this->assign('aggTotal', $aggTotal);
$this->assign('game_types', $game_types);
$this->assign('sumCash', $sumCash);
$this->assign('sumBalance', $sumBalance);
$this->assign('sumInside', $sumInside);
$this->assign('sumNoticeFail', $sumNoticeFail);
$this->assign('sumAll', $sumAll);
$this->assign('data',$data);
$this->display();
}
public function aggDetail($p = 1)
{
$limit = I('row', 10);
$gameId = I('game_id', 0);
$deviceType = 0;
$orderNumber = I('order_number', '');
$roleName = I('role_name', '');
$account = I('account', '');
$gameId = I('game_id', 0);
$channelType = I('channel_type', 0);
$game = M('game', 'tab_')->field(['id', 'unique_code', 'game_name', 'sdk_version'])->where(['id' => $gameId])->find();
$client = new AggregateClient();
$result = $client->api('game-recharge-detail', [
'unique_code' => $game['unique_code'],
'started_at' => I('timestart', ''),
'ended_at' => I('timeend', ''),
'account' => $account,
'order_number' => $orderNumber,
'role_name' => $roleName,
'device_type' => $game['sdk_version'],
'page' => $p,
'limit' => $limit,
'channel_type' => $channelType,
]);
$count = 0;
$total = '0.00';
$records = [];
if ($result['code'] == '0000') {
$count = $result['data']['count'];
$total = $result['data']['total'];
$records = $result['data']['records'];
}
foreach ($records as $key => $record) {
$records[$key]['game_name'] = $game['game_name'];
$records[$key]['rom_platform'] = $record['rom_platform'] == 'android' ? '安卓' : 'IOS';
}
if(isset($_REQUEST['export'])){
//操作日志
$GetData = $_GET;
unset($GetData['export']);
$dcop = array(
"order_number"=>"支付订单号",
"pay_success_time"=>"充值时间",
"account"=>"玩家账号",
"game_name"=>"游戏名称",
"rom_platform"=>"设备类型",
"role_name"=>"角色名称",
"money"=>"充值金额",
);
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$GetData),'menu'=>"充值-财务管理-游戏统计-订单查看-导出"]);
data2csv($records, "聚合游戏统计订单查看", $dcop);
}
$page = set_pagination($count, $limit);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('game', $game);
$this->assign('pagination', $page);
$this->assign('total', $total);
$this->assign('records', $records);
$this->display();
}
public function gameStatisticsDetail($p = 1) {
if (isset($_REQUEST['pay_way'])) {
$map['pay_way'] = $_REQUEST['pay_way'];
}
if (!empty($_REQUEST['pay_order_number'])) {
$map['pay_order_number'] = $_REQUEST['pay_order_number'];
}
if (!empty(I('partner_id'))&&empty(I("game_id"))) {
$wherePartner = I('partner_id');
$gameId = M("game","tab_")->field("id")->where("partner_id={$wherePartner}")->select();
$gameId = implode(',',array_column($gameId,'id'));
$map['game_id'] = ['in',$gameId];
}
if (!empty(I('timestart'))) {
$timestart = strtotime(I('timestart'));
$map['_string'] = "payed_time >= {$timestart}";
}
if (!empty(I('timeend'))) {
$timeend = strtotime(I('timeend') . ' 23:59:59');
if (!empty($map['_string'])) {
$map['_string'] .= " and ";
}
$map['_string'] .= " payed_time < {$timeend}";
}
if (!empty(I("promote_id"))) {
$promote_id[] = I("promote_id");
}
if (!empty(I("root_id"))) {
$root_id = I("root_id");
$promote_id = $this->getPromoteList($root_id);
array_push($promote_id, $root_id);
}
if ($_REQUEST['root_id']=='0') {
$map['promote_id'] = $_REQUEST['root_id'];
}
if ($_REQUEST['merchant_id']){
$map['merchant_id'] = $_REQUEST['merchant_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_game_status'] = 1;
if (!empty(I("game_id"))) {
$map['game_id'] = I("game_id");
}
if(empty(I("game_id")) && !empty(I("game_name"))){
$map['game_name'] = array('like','%'.I("game_name").'%');;
}
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").'%');
}
D("Spend")->addSubsiteWhere($map);
// var_dump($map);die();
$field = "pay_order_number,FROM_UNIXTIME(payed_time) as pay_time,user_account,user_nickname,game_name,promote_account,spend_ip,server_name,game_player_name,pay_amount,cost,pay_way,sdk_version,merchant_id";
$group = "";
$order = "payed_time DESC";
if(isset($_REQUEST['export'])){
$data = D('spend')->getSpendData($map,$field,$group,$order,0,0);
}else{
$data = D('spend')->getSpendData($map,$field,$group,$order,$page,$row);
}
$merchant_data = M("payment_merchant","tab_")
->field("id,name")
->where("1=1")
->select();
$handle_merchant = [];
foreach ($merchant_data as $key => $value) {
$handle_merchant[$value['id']] = $value['name'];
}
foreach($data as $key => $value) {
$data[$key]['merchant_name'] = $handle_merchant[$value['merchant_id']];
$data[$key]['pay_way'] = getPayType($value['pay_way']);
$data[$key]['sdk_version'] =getGameTypeName($data[$key]['sdk_version']);
$data[$key]['game_name'] =clearGameNameType($data[$key]['game_name']);
($data[$key]['promote_account']=='官方渠道')?($data[$key]['promote_account']=C('OFFICIEL_CHANNEL')):'';
if (isset($_REQUEST['export'])) {
checkEncryptionAuth($data[$key]['user_account'],'gameStatisticsDetail');
}
}
if(isset($_REQUEST['export'])){
//操作日志
$GetData = $_GET;
unset($GetData['export']);
$dcop = array(
"pay_order_number"=>"支付订单号",
"pay_time"=>"充值时间",
"user_account"=>"玩家账号",
"game_name"=>"游戏名称",
"sdk_version"=>"设备类型",
"promote_account"=>"所属推广员",
"spend_ip"=>"充值ip",
"server_name"=>"游戏区服",
"game_player_name"=>"角色名称",
"cost"=>"订单金额",
"pay_amount"=>"实付金额",
"pay_way"=>"充值方式",
"merchant_name"=>"所属商户"
);
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$GetData),'menu'=>"充值-财务管理-游戏统计-订单查看-导出"]);
data2csv($data,"游戏统计订单查看",$dcop);
}
$totalMap = $map;
if ($map['game_id']) {
$totalMap['s.game_id'] = $map['game_id'];
unset($totalMap['game_id']);
}
if ($map['game_name']) {
$totalMap['s.game_name'] = $map['game_name'];
unset($totalMap['game_name']);
}
$totalData = D('spend')->totalGameStatistics($totalMap, 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,'count(*) as count',$group,$order);
$this->checkListOrCountAuthRestMap($map,[]);
$count = $count[0]['count'];
$page = set_pagination($count,$row);
if($page) {$this->assign('_page', $page);}
$this->meta_title = '游戏订单查看';
$this->assign('data',$data);
$this->display();
}
public function coinDetail($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('timestart'))) {
$timestart = strtotime(I('timestart'));
$map['_string'] = "payed_time > {$timestart}";
}
if (!empty(I('timeend'))) {
$timeend = strtotime(I('timeend') . ' 23:59:59');;
$map['_string'] .= " and payed_time < {$timeend}";
}
if (!empty(I("promote_id"))) {
$promote_id[] = I("promote_id");
}
if (!empty(I("root_id"))) {
$root_id = I("root_id");
$promote_id = $this->getPromoteList($root_id);
array_push($promote_id, $root_id);
}
if ($_REQUEST['root_id']=='0') {
$map['tab_spend.promote_id'] = $_REQUEST['root_id'];
}
$promote_id = implode(',',$promote_id);
if ($promote_id) {
$map['tab_spend.promote_id'] = ['in',$promote_id];
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map['pay_game_status'] = 1;
if (!empty(I("game_id"))) {
$map['tab_spend.game_id'] = I("game_id");
}
if (!empty(I('user_account'))) {
$map['tab_spend.user_account'] = array('like','%'.I("user_account").'%');
}
if (!empty(I('user_nickname'))) {
$map['tab_spend.game_player_name'] = array('like',I("user_nickname").'%');
}
// var_dump($map);die();
$field = "pay_order_number,FROM_UNIXTIME(payed_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,tab_spend.sdk_version,
game_player_name,pay_amount,cost,pay_way";
$group = "";
$order = "payed_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']);
$data[$key]['game_name'] =clearGameNameType($data[$key]['game_name']);
$data[$key]['sdk_version'] =getGameTypeName($data[$key]['sdk_version']);
$data[$key]['cost'] = number_format($value['cost'],2,'.','');
$data[$key]['pay_amount'] = number_format($value['pay_amount'],2,'.','');
}
if(isset($_REQUEST['export'])){
//操作日志
$GetData = $_GET;
unset($GetData['export']);
$dcop = array(
"pay_order_number"=>"支付订单号",
"pay_time"=>"充值时间",
"user_account"=>"玩家账号",
"game_name"=>"游戏名称",
"sdk_version"=>"设备名称",
"server_name"=>"游戏区服",
"game_player_name"=>"角色名称",
"cost"=>"订单金额",
"pay_amount"=>"实付金额",
"pay_way"=>"充值方式"
);
if ($map['pay_way'] ==-1) {
$title = "内充支出明细";
$dcop["bind_balance"]="绑定币余额";
} elseif ($map['pay_way'] ==0) {//平台币
$title = "平台币直充明细";
$dcop["balance"]="平台币余额";
}
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$GetData),'menu'=>"充值-财务管理-游戏统计-{$title}-导出"]);
data2csv($data,$title,$dcop);
}
$count = D("spend")->getSpendData($map,$field,$group,$order);
$count = count($count);
$page = set_pagination($count,$row);
$this->checkListOrCountAuthRestMap($map,[]);
$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 getPartnetList()
{
$game_ids = array_column(getGameByName(I("game_name"), I("sdk_type")), 'id');
if ($game_ids) {
$map['g.id'] = ['in', $game_ids];
}
if (I('sdk_type')) {
$map['sdk_version'] = I('sdk_type');
}
$data = M('partner','tab_')->alias('p')
->join('left join tab_game as g on g.partner_id = p.id')
->field("partner, p.id")
->where($map)
->group('p.id')
->select();
$this->ajaxReturn($data,'json');
}
/**
*充值方式统计
*/
public function payTypeStatistics()
{
$time = array('egt', 0);;
if(!array_key_exists("timestart",$_REQUEST)){
$this->redirect(ACTION_NAME, array('timestart' => date('Y-m-d',strtotime('-30 day')),"timeend"=>date('Y-m-d')));
}
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$time = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$time = array('between', [strtotime($_REQUEST['timestart']), time()]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$time = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
}
// setPowerPromoteIds($map);
$cashMap = [
'pay_status' => 1,'pay_way'=>['egt',1],'payed_time'=>$time
];
D("Spend")->addSubsiteWhere($cashMap);
//获取现金充值
$cashStatistics = M('spend', 'tab_')
->field('pay_way,"" as pay_type,SUM(pay_amount) AS pay_amount')
->where($cashMap)
->group('pay_way')
->select();
foreach ($cashStatistics as $key => $value) {
$cashStatistics[$key]['pay_type'] = getPayType($value['pay_way']);
$cashStatistics[$key]['balance'] = '0.00';
}
$cashStatistics = array_column($cashStatistics, null, 'pay_way');
// dd($cashStatistics);
//获取平台币充值
$depositMap = [
'pay_source' => 2,
'tab_deposit.pay_status' => 1,
'tab_deposit.pay_way' => ['gt', 0],
'tab_deposit.payed_time'=>$time,
];
D("Deposit")->addSubsiteWhere($depositMap,"tab_deposit");
$deposit = M('deposit', 'tab_')->where($depositMap)->field('tab_deposit.pay_way,"" as pay_type, SUM(tab_deposit.pay_amount) AS balance')
->group('tab_deposit.pay_way')
->select();
foreach ($deposit as $key => $value) {
if (!array_key_exists($value['pay_way'], $cashStatistics)) {
$cashStatistics[$value['pay_way']] = $value;
$cashStatistics[$value['pay_way']]['pay_type'] = getPayType($value['pay_way']);//充值方式文字影视
$cashStatistics[$value['pay_way']]['pay_amount'] = '0.00';
}
$cashStatistics[$value['pay_way']]['balance'] = $value['balance'];//别表的平台币充值
}
//超级签数据
$superSignData = M('game_supersign','tab_')
->field("pay_way,'' as pay_type,sum(pay_price) as pay_amount")
->where([
'pay_status' => 1,
'pay_way' => ['gt', 0],
'pay_time'=>$time
])
->group('pay_way')
->select();
foreach ($superSignData as $key => $value) {
if (!array_key_exists($value['pay_way'], $cashStatistics)) {
$cashStatistics[$value['pay_way']] = $value;
$cashStatistics[$value['pay_way']]['pay_type'] = getPayType($value['pay_way']);//充值方式文字影视
$cashStatistics[$value['pay_way']]['pay_amount'] = '0.00';
$cashStatistics[$value['pay_way']]['balance'] = 0;//别表的平台币充值
}
$cashStatistics[$value['pay_way']]['pay_amount'] += $value['pay_amount'];//别表的平台币充值
}
//绑定币数据
$bindRechargeData = M('bind_recharge','tab_')
->field('pay_way,"" as pay_type,sum(real_amount) as pay_amount')
->where([
'pay_status' => 1,
'pay_way' => ['gt', 0],
'create_time'=>$time
])
->group('pay_way')
->select();
foreach ($bindRechargeData as $key => $value) {
if ($value['pay_way'] == NULL&&$value['pay_amount'] == NULL) {
continue;
}
if (!array_key_exists($value['pay_way'], $cashStatistics)) {
$cashStatistics[$value['pay_way']] = $value;
$cashStatistics[$value['pay_way']]['pay_type'] = getPayType($value['pay_way']);//充值方式文字影视
$cashStatistics[$value['pay_way']]['pay_amount'] = '0.00';
$cashStatistics[$value['pay_way']]['balance'] = 0;//别表的平台币充值
}
$cashStatistics[$value['pay_way']]['balance'] += $value['pay_amount'];//别表的平台币充值
}
//推广后台
$spreadData = M("coin_pay_order","tab_")
->field("pay_way,'' as pay_type,sum(pay_amount) as pay_amount")
->where([
'order_status'=>['egt',1],
'pay_way'=>['egt',1],'pay_time'=>$time
])
->group('pay_way')
->select();
foreach ($spreadData as $key => $value) {
if ($value['pay_way'] == NULL&&$value['pay_amount'] == NULL) {
continue;
}
if (!array_key_exists($value['pay_way'], $cashStatistics)) {
$cashStatistics[$value['pay_way']] = $value;
$cashStatistics[$value['pay_way']]['pay_type'] = getPayType($value['pay_way']);//充值方式文字影视
$cashStatistics[$value['pay_way']]['pay_amount'] = '0.00';
$cashStatistics[$value['pay_way']]['balance'] = 0;//别表的平台币充值
}
$cashStatistics[$value['pay_way']]['balance'] += $value['pay_amount'];//别表的平台币充值
}
//官网充值
$offcialmap = [
'pay_status'=>1,
'pay_way'=>['egt',1],
'pay_source'=>0,
'payed_time'=>$time
];
D("Deposit")->addSubsiteWhere($offcialmap);
$offcialData = M('deposit','tab_')
->field("pay_way,'' as pay_type,sum(pay_amount) as pay_amount")
->where($offcialmap)
->group('pay_way')
->select();
foreach ($offcialData as $key => $value) {
if ($value['pay_way'] == NULL&&$value['pay_amount'] == NULL) {
continue;
}
if (!array_key_exists($value['pay_way'], $cashStatistics)) {
$cashStatistics[$value['pay_way']] = $value;
$cashStatistics[$value['pay_way']]['pay_type'] = getPayType($value['pay_way']);//充值方式文字影视
$cashStatistics[$value['pay_way']]['pay_amount'] = '0.00';
$cashStatistics[$value['pay_way']]['balance'] = 0;//别表的平台币充值
}
$cashStatistics[$value['pay_way']]['balance'] += $value['pay_amount'];//别表的平台币充值
}
$testOrderMap = [
'pay_way'=>['egt',1],
'pay_time'=>$time
];
addSubsiteWhere($testOrderMap,"partner_type");
$testOrderData = M('test_order', 'tab_')
->where($testOrderMap)
->field('pay_way,sum(pay_amount) as pay_amount')
->group("pay_way")
->select();
foreach ($testOrderData as $key => $value) {
if ($value['pay_way'] == NULL&&$value['pay_amount'] == NULL) {
continue;
}
if (!array_key_exists($value['pay_way'], $cashStatistics)) {
$cashStatistics[$value['pay_way']] = $value;
$cashStatistics[$value['pay_way']]['pay_type'] = getPayType($value['pay_way']);//充值方式文字影视
$cashStatistics[$value['pay_way']]['pay_amount'] = '0.00';
$cashStatistics[$value['pay_way']]['balance'] = 0;//别表的平台币充值
}
$cashStatistics[$value['pay_way']]['balance'] += $value['pay_amount'];//别表的平台币充值
}
foreach ($cashStatistics as $key => $value) {
$cashStatistics[$key]['pay_rate'] = '';
$cashStatistics[$key]['total'] = $value['pay_amount'] + $value['balance'];//添加列表合计
}
// var_dump($cashStatistics);die();
//底部总计
$all_pay_amount = array_sum(array_column($cashStatistics, 'pay_amount'));//现金充值总计
$all_balance = array_sum(array_column($cashStatistics, 'balance'));//平台币充值总计
$all_total = array_sum(array_column($cashStatistics, 'total'));//合计总计
$this->meta_title = "平台统计";
if($_REQUEST['export']) {
foreach($cashStatistics as $key =>$value) {
unset($cashStatistics[$key]['pay_way']);
$cashStatistics[$key]['pay_rate'] = strval(round($value['total']/$all_total, 4)*100) . "%";
}
db2csv(array_merge($cashStatistics,
[0=>['pay_type'=>'总计','pay_amount'=>$all_pay_amount,'balance'=>$all_balance, 'pay_rate'=>'', 'total'=>$all_total]]),'平台统计'
,['支付方式','现金充值','平台币充值', '支付方式占比', '合计']);
}
$this->checkListOrCountAuthRestMap($map,[]);
$this->assign('all_pay_amount', $all_pay_amount);
$this->assign('all_balance', $all_balance);
$this->assign('all_total', $all_total);
$this->assign('data', $cashStatistics);
$this->display();
}
public function valueDetail($p=1)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$isExport = I('export', 0);
$startedAt = I('timestart', '');
$endedAt = I('timeend', '');
$userAccount = I('user_account', '');
$orderField = I('order_field', '');
$orderType = I('order_type', '');
$map = [];
$lastMap = [];
$map['_string'] = $lastMap['_string'] = '1=1';
if ($startedAt != '') {
$map['_string'] .= ' and create_time >=' . strtotime($startedAt . ' 00:00:00');
}
if ($endedAt != '') {
$map['_string'] .= ' and create_time <=' . strtotime($endedAt . ' 23:59:59');
$lastMap['_string'] .= ' and create_time <=' . strtotime($endedAt . ' 23:59:59');
}
$userMap = [];
if ($userAccount != '') {
$userMap['account'] = $userAccount;
}
$valueSubSql = M('value_detail_log', 'tab_')->field([
'abs(IFNULL(sum(IF(pay_type=1,value,0)), 0)) amount1',
'IFNULL(sum(IF(pay_type=2,value,0)), 0) amount2',
'IFNULL(sum(IF(pay_type=3,value,0)), 0) amount3',
'user_id'
])
->where($map)
->group('user_id')
->select(false);
$lastSubSql = M('value_detail_log', 'tab_')->field(['CONVERT(SUBSTRING_INDEX(group_concat(id order by `create_time` desc),",",1), UNSIGNED INTEGER)'])
->where($lastMap)
->group('user_id')
->select(false);
$reaminSubSql = M('value_detail_log', 'tab_')->field('user_id, after_value amount')
->where(['_string' => 'id in(' . $lastSubSql . ')'])
->group('user_id')
->select(false);
$this->checkListOrCountAuthRestMap($userMap, []);
$query = M('user', 'tab_')
->alias('a')
->where($userMap)
->join('left join (' . $valueSubSql . ') b on a.id=b.user_id')
->join('left join (' . $reaminSubSql . ') c on a.id=c.user_id');
$countQuery = clone $query;
$sumQuery = clone $query;
$order = 'id desc';
if ($orderField != '') {
$order = $orderField . ' ' . ($orderType == '' ? 'desc' : $orderType);
}
$columns = ['a.account', 'a.id', 'a.balance', 'b.amount1 spend_value', 'b.amount2 deposit_value', 'b.amount3 promote_value', 'c.amount remain'];
$records = [];
if ($isExport == 1) {
$records = $query->field($columns)->order($order)->limit(10000)->select();
} else {
$records = $query->field($columns)->order($order)->page($page, $row)->select();
}
foreach ($records as $key => $record) {
$records[$key]['spend_value'] = number_format(abs(floatval($record['spend_value'])), 2, '.', '');
$records[$key]['deposit_value'] = number_format(abs(floatval($record['deposit_value'])), 2, '.', '');
$records[$key]['promote_value'] = number_format(floatval($record['promote_value']), 2, '.', '');
$records[$key]['remain'] = number_format(floatval($record['remain']), 2, '.', '');
}
$count = $countQuery->count();
$sumColumns = ['sum(a.balance) balance', 'sum(b.amount1) spend_value', 'sum(b.amount2) deposit_value', 'sum(b.amount3) promote_value', 'sum(c.amount) remain'];
$summary = $sumQuery->field($sumColumns)->find();
if($isExport == 1) {
$getData = $_GET;
unset($getData['export']);
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'url'=>U(CONTROLLER_NAME.'/'.ACTION_NAME,$getData),'menu'=>"财务-数据统计-平台币统计-导出"]);
data2csv($records, '平台币统计', [
'id' => '账号ID',
'account' => '玩家账号',
'balance' => '当前平台币余额',
'remain' => '平台币余额',
'spend_value' => '平台币直充支出',
'deposit_value' => '平台币直充金额',
'promote_value' => '后台发放平台币',
]);
}
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('_page', $page);
$this->assign('records', $records);
$this->assign('summary', $summary);
$this->assign('orderField', $orderField);
$this->assign('orderType', $orderType);
$this->display();
}
public function definiteDetaile($p=1) {
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$user_id = I('user_id');
$orderNumber = I('order_number');
$map = [];
if($orderNumber) {
$map['order_number'] = $orderNumber;
}
$map['user_id'] = $user_id;
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['create_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['create_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['create_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
}
$total = '0.00';
$t = M('value_detail_log', 'tab_')->where($map)->sum('value');
if (empty($t)) {
$t = '0.00';
}
$valueDetailDatas = M('value_detail_log', 'tab_')->field('order_number, user_id, before_value, value, after_value, create_time, type, remark, pay_type')
->where($map)
->page($page,$row)
->order('create_time desc')
->select();
$counts = M('value_detail_log', 'tab_')->field('id')
->where($map)
->count();
foreach ($valueDetailDatas as $key => $valueDetailData) {
$vlaueDetailDatas[$key]['create_time'] = date('Y-m-d H:i:s', $valueDetailData['create_time']);
$vlaueDetailDatas[$key]['value'] = $valueDetailData['value'];
$vlaueDetailDatas[$key]['after_value'] = $valueDetailData['after_value'];
$vlaueDetailDatas[$key]['order_number'] = $valueDetailData['order_number'];
$vlaueDetailDatas[$key]['pay_type'] = $valueDetailData['pay_type'];
if($valueDetailData['pay_type'] == 1) {
$vlaueDetailDatas[$key]['type'] = "消费";
$total += $valueDetailData['value'];
}
if($valueDetailData['pay_type'] == 2) {
$vlaueDetailDatas[$key]['type'] = "充值";
$total += $valueDetailData['value'];
}
if ($valueDetailData['pay_type'] == 3) {
$vlaueDetailDatas[$key]['type'] = "平台发放";
$total += $valueDetailData['value'];
}
}
if (!empty($vlaueDetailDatas[0]['after_value'])) {
$totalAfterValue = number_format($vlaueDetailDatas[0]['after_value'],2,'.','');
}else {
$totalAfterValue = '0.00';
}
$total = number_format($total,2,'.','');
if($t >= 0 ) {
$fuhao = '+';
}else {
$fuhao = '';
}
$this->checkListOrCountAuthRestMap($map,[]);
$page = set_pagination($counts,$row);
if($page) {$this->assign('_page', $page);}
$this->assign('fuhao', $fuhao);
if(empty($_REQUEST['timestart']) && empty($_REQUEST['timeend']) && empty(I('user_account'))) {
$this->assign('starttime', $initBegTime);
$this->assign('endtime', $initEndTime);
}else {
$this->assign('starttime', $_REQUEST['timestart']);
$this->assign('endtime', $_REQUEST['endtime']);
}
$this->assign('total', $t);
$this->assign('listdata', $vlaueDetailDatas);
$this->assign('totalAfterValue', $totalAfterValue);
$this->display();
}
}