diff --git a/Application/Admin/Controller/MarketPerformanceSetController.class.php b/Application/Admin/Controller/MarketPerformanceSetController.class.php index 3c44e21b1..0cf9806bd 100644 --- a/Application/Admin/Controller/MarketPerformanceSetController.class.php +++ b/Application/Admin/Controller/MarketPerformanceSetController.class.php @@ -21,6 +21,7 @@ class MarketPerformanceSetController extends Controller { private $channelRatio; private $gameInfo; private $companyInfo; + private $marketUserInfo; private $settleupMarketorderModel; private $marketAltogetherModel; private $taxRatio; @@ -68,6 +69,8 @@ class MarketPerformanceSetController extends Controller { $this->getAllDownFlowSpend(); $this->getAllGameInfo(); $this->getCompanyOtherInfo(); + $this->getMarketUserInfo(); + $this->getPuStatement(); $this->getPuSpecialStatement(); $this->performanceSet(); @@ -163,19 +166,22 @@ class MarketPerformanceSetController extends Controller { "p.company_id"=>["NOT IN",$this->inSideCompanyIds], "p.company_belong"=>['GT',0] ]; + //测试 + // $where['p.company_id'] = 43; + $dbres = M("Spend","tab_") ->alias("s") ->field("substring_index(game_name, '(', 1) relation_game_name, SUM(pay_amount) pay_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") ->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(); foreach ($dbres as $v) { - if(!array_key_exists($v['relation_game_name'],$this->downFlowData[$v['company_id']])){ - $this->downFlowData[$v['company_id']][$v['relation_game_name']] = [ + if(!array_key_exists($v['relation_game_name'],$this->downFlowData[$v['company_id']][$v['market_admin_id']])){ + $this->downFlowData[$v['company_id']][$v['market_admin_id']][$v['relation_game_name']] = [ "cp_pay_amount"=>0, "promote_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); $cp_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['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['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']]['channel_amount'] += $channel_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['market_admin_id']][$v['relation_game_name']]['promote_pay_amount'] += $promote_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['market_admin_id']][$v['relation_game_name']]['refund_amount'] += $v['refund_amount']; } unset($dbres); } @@ -202,8 +208,10 @@ class MarketPerformanceSetController extends Controller { private function getAllGameInfo() { $games=[]; - foreach ( $this->downFlowData as $key => $value) { - $games = array_merge(array_keys($value),$games); + foreach ( $this->downFlowData as $key => $market) { + foreach ($market as $value) { + $games = array_merge(array_keys($value),$games); + } } $games = array_unique($games); //获取游戏信息 @@ -222,13 +230,25 @@ class MarketPerformanceSetController extends Controller { $companyIds = array_unique(array_keys($this->downFlowData)); $companyRes = M("promote_company","tab_")->alias("pc") ->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]) ->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; } + /** + * 获取市场员信息 + */ + 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']) ){ continue; } - if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']])){ - continue; - } - if($this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] == 0){ - $this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; + + $marketKeys = array_keys($this->downFlowData[$v['company_id']]); + foreach ($marketKeys as $marketId) { + if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']][$marketId])){ + 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']) ){ continue; } - if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']])){ - continue; - } - if($this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] == 0){ - $this->downFlowData[$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; + + $marketKeys = array_keys($this->downFlowData[$v['company_id']]); + foreach ($marketKeys as $marketId) { + if(!array_key_exists($val['game_name'],$this->downFlowData[$v['company_id']][$marketId])){ + 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) ){ 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() { - foreach ($this->downFlowData as $company_id => $games) { - $baseArr = $this->companyInfo[$company_id]; - $baseArr['pay_time'] = $this->date; - $baseArr['is_settlement'] = 1; - foreach ($games as $k => $v) { - // if($company_id == 452){ - // dd($v); - // } - $game = $this->gameInfo[$k]; - $cp_ratio = $game['cp_ratio']; - $tempArr = $baseArr; - $tempArr['game_id'] = $game['relation_game_id']; - $tempArr['relation_game_id'] = $game['relation_game_id']; - $tempArr['game_name'] = $k; - $tempArr['pay_amount'] = $v['pay_amount']; - $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['channel_amount'] = $v['channel_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_profit'] = $tempArr['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']-$tempArr['channel_amount']-$tempArr['company_tax']; - $tempArr['is_tip'] = 0; - if($this->oldMarketPerformance){ - 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'].''){ + foreach ($this->downFlowData as $company_id => $markerts) { + foreach ($markerts as $markertUserId => $games) { + $baseArr = $this->companyInfo[$company_id]; + $baseArr['pay_time'] = $this->date; + $baseArr['is_settlement'] = 1; + $baseArr['real_name'] = $this->marketUserInfo[$markertUserId]; + $baseArr['admin_id'] = $markertUserId; + foreach ($games as $k => $v) { + $game = $this->gameInfo[$k]; + $cp_ratio = $game['cp_ratio']; + $tempArr = $baseArr; + $tempArr['game_id'] = $game['relation_game_id']; + $tempArr['relation_game_id'] = $game['relation_game_id']; + $tempArr['game_name'] = $k; + $tempArr['pay_amount'] = $v['pay_amount']; + $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['channel_amount'] = $v['channel_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_profit'] = $tempArr['pay_amount']-$tempArr['cp_amount']-$tempArr['promote_amount']-$tempArr['channel_amount']-$tempArr['company_tax']; + $tempArr['is_tip'] = 0; + if($this->oldMarketPerformance){ + 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; + } } } + //下游流水不等于就要算毛利 + if($v['promote_pay_amount'] != 0){ + $this->adddata[]= $tempArr; + } + } - //下游流水不等于就要算毛利 - if($v['promote_pay_amount'] != 0){ - $this->adddata[]= $tempArr; - } - } + } } /**