From 380243dbb87ea95b8393fc8d5b73669038cdcb49 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Thu, 28 May 2020 11:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=93=E7=AE=97=E7=9A=84?= =?UTF-8?q?=E8=A1=A5=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompanyStatementSetController.class.php | 209 ++++++++++++------ 1 file changed, 145 insertions(+), 64 deletions(-) diff --git a/Application/Admin/Controller/CompanyStatementSetController.class.php b/Application/Admin/Controller/CompanyStatementSetController.class.php index 54596f491..640a26862 100644 --- a/Application/Admin/Controller/CompanyStatementSetController.class.php +++ b/Application/Admin/Controller/CompanyStatementSetController.class.php @@ -63,43 +63,33 @@ class CompanyStatementSetController extends Controller { if($w == 1){ echo $nowdate.":".PHP_EOL; echo "--周结begin".PHP_EOL; - $this->cpStatement(0,$stime); + // $this->cpStatement(0,$stime); + $this->promoteCompanyStatement(0,$stime); + } if($d == 1){ echo $nowdate.":".PHP_EOL; echo "--月结&补点begin".PHP_EOL; - $this->cpStatement(1,$stime); + // $this->cpStatement(1,$stime); // $this->cpStatement(2,$stime); + + $this->promoteCompanyStatement(1,$stime); } }else{ echo $nowdate."非周一和月初,无需任何处理".PHP_EOL; } } /** - * TODO:以下为上下游结算 + * TODO:渠道费未进行计算 * 上游结算 * @param [string] $type 0:周结 1:月结 2:周结补点 */ public function cpStatement($type,$stime) { - if($type == 0){ - $begintime = mktime(0,0,0,date('m',$stime),date('d',$stime)-7,date('Y',$stime)); - $endtime = mktime(0,0,0,date('m',$stime),date('d',$stime),date('Y',$stime))-1; - }else{ - $thismonth = date('m',$stime); - $thisyear = date('Y',$stime); - if ($thismonth == 1) { - $lastmonth = 12; - $lastyear = $thisyear - 1; - } else { - $lastmonth = $thismonth - 1; - $lastyear = $thisyear; - } - $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; - $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); - $begintime = strtotime($lastStartDay);//上个月的月初时间戳 - $endtime = strtotime($lastEndDay)+24*3600-1;//上个月的月末时间戳 - } + $t = setBeginAndEndTime($type); + $begintime = $t[0]; + $endtime = $t[1]; + //获取哪些要结算 if($type == 1){ $cpDbRes = M("CompanyRelation","tab_")->where("settlement_type = 2 AND (first_company_type = '1' OR second_company_type = '1')")->select(); @@ -123,7 +113,7 @@ class CompanyStatementSetController extends Controller { $cp_id = implode(",",array_flip(array_flip(array_keys($cpList)))); $js_id = implode(",",array_unique($js_id)); //获取cp公司 - $tmpp = M("Partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where(["id"=>['in',$cp_id]])->select(); + $tmpp = M("Partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank,channel_rate,invoice_rate")->where(["id"=>['in',$cp_id]])->select(); $cp =[]; foreach ($tmpp as $v) { $cp[$v['id']]=$v; @@ -213,6 +203,10 @@ class CompanyStatementSetController extends Controller { $add_data['verify_log'] = $verify_log; $add_data['op_time'] =time(); $add_data['statement_info'] =[]; + //获取渠道及发票税率 + $promote_ratio = $cp[$add_data['company_id']]['channel_rate'] ?? 0; + $fax_ratio = $cp[$add_data['company_id']]['invoice_rate'] ?? 0; + //游戏统计 foreach($v['list'] as $ke=>$va){ $game =[]; $game['pay_amount'] =$va['pay_money']; @@ -226,10 +220,15 @@ class CompanyStatementSetController extends Controller { }else{ //获取比例 $game['relation_game_id']=$game_id['relation_game_id']; - if($type > 0){ + if($type == 1){ $tratio = getGameCpRadio($game_id['id'],$va['pay_money'],true); - }else{ + }elseif($type == 0){ $tratio = getGameCpRadio($game_id['id'],$va['pay_money'],false); + }else{ + //补丁 + $tratio1 = getGameCpRadio($game_id['id'],$va['pay_money'],true); + $tratio2 = getGameCpRadio($game_id['id'],$va['pay_money'],false); + $tratio = $tratio1-$tratio2; } } @@ -242,58 +241,65 @@ class CompanyStatementSetController extends Controller { } $add_data['pay_amount'] += $va['pay_money']; - $game['sum_money']=round($va['pay_money']*$tratio/100,2); + $game['sum_money']=round($va['pay_money']*(100-$promote_ratio)*$tratio*(100-$fax_ratio)/100*100*100,2);//结算金额=平台总额*(1-渠道费)*分成比例*(1-税费费率) $add_data['statement_money'] += $game['sum_money']; - $game['fax_ratio']=0; - $game['promote_ratio']=0; + $game['fax_ratio']=$fax_ratio; + $game['promote_ratio']=$promote_ratio; + $game['statement_begin_time']=$statement_begin_time; $game['statement_end_time']=$statement_end_time; $game['statement_type']=0; $add_data['statement_info'][] = $game; } $add_data['platform_amount'] = $add_data['pay_amount']; - //奖罚 - $rrmap = array( - "reward_time" => ['between', [$begintime,$endtime]], - "company_type"=>1, - "company_id"=>$add_data['company_id'] - ); - $rfres = M("RewardRecord","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 - ") - ->where($rrmap)->find(); - if($rfres['reward_count'] > 0){ - $reward_count = $rfres['reward_count']; - $add_data['statement_info'][] = array( - "statement_begin_time"=>$statement_begin_time, - "statement_end_time"=>$statement_end_time, - 'statement_type'=>2, - "game_name"=>"奖励", - 'pay_amount'=>$reward_count, - 'sum_money'=>$reward_count, - ); - $add_data['statement_money']+=$reward_count; - $add_data['pay_amount']+=$reward_count; - } - if($rfres['fine_count'] > 0){ - $fine_count = $rfres['fine_count']; - $add_data['statement_info'][] = array( - "statement_begin_time"=>$statement_begin_time, - "statement_end_time"=>$statement_end_time, - 'statement_type'=>1, - "game_name"=>"罚款", - 'pay_amount'=>$fine_count, - 'sum_money'=>$fine_count, + if($type < 2){ + //非补点奖罚 + $rrmap = array( + "reward_time" => ['between', [$begintime,$endtime]], + "company_type"=>1, + "company_id"=>$add_data['company_id'] ); - $add_data['statement_money'] -= $fine_count; - $add_data['pay_amount'] -= $fine_count;; + $rfres = M("RewardRecord","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 + ") + ->where($rrmap)->find(); + if($rfres['reward_count'] > 0){ + $reward_count = $rfres['reward_count']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>2, + "game_name"=>"奖励", + 'pay_amount'=>$reward_count, + 'sum_money'=>$reward_count, + ); + $add_data['statement_money']+=$reward_count; + $add_data['pay_amount']+=$reward_count; + } + if($rfres['fine_count'] > 0){ + $fine_count = $rfres['fine_count']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"罚款", + 'pay_amount'=>$fine_count, + 'sum_money'=>$fine_count, + ); + $add_data['statement_money'] -= $fine_count; + $add_data['pay_amount'] -= $fine_count;; + } } - + $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); + if($type == 2 && $add_data['statement_money'] == 0){ + //金额为0不补点 + continue; + } //添加 $StatementDb->add($add_data); } @@ -348,7 +354,82 @@ class CompanyStatementSetController extends Controller { } return $cplList; } + /** + * 下游结算 + */ + public function promoteCompanyStatement($type,$stime) + { + + $t = setBeginAndEndTime($type); + $begintime = $t[0]; + $endtime = $t[1]; + //获取哪些要结算 + if($type == 1){ + $pcDbRes = M("CompanyRelation","tab_")->where("settlement_type = 2 AND (first_company_type = '2' OR second_company_type = '2')")->select(); + }else{ + $pcDbRes = M("CompanyRelation","tab_")->where("settlement_type = 1 AND (first_company_type = '2' OR second_company_type = '2')")->select(); + } + + $pcList=[]; + $js_id = [];//己方公司 + foreach ($pcDbRes as $k => $v) { + if($v['first_company_type'] == 2){ + $pcList[$v['first_company_id']] =$v; + $js_id[] =$v['second_company_id']; + }else{ + $pcList[$v['second_company_id']] =$v; + $js_id[] =$v['first_company_id']; + } + + } + $pc_id = implode(",",array_flip(array_flip(array_keys($pcList)))); + $js_id = implode(",",array_unique($js_id)); + if(count($js_id) ==0 || count($pcList) == 0){ + //无需处理 + return ; + } + //获取cp公司 + $tmpp = M("PromoteCompany","tab_")->field("id,company_name partner,settlement_contact link_man,contact_phone link_phone,address,bank_address opening_bank,bank_card bank_account")->where(["id"=>['in',$pc_id]])->select(); + $pc =[]; + foreach ($tmpp as $v) { + $pc[$v['id']]=$v; + } + unset($tmpp); + //获取己方公司 + $our = []; + $tmpp = M("CompanyInfo","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where(["id"=>['in',$js_id]])->select(); + foreach ($tmpp as $v) { + $our[$v['id']]=$v; + } + unset($tmpp); + unset($js_id); + dump($pc); + dd($our); + + } + //设定开始结束时间 + protected function setBeginAndEndTime($type){ + if($type == 0){ + $begintime = mktime(0,0,0,date('m',$stime),date('d',$stime)-7,date('Y',$stime)); + $endtime = mktime(0,0,0,date('m',$stime),date('d',$stime),date('Y',$stime))-1; + }else{ + $thismonth = date('m',$stime); + $thisyear = date('Y',$stime); + if ($thismonth == 1) { + $lastmonth = 12; + $lastyear = $thisyear - 1; + } else { + $lastmonth = $thismonth - 1; + $lastyear = $thisyear; + } + $lastStartDay = $lastyear . '-' . $lastmonth . '-1'; + $lastEndDay = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)); + $begintime = strtotime($lastStartDay);//上个月的月初时间戳 + $endtime = strtotime($lastEndDay)+24*3600-1;//上个月的月末时间戳 + } + return [$begintime,$endtime]; + } }