Merge pull request 'feature/more_payment' (#418) from feature/more_payment into master

Reviewed-on: http://8.136.139.249:3000/wmtx/platform/pulls/418
master
廖金灵 4 years ago
commit 2c10246a4f

@ -21,6 +21,7 @@ class MarketPerformanceSetController extends Controller {
private $channelRatio; private $channelRatio;
private $gameInfo; private $gameInfo;
private $companyInfo; private $companyInfo;
private $marketUserInfo;
private $settleupMarketorderModel; private $settleupMarketorderModel;
private $marketAltogetherModel; private $marketAltogetherModel;
private $taxRatio; private $taxRatio;
@ -68,6 +69,8 @@ class MarketPerformanceSetController extends Controller {
$this->getAllDownFlowSpend(); $this->getAllDownFlowSpend();
$this->getAllGameInfo(); $this->getAllGameInfo();
$this->getCompanyOtherInfo(); $this->getCompanyOtherInfo();
$this->getMarketUserInfo();
$this->getPuStatement(); $this->getPuStatement();
$this->getPuSpecialStatement(); $this->getPuSpecialStatement();
$this->performanceSet(); $this->performanceSet();
@ -163,19 +166,22 @@ class MarketPerformanceSetController extends Controller {
"p.company_id"=>["NOT IN",$this->inSideCompanyIds], "p.company_id"=>["NOT IN",$this->inSideCompanyIds],
"p.company_belong"=>['GT',0] "p.company_belong"=>['GT',0]
]; ];
//测试
// $where['p.company_id'] = 43;
$dbres = M("Spend","tab_") $dbres = M("Spend","tab_")
->alias("s") ->alias("s")
->field("substring_index(game_name, '(', 1) relation_game_name, ->field("substring_index(game_name, '(', 1) relation_game_name,
SUM(pay_amount) pay_amount, SUM(pay_amount) pay_amount,
IFNULL(SUM(CASE WHEN is_refund = 1 THEN pay_amount ELSE 0 END),0) as refund_amount, IFNULL(SUM(CASE WHEN is_refund = 1 THEN pay_amount ELSE 0 END),0) as refund_amount,
p.company_id,p.company_belong,merchant_id") p.company_id,p.company_belong,merchant_id,market_admin_id")
->join("tab_promote as p on s.promote_id = p.id") ->join("tab_promote as p on s.promote_id = p.id")
->where($where) ->where($where)
->group("relation_game_name,company_id,merchant_id") ->group("relation_game_name,company_id,merchant_id,market_admin_id")
->order("pay_amount desc")->select(); ->order("pay_amount desc")->select();
foreach ($dbres as $v) { foreach ($dbres as $v) {
if(!array_key_exists($v['relation_game_name'],$this->downFlowData[$v['company_id']])){ if(!array_key_exists($v['relation_game_name'],$this->downFlowData[$v['company_id']][$v['market_admin_id']])){
$this->downFlowData[$v['company_id']][$v['relation_game_name']] = [ $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']] = [
"cp_pay_amount"=>0, "cp_pay_amount"=>0,
"promote_pay_amount"=>0, "promote_pay_amount"=>0,
"pay_amount"=>0, "pay_amount"=>0,
@ -188,11 +194,11 @@ class MarketPerformanceSetController extends Controller {
$channel_amount = round($v['pay_amount']*$this->channelRatio[$v['merchant_id']]/100,2); $channel_amount = round($v['pay_amount']*$this->channelRatio[$v['merchant_id']]/100,2);
$cp_amount = $v['pay_amount']-$v['refund_amount']; $cp_amount = $v['pay_amount']-$v['refund_amount'];
$promote_amount = $v['pay_amount']-$v['refund_amount']; $promote_amount = $v['pay_amount']-$v['refund_amount'];
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['channel_amount'] += $channel_amount; $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']]['channel_amount'] += $channel_amount;
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['cp_pay_amount'] += $cp_amount; $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']]['cp_pay_amount'] += $cp_amount;
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['promote_pay_amount'] += $promote_amount; $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']]['promote_pay_amount'] += $promote_amount;
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['pay_amount'] += $v['pay_amount']; $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']]['pay_amount'] += $v['pay_amount'];
$this->downFlowData[$v['company_id']][$v['relation_game_name']]['refund_amount'] += $v['refund_amount']; $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']]['refund_amount'] += $v['refund_amount'];
} }
unset($dbres); unset($dbres);
} }
@ -202,8 +208,10 @@ class MarketPerformanceSetController extends Controller {
private function getAllGameInfo() private function getAllGameInfo()
{ {
$games=[]; $games=[];
foreach ( $this->downFlowData as $key => $value) { foreach ( $this->downFlowData as $key => $market) {
$games = array_merge(array_keys($value),$games); foreach ($market as $value) {
$games = array_merge(array_keys($value),$games);
}
} }
$games = array_unique($games); $games = array_unique($games);
//获取游戏信息 //获取游戏信息
@ -222,13 +230,25 @@ class MarketPerformanceSetController extends Controller {
$companyIds = array_unique(array_keys($this->downFlowData)); $companyIds = array_unique(array_keys($this->downFlowData));
$companyRes = M("promote_company","tab_")->alias("pc") $companyRes = M("promote_company","tab_")->alias("pc")
->join("tab_promote as p on p.company_id = pc.id") ->join("tab_promote as p on p.company_id = pc.id")
->join("sys_member as m on p.admin_id = m.uid")
->where(['pc.id'=>['in',$companyIds],'p.level'=>1]) ->where(['pc.id'=>['in',$companyIds],'p.level'=>1])
->group("pc.id") ->group("pc.id")
->getField("pc.id company_id,pc.company_name,pc.company_belong,pc.develop_type,p.id promote_id,p.account promote_account,p.admin_id,m.real_name",TRUE); ->getField("pc.id company_id,pc.company_name,pc.company_belong,pc.develop_type,p.id promote_id,p.account promote_account",TRUE);
$this->companyInfo = $companyRes; $this->companyInfo = $companyRes;
} }
/**
* 获取市场员信息
*/
private function getMarketUserInfo()
{
$userid=[];
foreach ( $this->downFlowData as $key => $value) {
$userid = array_merge(array_keys($value),$userid);
}
$userid = array_unique($userid);
$this->marketUserInfo = M("member")->where(["uid"=>['in',$userid]])->getField("uid,real_name",true);
}
/** /**
* 获取下游结算比例,以最后一周的结算比例为最终比例 * 获取下游结算比例,以最后一周的结算比例为最终比例
*/ */
@ -300,11 +320,15 @@ class MarketPerformanceSetController extends Controller {
if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){ if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){
continue; continue;
} }
if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']])){
continue; $marketKeys = array_keys($this->downFlowData[$v['company_id']]);
} foreach ($marketKeys as $marketId) {
if($this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] == 0){ if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']][$marketId])){
$this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; continue;
}
if($this->downFlowData[$v['company_id']][$marketId][$val['game_name']]["ratio"] == 0){
$this->downFlowData[$v['company_id']][$marketId][$val['game_name']]["ratio"] = $val['ratio'];
}
} }
} }
} }
@ -339,11 +363,15 @@ class MarketPerformanceSetController extends Controller {
if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){ if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){
continue; continue;
} }
if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']])){
continue; $marketKeys = array_keys($this->downFlowData[$v['company_id']]);
} foreach ($marketKeys as $marketId) {
if($this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] == 0){ if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']][$marketId])){
$this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; continue;
}
if($this->downFlowData[$v['company_id']][$marketId][$val['game_name']]["ratio"] == 0){
$this->downFlowData[$v['company_id']][$marketId][$val['game_name']]["ratio"] = $val['ratio'];
}
} }
} }
} }
@ -369,7 +397,17 @@ class MarketPerformanceSetController extends Controller {
if( !array_key_exists($val['game_name'],$this->gameInfo) ){ if( !array_key_exists($val['game_name'],$this->gameInfo) ){
continue; continue;
} }
$this->downFlowData[$v['company_id']][$val['game_name']]["special_amount"] += $val['sum_money']; $marketKeys = array_keys($this->downFlowData[$v['company_id']]);
$isMoreUser = count($marketKeys) > 1 ? true :false;
// dd($isMoreUser);
foreach ($marketKeys as $marketId) {
if($isMoreUser){
$sum_money = round($this->downFlowData[$v['company_id']][$marketId][$val['game_name']]['pay_amount']/$val['pay_amount']*$val['sum_money'],2);
}else{
$sum_money = $val['sum_money'];
}
$this->downFlowData[$v['company_id']][$marketId][$val['game_name']]["special_amount"] += $sum_money;
}
} }
} }
} }
@ -425,43 +463,45 @@ class MarketPerformanceSetController extends Controller {
*/ */
private function performanceSet() private function performanceSet()
{ {
foreach ($this->downFlowData as $company_id => $games) { foreach ($this->downFlowData as $company_id => $markerts) {
$baseArr = $this->companyInfo[$company_id]; foreach ($markerts as $markertUserId => $games) {
$baseArr['pay_time'] = $this->date; $baseArr = $this->companyInfo[$company_id];
$baseArr['is_settlement'] = 1; $baseArr['pay_time'] = $this->date;
foreach ($games as $k => $v) { $baseArr['is_settlement'] = 1;
// if($company_id == 452){ $baseArr['real_name'] = $this->marketUserInfo[$markertUserId];
// dd($v); $baseArr['admin_id'] = $markertUserId;
// } foreach ($games as $k => $v) {
$game = $this->gameInfo[$k]; $game = $this->gameInfo[$k];
$cp_ratio = $game['cp_ratio']; $cp_ratio = $game['cp_ratio'];
$tempArr = $baseArr; $tempArr = $baseArr;
$tempArr['game_id'] = $game['relation_game_id']; $tempArr['game_id'] = $game['relation_game_id'];
$tempArr['relation_game_id'] = $game['relation_game_id']; $tempArr['relation_game_id'] = $game['relation_game_id'];
$tempArr['game_name'] = $k; $tempArr['game_name'] = $k;
$tempArr['pay_amount'] = $v['pay_amount']; $tempArr['pay_amount'] = $v['pay_amount'];
$tempArr['cp_amount'] = round($v['cp_pay_amount']*$cp_ratio/100,2); $tempArr['cp_amount'] = round($v['cp_pay_amount']*$cp_ratio/100,2);
$tempArr['promote_amount'] = round($v['promote_pay_amount']*$v['ratio']/100+$v['special_amount'],2); $tempArr['promote_amount'] = round($v['promote_pay_amount']*$v['ratio']/100+$v['special_amount'],2);
$tempArr['channel_amount'] = $v['channel_amount']; $tempArr['channel_amount'] = $v['channel_amount'];
$tempArr['refund_amount'] = $v['refund_amount']; $tempArr['refund_amount'] = $v['refund_amount'];
$tempArr['company_tax'] = round( ($v['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']) * ($this->taxRatio / 100),2 ); $tempArr['company_tax'] = round( ($v['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']) * ($this->taxRatio / 100),2 );
$tempArr['company_profit'] = $tempArr['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']-$tempArr['channel_amount']-$tempArr['company_tax']; $tempArr['company_profit'] = $tempArr['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']-$tempArr['channel_amount']-$tempArr['company_tax'];
$tempArr['is_tip'] = 0; $tempArr['is_tip'] = 0;
if($this->oldMarketPerformance){ if($this->oldMarketPerformance){
if(!array_key_exists($company_id,$this->oldMarketPerformance) || !array_key_exists($k,$this->oldMarketPerformance[$company_id])){ if(!array_key_exists($company_id,$this->oldMarketPerformance) || !array_key_exists($k,$this->oldMarketPerformance[$company_id])){
$tempArr['is_tip'] = 1;
}else{
if($this->oldMarketPerformance[$company_id][$k]['company_profit'] != $tempArr['company_profit'].''){
$tempArr['is_tip'] = 1; $tempArr['is_tip'] = 1;
}else{
if($this->oldMarketPerformance[$company_id][$k]['company_profit'] != $tempArr['company_profit'].''){
$tempArr['is_tip'] = 1;
}
} }
} }
//下游流水不等于就要算毛利
if($v['promote_pay_amount'] != 0){
$this->adddata[]= $tempArr;
}
} }
//下游流水不等于就要算毛利
if($v['promote_pay_amount'] != 0){
$this->adddata[]= $tempArr;
}
} }
} }
} }
/** /**

Loading…
Cancel
Save