From db28185af3970384ba19970a36b156ae2815db31 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Fri, 18 Jun 2021 16:21:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=AF=9B=E5=88=A9=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/GameMarginController.class.php | 2 +- .../GameMarginSetController.class.php | 140 +++++++++++------- 2 files changed, 87 insertions(+), 55 deletions(-) diff --git a/Application/Admin/Controller/GameMarginController.class.php b/Application/Admin/Controller/GameMarginController.class.php index 062412a04..86b4b3317 100644 --- a/Application/Admin/Controller/GameMarginController.class.php +++ b/Application/Admin/Controller/GameMarginController.class.php @@ -200,7 +200,7 @@ class GameMarginController extends AdminController $v["jh_margin_ratio"] = "=ROUND(Y{$line}/V{$line},3)"; } - $v['margin_amount'] = "=ROUND((D{$line}-G{$line}-I{$line}-J{$line}-M{$line}-R{$line}+X{$line}),2)"; + $v['margin_amount'] = "=ROUND((D{$line}-G{$line}-I{$line}-J{$line}-M{$line}-R{$line}-(V{$line}}-X{$line})),2)"; $v['margin_ratio'] = "=ROUND(AB{$line}/D{$line},3)"; $v['count_year'] = $date['count_year']; $v['count_month'] = $date['count_month']; diff --git a/Application/Admin/Controller/GameMarginSetController.class.php b/Application/Admin/Controller/GameMarginSetController.class.php index 9b9b9a8ce..96319cd4b 100644 --- a/Application/Admin/Controller/GameMarginSetController.class.php +++ b/Application/Admin/Controller/GameMarginSetController.class.php @@ -17,12 +17,11 @@ class GameMarginSetController extends Controller { private $year;//年份 private $adddata;//要添加的数据 private $inSideCompanyIds; - private $debugGame=false; - private $debugStr=''; + private $downFlowData; /** * 更新某月数据 */ - public function setFreeMonth($count_date,$debug_game=false) + public function setFreeMonth($count_date) { //设置转换精度 ini_set('serialize_precision',14); @@ -38,8 +37,6 @@ class GameMarginSetController extends 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->debugGame=$debug_game; - $this->reCount(); $this->setGameMargin(); } @@ -62,16 +59,19 @@ class GameMarginSetController extends Controller { private function setGameMargin() { $this->getInsideCompanyid(); + //获取所有下游支付信息 + $this->getAllDownFlowSpend(); $this->getAllGameSpend(); $this->getJuheStatement(); $this->getCpStatement(); $this->getPuStatement(); $this->getPcStatement(); + //计算内外团数据 + $this->setDownFlowCount(); + //3.特殊补点 + $this->getPuSpecialStatement(); $this->setMarginCount(); - if($this->debugGame){ - $str = $this->debugGame . PHP_EOL."公司名称,团体归属,时间,流水,分成". $this->debugStr . PHP_EOL; - echo $str; - } + echo "{$this->year}-{$this->month}生成成功".PHP_EOL; } /** @@ -88,6 +88,33 @@ class GameMarginSetController extends Controller { } $this->inSideCompanyIds = implode(",",$res); } + //获取期间下游公司游戏流水 + private function getAllDownFlowSpend() + { + $where = [ + "pay_status"=>1, + "is_refund"=>0, + "is_check"=>1, + "payed_time"=>["between",[$this->beginThismonth,$this->endThismonth]], + "p.company_id"=>["NOT IN",$this->inSideCompanyIds] + ]; + $dbres = M("Spend","tab_") + ->alias("s") + ->field("substring_index(game_name, '(', 1) relation_game_name,SUM(pay_amount) pay_amount,p.company_id,p.company_belong") + ->join("tab_promote as p on s.promote_id = p.id") + ->where($where) + ->group("relation_game_name,company_id") + ->order("pay_amount desc")->select(); + foreach ($dbres as $v) { + if($v['company_belong'] > 0){ + $v['company_belong'] = 1; + }else{ + $v['company_belong'] = 0; + } + $this->downFlowData[$v['company_belong']][$v['company_id']][$v['relation_game_name']]['pay_amount'] = $v['pay_amount']; + } + unset($dbres); + } //获取期间所有有流水的游戏 private function getAllGameSpend() { @@ -149,7 +176,7 @@ class GameMarginSetController extends Controller { "company_type"=>2, "withdraw_type"=>0 ]; - $statement_pool = M("company_statement_pool","tab_")->where($where)->order("statement_begin_time asc")->select(); + $statement_pool = M("company_statement_pool","tab_")->where($where)->order("statement_begin_time desc")->select(); //获取结算分段 $date_arr = []; foreach ($statement_pool as $k => $v) { @@ -158,18 +185,15 @@ class GameMarginSetController extends Controller { "statement_end_time"=>$v['statement_end_time'], "begin_time"=>date("Y.m.d",$v['statement_begin_time']), "end_time"=>date("Y.m.d",$v['statement_end_time']), - "recount"=>false, "withdraw_type"=>0 ]; if($v['statement_begin_time'] < $this->beginThismonth){ $tem['statement_begin_time'] = $this->beginThismonth; $tem['begin_time'] = date("Y.m.d",$this->beginThismonth); - $tem['recount'] = true; } if($v['statement_end_time'] > $this->endThismonth){ $tem['statement_end_time'] = $this->endThismonth; $tem['end_time'] = date("Y.m.d",$this->endThismonth); - $tem['recount'] = true; } $this->getPuAllStatement($tem,$v); $this->getPuCompanyStatement($tem);//对公周结 @@ -181,13 +205,10 @@ class GameMarginSetController extends Controller { "statement_end_time"=>$this->endThismonth, "begin_time"=>date("Y.m.d",$this->beginThismonth), "end_time"=>date("Y.m.d",$this->endThismonth), - "recount"=>false, "withdraw_type"=>1 ]; $this->getPuCompanyStatement($tem); - //3.特殊补点 - $this->getPuSpecialStatement(); - + } /** * 获取所有个人周结 @@ -215,22 +236,11 @@ class GameMarginSetController extends Controller { if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){ continue; } - if($time['recount']){ - $pay_amount = $this->getPuGameSpend($va['account'],$val['game_name']."(",$time['statement_begin_time'],$time['statement_end_time']); - $val['sum_money'] = round($pay_amount/$val['pay_amount']*$val['sum_money'],2); - $val['pay_amount'] = $pay_amount; - } - if( array_key_exists("pu_pay_amount",$this->adddata[$val['game_name']]) ){ - $this->adddata[$val['game_name']]['pu_pay_amount'] += $val['pay_amount']; - $this->adddata[$val['game_name']]['pu_statement_amount'] += $val['sum_money']; - - }else{ - - $this->adddata[$val['game_name']]['pu_pay_amount'] = $val['pay_amount']; - $this->adddata[$val['game_name']]['pu_statement_amount'] = $val['sum_money']; + if(!array_key_exists($val['game_name'],$this->downFlowData[1][$v['company_id']])){ + continue; } - if($this->debugGame && $this->debugGame == $val['game_name']){ - $this->debugStr .= (PHP_EOL."{$v['company_name']},外团,{$time['begin_time']}-{$time['end_time']},{$val['pay_amount']},{$val['sum_money']}"); + if(!array_key_exists("ratio",$this->downFlowData[1][$v['company_id']][$val['game_name']])){ + $this->downFlowData[1][$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; } } } @@ -290,21 +300,12 @@ class GameMarginSetController extends Controller { if( ($val['statement_begin_time'] != $time['begin_time']) && ($val['statement_end_time'] != $time['end_time']) ){ continue; } - if($time['recount']){ - $pay_amount = $this->getPuCompanyGameSpend($v['company_id'],$val['game_name']."(",$time['statement_begin_time'],$time['statement_end_time']); - $val['sum_money'] = round($pay_amount/$val['pay_amount']*$val['sum_money'],2); - $val['pay_amount'] = $pay_amount; - } - if( array_key_exists("pu_pay_amount",$this->adddata[$val['game_name']]) ){ - $this->adddata[$val['game_name']]['pu_pay_amount'] += $val['pay_amount']; - $this->adddata[$val['game_name']]['pu_statement_amount'] += $val['sum_money']; - }else{ - $this->adddata[$val['game_name']]['pu_pay_amount'] = $val['pay_amount']; - $this->adddata[$val['game_name']]['pu_statement_amount'] = $val['sum_money']; - } - if($this->debugGame && $this->debugGame == $val['game_name']){ - $this->debugStr .= (PHP_EOL."{$v['company_name']},外团,{$time['begin_time']}-{$time['end_time']},{$val['pay_amount']},{$val['sum_money']}"); + if(!array_key_exists($val['game_name'],$this->downFlowData[1][$v['company_id']])){ + continue; + } + if(!array_key_exists("ratio",$this->downFlowData[1][$v['company_id']][$val['game_name']])){ + $this->downFlowData[1][$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; } } } @@ -399,7 +400,7 @@ class GameMarginSetController extends Controller { return [$OPName]; } } - //获取下游内团 + //获取下游内团,未计算下游内团周结算 private function getPcStatement() { $where = [ @@ -418,17 +419,48 @@ class GameMarginSetController extends Controller { if( !array_key_exists($val['game_name'],$this->adddata) ){ continue; } - if( array_key_exists("pc_pay_amount",$this->adddata[$val['game_name']]) ){ - $this->adddata[$val['game_name']]['pc_pay_amount'] += $val['pay_amount']; - $this->adddata[$val['game_name']]['pc_statement_amount'] += $val['sum_money']; - }else{ - $this->adddata[$val['game_name']]['pc_pay_amount'] = $val['pay_amount']; - $this->adddata[$val['game_name']]['pc_statement_amount'] = $val['sum_money']; + + if(!array_key_exists($val['game_name'],$this->downFlowData[0][$v['company_id']])){ + continue; + } + if(!array_key_exists("ratio",$this->downFlowData[1][$v['company_id']][$val['game_name']])){ + $this->downFlowData[0][$v['company_id']][$val['game_name']]["ratio"] = $val['ratio']; } } } } } + private function setDownFlowCount() + { + $insideGroup = $this->downFlowData[0]; + $outGroup = $this->downFlowData[1]; + foreach ($insideGroup as $companyId => $gameList) { + foreach ($gameList as $gameName => $v) { + $v['sum_money'] = round($v['pay_amount']*$v['ratio']/100,2); + if( array_key_exists("pc_pay_amount",$this->adddata[$gameName]) ){ + $this->adddata[$gameName]['pc_pay_amount'] += $v['pay_amount']; + $this->adddata[$gameName]['pc_statement_amount'] += $v['sum_money']; + }else{ + $this->adddata[$gameName]['pc_pay_amount'] = $v['pay_amount']; + $this->adddata[$gameName]['pc_statement_amount'] = $v['sum_money']; + } + } + } + + foreach ($outGroup as $companyId => $gameList) { + foreach ($gameList as $gameName => $v) { + $v['sum_money'] = round($v['pay_amount']*$v['ratio']/100,2); + if( array_key_exists("pu_pay_amount",$this->adddata[$gameName]) ){ + $this->adddata[$gameName]['pu_pay_amount'] += $v['pay_amount']; + $this->adddata[$gameName]['pu_statement_amount'] += $v['sum_money']; + }else{ + $this->adddata[$gameName]['pu_pay_amount'] = $v['pay_amount']; + $this->adddata[$gameName]['pu_statement_amount'] = $v['sum_money']; + } + } + } + + } //相关属性计算 private function setMarginCount() { @@ -484,7 +516,7 @@ class GameMarginSetController extends Controller { $v["jh_margin_ratio"] = round($v["jh_margin_amount"]/$v['jh_pay_amount'],3)*100; } - $v['margin_amount'] = round( ($v['pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount']+$v['jh_statement_amount']),2); + $v['margin_amount'] = round( ($v['pay_amount']-$v['cp_statement_amount']-$v['cp_rebate_amount']-$v['cp_other_amount']-$v['pc_statement_amount']-$v['pu_statement_amount']-( $v['jh_pay_amount'] - $v['jh_statement_amount'] )),2); $v['margin_ratio'] = round($v['margin_amount']/$v['pay_amount'],3)*100; $pay_amount += $v['pay_amount'];