@ -21,7 +21,8 @@ class FinancialSummarySetController extends \Think\Controller
//初始化
$this->beginThismonth = mktime(0,0,0,date('m')-1,1,date('Y'));
$this->endThismonth = mktime(0,0,0,date('m'),1,date('Y'))-1;
$temp = strtotime(date('Y-m-01 00:00:00',strtotime('-1 month')));
$temp = strtotime(date('Y',time()).'-'.(date('m',time())-1).'-01');
$this->year= date('Y',$temp);
$this->month= date('m',$temp);
$this->date = $this->year."-".$this->month;
@ -32,7 +33,7 @@ class FinancialSummarySetController extends \Think\Controller
$this->SpendModel = M("Spend",'tab_');
$this->GameSupersignModel = M("GameSupersign",'tab_');
$this->CoinPayOrderModel = M("CoinPayOrder",'tab_');//会长充值平台币表
$this->TestOrderModel = M("TestOrder",'tab_');//测试订单录入
}
/**
@ -52,6 +53,7 @@ class FinancialSummarySetController extends \Think\Controller
$this->month= $tarry[1];
$this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]);
$this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1;
$this->reCount();
$this->setFinancialSummary();
}
@ -85,16 +87,23 @@ class FinancialSummarySetController extends \Think\Controller
if($countRes > 0){
die("error:Repeated statistics,msg:{$this->date}已经聚合过");
}
//按收入类型
echo "{$this->date}开始统计".PHP_EOL;
echo "--收入类型统计中".PHP_EOL;
$this->setIncomeMoney();
//按合作方类型
echo "--合作方类型统计中".PHP_EOL;
$this->setPromoteMoney();
//支付渠道/支付类型
$this->setPayWayMoney();
//按支付商户
//
echo "--支付渠道统计中".PHP_EOL;
$this->setChannelMoney();
echo "--支付类型统计中".PHP_EOL;
$this->setPaywayMoney();
echo "--支付商户统计中".PHP_EOL;
$this->setMerchantMoney();
//存入数据
echo "--数据保存".PHP_EOL;
$this->addDb();
$t2 = microtime(true);
@ -116,7 +125,7 @@ class FinancialSummarySetController extends \Think\Controller
{
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"payed _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
);
$res = $this->SpendModel
@ -145,7 +154,7 @@ class FinancialSummarySetController extends \Think\Controller
"sort"=>3,
);
$map = array(
"create _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"payed _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
);
$temparr['sum_money'] = $this->DepositModel->field("IFNULL(sum(pay_amount),0) pay_amount")->where($map)->find()['pay_amount'];
@ -190,7 +199,7 @@ class FinancialSummarySetController extends \Think\Controller
}
//获取现金充值
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"payed _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1,
"pay_way"=>array("GT",0)
);
@ -201,24 +210,31 @@ class FinancialSummarySetController extends \Think\Controller
->find()['pay_amount'];
//获取平台币充值
$map1 = array(
"create _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"payed _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
);
if($testlist) $map1['user_id']=array("in",$testlist);
$deposit = $this->DepositModel->field("IFNULL(sum(pay_amount),0) pay_amount")->where($map1)->find()['pay_amount'];
$temparr['sum_money'] = number_format(($cash_spend*100+$deposit*100)/100, 2, '.', '');
//测试订单录入
$map2 = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth))
);
$test_pay_amount = $this->TestOrderModel->where($map2)->field("IFNULL(sum(pay_amount),0) pay_amount")->find()['pay_amount'];
$temparr['sum_money'] = number_format(($cash_spend*100 + $deposit*100 + $test_pay_amount*100 )/100, 2, '.', '');
$this->adddata[]=$temparr;
}
//奖罚收入
protected function getRewardRecordIncome()
{
$map = array(
"reward_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"confirm _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
);
$rrres = M("RewardRecord ","tab_")
$rrres = M("RewardDetail ","tab_")
->field("
IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count,
IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count
IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward_count,
IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine_count
")
->where($map)
->find();
@ -242,7 +258,7 @@ class FinancialSummarySetController extends \Think\Controller
public function setPromoteMoney()
{
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"payed _time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
);
$res = $this->SpendModel
@ -326,159 +342,174 @@ class FinancialSummarySetController extends \Think\Controller
"sum_money"=>number_format($other_group_nobind_count/100, 2, '.', '')
);
}
/**
* 获取类型为4,5的数据/按支付渠道类型,支付类型类型
*/
public function setPayWayMoney()
{
$moneyarry=[
"wx"=>0,
"zfb"=>0,
"gfzfb"=>0,
"sqzfb"=>0,
"sqkj"=>0,
"ybzf"=>0,
];
$this->getSpendPayWay($moneyarry);
$this->getGameSupersignPayWay($moneyarry);
$this->getDepositPayWay($moneyarry);
$this->getCoinPayOrderPayWay($moneyarry);
//统计数据
$moneyarry['zfb'] = ($moneyarry['gfzfb']-0+$moneyarry['sqzfb']);
$this->adddata[] = array(
"key_name"=>'gfwx_count',
"type"=>4,"sort"=>1,
"sum_money"=>number_format($moneyarry['wx']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'gfzfb_count',
"type"=>4,"sort"=>2,
"sum_money"=>number_format($moneyarry['gfzfb']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'sqzfb_count',
"type"=>4,"sort"=>3,
"sum_money"=>number_format($moneyarry['sqzfb']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'sqkj_count',
"type"=>4,"sort"=>4,
"sum_money"=>number_format($moneyarry['sqkj']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'wx_count',
"type"=>5,"sort"=>1,
"sum_money"=>number_format($moneyarry['wx']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'zfb_count',
"type"=>5,"sort"=>2,
"sum_money"=>number_format($moneyarry['zfb']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'kj_count',
"type"=>5,"sort"=>3,
"sum_money"=>number_format($moneyarry['sqkj']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'ybzf_count',
"type"=>4,"sort"=>5,
"sum_money"=>number_format($moneyarry['ybzf']/100, 2, '.', '')
);
$this->adddata[] = array(
"key_name"=>'ybzf_count',
"type"=>5,"sort"=>4,
"sum_money"=>number_format($moneyarry['ybzf']/100, 2, '.', '')
);
echo 'success';
public function setChannelMoney(){
$Channel = $this->getChannelCount($Channel);
foreach( $Channel as $k=>$v){
$this->adddata[] = array(
"key_name"=>$k,
"type"=>4,
"sort"=>$k,
"sum_money"=>number_format($v, 2, '.', '')
);
}
}
//获取spend表
protected function getSpendPayWay(& $moneyarry ){
//获取Channel
protected function getChannelCount(){
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1,
"pay_way"=>array("IN","1,2,3,9,15,17")
"s.payed_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.pay_status"=>1,
"s.merchant_id"=>["GT","0"]
);
$dbres=$this->SpendModel
->field("
IFNULL(SUM(CASE WHEN pay_way = 2 THEN pay_amount ELSE 0 END),0) as wxsm_count,
IFNULL(SUM(CASE WHEN pay_way = 3 THEN pay_amount ELSE 0 END),0) as wxapp_count,
IFNULL(SUM(CASE WHEN pay_way = 1 THEN pay_amount ELSE 0 END),0) as zfbgf_count,
IFNULL(SUM(CASE WHEN pay_way = 9 THEN pay_amount ELSE 0 END),0) as zfbsq_count,
IFNULL(SUM(CASE WHEN pay_way = 15 THEN pay_amount ELSE 0 END),0) as kjsq_count,
IFNULL(SUM(CASE WHEN pay_way = 17 THEN pay_amount ELSE 0 END),0) as ybzf_count
")
$spres=$this->SpendModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,p.channel")
->where($map)
->find();
$moneyarry['wx'] += ($dbres['wxsm_count']*100+$dbres['wxapp_count']*100);
$moneyarry['gfzfb'] += $dbres['zfbgf_count']*100;
$moneyarry['sqzfb'] += $dbres['zfbsq_count']*100;
$moneyarry['sqkj'] += $dbres['kjsq_count']*100;
$moneyarry['ybzf'] += $dbres['ybzf_count']*100;
->group("p.channel")
->join("left join tab_payment_merchant p ON p.id = s.merchant_id")
->select();
//超级签
$ss_map = [
"s.pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.pay_status"=>1
];
$ssres=$this->GameSupersignModel
->alias("s")
->field("SUM(s.pay_price) pay_amount,p.channel")
->join("left join tab_payment_merchant p ON p.id = s.merchant_id")
->group("p.channel")
->where($ss_map)
->select();
//玩家购买平台币
$dp_map =[
"s.payed_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.pay_status"=>1
];
$dpres=$this->DepositModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,p.channel")
->join("left join tab_payment_merchant p ON p.id = s.merchant_id")
->group("p.channel")
->where($dp_map)
->select();
//会长充值平台币
$co_map =[
"s.pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.order_status"=>array("EGT",1)
];
$cores=$this->CoinPayOrderModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,p.channel")
->join("left join tab_payment_merchant p ON p.id = s.merchant_id")
->group("p.channel")
->where($co_map)
->select();
//测试的订单
$to_map =[
"s.pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.merchant_id"=>["GT","0"]
];
$tores=$this->TestOrderModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,p.channel")
->join("left join tab_payment_merchant p ON p.id = s.merchant_id")
->group("p.channel")
->where($to_map)
->select();
$dbres = array_merge($spres,$ssres,$dpres,$cores,$tores);
$Channel = [];
foreach ($dbres as $k=>$v){
$Channel["c".$v['channel']] += $v['pay_amount'];
}
return $Channel;
}
//获取超级签购买
protected function getGameSupersignPayWay(& $moneyarry)
{
$map = array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1
);
$dbres=$this->GameSupersignModel
->field("
IFNULL(SUM(CASE WHEN pay_way = 2 THEN pay_price ELSE 0 END),0) as wx_count,
IFNULL(SUM(CASE WHEN pay_way = 1 THEN pay_price ELSE 0 END),0) as zfb_count,
IFNULL(SUM(CASE WHEN pay_way = 17 THEN pay_price ELSE 0 END),0) as ybzf_count
")
->where($map)
->find();
$moneyarry['wx'] += $dbres['wx_count']*100;
$moneyarry['gfzfb'] += $dbres['zfb_count']*100;
$moneyarry['ybzf'] += $dbres['ybzf_count']*100;
public function setPaywayMoney(){
$Ways = $this->getPaywayCount();
foreach($Ways as $k=>$v){
$this->adddata[] = array(
"key_name"=>$k,
"type"=>5,
"sort"=>$k,
"sum_money"=>number_format($v, 2, '.', '')
);
}
}
//玩家购买平台币
protected function getDepositPayWay(& $moneyarry)
{
//获取Channel
protected function getPaywayCount(){
$map = array(
"create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"pay_status"=>1,
"pay_way"=>array("IN","1,2,3,9,15,17")
"s.payed_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.pay_status"=>1,
"s.merchant_id"=>["GT","0"]
);
$dbres=$this->DepositModel
->field("
IFNULL(SUM(CASE WHEN pay_way = 2 THEN pay_amount ELSE 0 END),0) as wxsm_count,
IFNULL(SUM(CASE WHEN pay_way = 3 THEN pay_amount ELSE 0 END),0) as wxapp_count,
IFNULL(SUM(CASE WHEN pay_way = 1 THEN pay_amount ELSE 0 END),0) as zfbgf_count,
IFNULL(SUM(CASE WHEN pay_way = 9 THEN pay_amount ELSE 0 END),0) as zfbsq_count,
IFNULL(SUM(CASE WHEN pay_way = 15 THEN pay_amount ELSE 0 END),0) as kjsq_count,
IFNULL(SUM(CASE WHEN pay_way = 17 THEN pay_amount ELSE 0 END),0) as ybzf_count
")
$spres=$this->SpendModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,s.merchant_way")
->where($map)
->find();
$moneyarry['wx'] += ($dbres['wxsm_count']*100+$dbres['wxapp_count']*100);
$moneyarry['gfzfb'] += $dbres['zfbgf_count']*100;
$moneyarry['sqzfb'] += $dbres['zfbsq_count']*100;
$moneyarry['sqkj'] += $dbres['kjsq_count']*100;
$moneyarry['ybzf'] += $dbres['ybzf_count']*100;
}
//会长充值平台币
protected function getCoinPayOrderPayWay(& $moneyarry)
{
$map= array(
"pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"order_status"=>array("EGT",1)
);
$dbres= $this->CoinPayOrderModel
->field("
IFNULL(SUM(CASE WHEN pay_way = 2 THEN pay_amount ELSE 0 END),0) as wx_count,
IFNULL(SUM(CASE WHEN pay_way = 1 THEN pay_amount ELSE 0 END),0) as zfb_count,
IFNULL(SUM(CASE WHEN pay_way = 17 THEN pay_amount ELSE 0 END),0) as ybzf_count
")
->where($map)
->find();
$moneyarry['wx'] += $dbres['wx_count']*100;
$moneyarry['gfzfb'] += $dbres['zfb_count']*100;
$moneyarry['ybzf'] += $dbres['ybzf_count']*100;
->group("s.merchant_way")
->select();
//超级签
$ss_map = [
"s.pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.pay_status"=>1
];
$ssres=$this->GameSupersignModel
->alias("s")
->field("SUM(s.pay_price) pay_amount,s.merchant_way")
->group("s.merchant_way")
->where($ss_map)
->select();
//玩家购买平台币
$dp_map =[
"s.payed_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.pay_status"=>1
];
$dpres=$this->DepositModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,s.merchant_way")
->group("s.merchant_way")
->where($dp_map)
->select();
//会长充值平台币
$co_map =[
"s.pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.order_status"=>array("EGT",1)
];
$cores=$this->CoinPayOrderModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,s.merchant_way")
->group("s.merchant_way")
->where($co_map)
->select();
//测试的订单
$to_map =[
"s.pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)),
"s.merchant_id"=>["GT","0"]
];
$tores=$this->TestOrderModel
->alias("s")
->field("SUM(s.pay_amount) pay_amount,s.merchant_way")
->group("s.merchant_way")
->where($to_map)
->select();
$dbres = array_merge($spres,$ssres,$dpres,$cores,$tores);
$Ways = [];
foreach ($dbres as $k=>$v){
$Ways["w".$v['merchant_way']] += $v['pay_amount'];
}
return $Ways;
}
public function addDb()
{
foreach ($this->adddata as $k=> & $v) {
@ -513,13 +544,13 @@ class FinancialSummarySetController extends \Think\Controller
->select(false);
//平台币充值金额计算
$coinData = M('pay_info ','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("left join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info .user_id")
$coinData = M('deposit ','tab_')
// ->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("left join tab_test_white_list on tab_test_white_list.user_id=tab_deposit .user_id")
->join("left join tab_payment_merchant merchant on merchant.id=tab_deposit.merchant_id")
->field("0 cash_amount,SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null and pay_source=0 THEN pay_amount ELSE 0 END) as coin_amount,
0 offcial_amount,0 spread_amount,0 supersign_amount,0 test_order_amount,merchant_id,name,channel,identifier,payed_time,game_id,main_name,merchant_way,merchant.account")
->field("0 cash_amount,SUM(CASE WHEN merchant.id is not null and pay_source=2 and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null and pay_source=2 THEN pay_amount ELSE 0 END) as coin_amount,
0 offcial_amount,0 spread_amount,0 supersign_amount,0 test_order_amount,merchant_id,name,channel,identifier,payed_time,0 game_id,main_name,merchant_way,merchant.account")
->where(['pay_status'=>1,'tab_deposit.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id")
@ -528,8 +559,8 @@ class FinancialSummarySetController extends \Think\Controller
$officalData = M('deposit','tab_')
->join("left join tab_test_white_list on tab_test_white_list.user_id=tab_deposit.user_id")
->join("left join tab_payment_merchant merchant on merchant.id=tab_deposit.merchant_id")
->field("0 cash_amount,SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
0 as coin_amount,SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null and pay_source=2 THEN pay_amount ELSE 0 END) as offcial_amount,
->field("0 cash_amount,SUM(CASE WHEN merchant.id is not null and pay_source=0 and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
0 as coin_amount,SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null and pay_source=0 THEN pay_amount ELSE 0 END) as offcial_amount,
0 spread_amount,0 supersign_amount,0 test_order_amount,merchant_id,name,channel,identifier,payed_time,0 as game_id,main_name,merchant_way,merchant.account")
->where(['pay_status'=>1,'tab_deposit.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)