From b75bcdbb1c30d60100b8f0f8309e966d4b24e4d8 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Tue, 23 Feb 2021 20:56:36 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8A=E6=B8=B8?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/Common/extend.php | 77 + .../CompanyStatementController.class.php | 17 +- ...SubCompanyStatementSetController.class.php | 2436 +++++++++++++++++ .../CompanyStatement/subViewCpStatement.html | 273 ++ Public/Admin/excel/sub_up_stream.xls | Bin 0 -> 20480 bytes 5 files changed, 2800 insertions(+), 3 deletions(-) create mode 100644 Application/Admin/Controller/SubCompanyStatementSetController.class.php create mode 100644 Application/Admin/View/CompanyStatement/subViewCpStatement.html create mode 100644 Public/Admin/excel/sub_up_stream.xls diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index 1d51bcf8d..a6c55550c 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -2001,6 +2001,83 @@ function excelUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_ } +//子站上游cp对账单导出 +function excelSubUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money) { + header("Content-type: text/html; charset=utf-8"); + error_reporting(E_ALL); + ini_set('display_errors', TRUE); + ini_set('display_startup_errors', TRUE); + + define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
'); + + Vendor("PHPExcel.PHPExcel"); + $objReader = \PHPExcel_IOFactory::createReader('Excel5'); + + //设置模板文件 + $objPHPExcel = $objReader->load("Public/Admin/excel/sub_up_stream.xls"); + //增加甲方信息 + $objPHPExcel->getActiveSheet()->setCellValue('D2', $data['first_party_info']['partner']); + $objPHPExcel->getActiveSheet()->setCellValue('D3', $data['first_party_info']['link_man']); + $objPHPExcel->getActiveSheet()->setCellValue('D4', $data['first_party_info']['link_phone']."\t"); + $objPHPExcel->getActiveSheet()->setCellValue('D5', $data['first_party_info']['address']); + $objPHPExcel->getActiveSheet()->setCellValue('D6', $data['first_party_info']['company_tax_no']); + + //增加乙方信息 + $objPHPExcel->getActiveSheet()->setCellValue('J2', $data['second_party_info']['partner']); + $objPHPExcel->getActiveSheet()->setCellValue('J3', $data['second_party_info']['link_man']); + $objPHPExcel->getActiveSheet()->setCellValue('J4', $data['second_party_info']['link_phone']."\t"); + $objPHPExcel->getActiveSheet()->setCellValue('J5', $data['second_party_info']['address']); + $objPHPExcel->getActiveSheet()->setCellValue('J6', $data['second_party_info']['company_tax_no']." "); + + $objPHPExcel->getActiveSheet()->setCellValue('C7', "支付给:".$data['receive_company']['partner']); //增加支付给对应公司 + $line = 9; + //记录统计项目 + $pay_amount_str = "=SUM(J9:"; + $plat_amount_str = "=SUM(E9:"; + $listCount = count($data['statement_info']); + $listLineMax = $line+$listCount-1; + $objPHPExcel->getActiveSheet()->insertNewRowBefore($line,$listCount)->mergeCells("F$line:G{$listLineMax}")->mergeCells("H$line:I{$listLineMax}")->mergeCells("J$line:K{$listLineMax}"); + + //增加结算记录 + foreach ($data['statement_info'] as $key => $value) { + if($line == 9){ + //初始行 + $objPHPExcel->getActiveSheet()->setCellValue('F'.$line, $value['promote_ratio'] . '%')->setCellValue('H'.$line, $value['fax_ratio'] . '%')->setCellValue('J'.$line, $all_pay_amount); + } + $objPHPExcel->getActiveSheet()->mergeCells("D$line:E{$line}"); + $objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['statement_begin_time'].'-'.$value['statement_end_time']); + if ($value['statement_type'] > 0) { + + } else { + $product_name = $value['game_name']; + $objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $product_name); + } + + + $line++; + } + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line), "=J9"); //本月分成总金额(人民币大写) + //收款方 + $objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+1), $data['receive_company']['payee_name']); + $objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+2), $data['receive_company']['bank_account']."\t"); + $objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+3), $data['receive_company']['opening_bank']); + //付款方 + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+1), $data['pay_company']['payee_name']); + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+2), $data['pay_company']['bank_account']."\t"); + $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+3), $data['pay_company']['opening_bank']); + + $statement_begin_time = date('Y.m.d', $data['statement_begin_time']);//对账开始时间 + $statement_end_time = date('Y.m.d',$data['statement_end_time']);//对账截止时间 + $fileName = "{$data['company_name']}&{$data['my_company']}-对账单{$statement_begin_time}-{$statement_end_time}"; + ob_end_clean();//清除缓冲区,避免乱码 + header('pragma:public'); + header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls'); + header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印 + $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); + $objWriter->save('php://output'); + exit; +} + //下游工会对账单导出 function excelSpecialComplementEmplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money) { diff --git a/Application/Admin/Controller/CompanyStatementController.class.php b/Application/Admin/Controller/CompanyStatementController.class.php index cb3ad059a..bf2499d0e 100644 --- a/Application/Admin/Controller/CompanyStatementController.class.php +++ b/Application/Admin/Controller/CompanyStatementController.class.php @@ -284,14 +284,20 @@ class CompanyStatementController extends ThinkController "first_party_info"=>$first_party_info, "second_party_info"=>$second_party_info, "statement_info"=>$statement_info, - "statement_count"=>array("pay_amount"=>$dbres['pay_amount'],"statement_money"=>$dbres['statement_money'],"big_ratio_money"=>convertAmountToCn($dbres['statement_money'])) + "statement_count"=>array("pay_amount"=>$dbres['pay_amount'],"list_count"=>count($statement_info),"statement_money"=>$dbres['statement_money'],"big_ratio_money"=>convertAmountToCn($dbres['statement_money'])) ); $this->assign("data",$senddata); + // dd($senddata); if($dbres["company_belong"] == 9){ //上游 - $this->display("viewCpStatement"); + if(!IS_SUBSITE){ + $this->display("viewCpStatement"); + }else{ + $this->display("subViewCpStatement"); + } + }else{ if ($dbres["withdraw_type"] == 3) { if($dbres["company_type"] == 1){ @@ -562,7 +568,12 @@ class CompanyStatementController extends ThinkController } if ($data['company_belong'] == 9) {//上游 - excelUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money); + if(!IS_SUBSITE){ + excelUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money); + }else{ + excelSubUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money); + } + } else { //下游 // if($dbres["company_type"] == 1){ diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php new file mode 100644 index 000000000..9fbce7e8c --- /dev/null +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -0,0 +1,2436 @@ +"周结", + "1"=>"月结", + "2"=>"补点" + ]; + public $token = "LYHTQDJS"; + + public function _initialize(){ + $cpapihost = M("Kv")->field("value")->where("`key` = 'aggregate_cp_settlement_api'")->find(); + + if(empty($cpapihost)){ + echo "请先设置请求接口aggregate_cp_settlement_api的值".PHP_EOL;die; + } + $this->cpapihost = $cpapihost['value']; + } + /** + * Undocumented function + * + * @param [type] $begin 开始时间 2020-04-01 + * @param string $end 结束时间,默认今天 + * @param string $company all/pc/cp/pu 全部 下游公司 上游 下游个人 + * @return void + */ + public function setFreeDateCount($begin,$end='',$company='all') + { + if($end == '') $end = $begin; + //判断日期格式 + $patten = "/^\d{4}[\-](0?[1-9]|1[012])[\-](0?[1-9]|[12][0-9]|3[01])$/"; + if (!preg_match($patten, $begin)) { + die("开始时间格式错误"); + } + if (!preg_match($patten, $end)) { + die("结束时间格式错误"); + } + if(strtotime($end) < strtotime($begin)){ + die("结束时间不能比开始时间小"); + } + if(strtotime($end)+86399-24*3600 > time()){ + die("结束时间不能大于当前"); + } + + $starttime = $begin?strtotime($begin):mktime(0,0,0,date('m'),date('d'),date('Y')); + $endtime = $end?strtotime($end)+86399:$starttime+86399; + $datelist = get_date_list($starttime,$endtime,1); + $countdate = count($datelist); + for($i=0;$i<$countdate;$i++){ + $this->setDailyCount($datelist[$i],$company); + } + } + public function setDailyCount($stime="now",$company='all') + { + if(!IS_CLI){ + die("只支持脚本访问"); + } + if($stime=="now"){ + $stime=time(); + }else{ + $stime = strtotime($stime); + } + $nowdate = date("Y-m-d",$stime); + $w = (int)date("w",$stime); + $d = (int)date("d",$stime); + + if($w == 1 || $d == 1){ + if($w == 1){ + if($company == "all"){ + echo $nowdate.":".PHP_EOL; + echo "--周结begin".PHP_EOL; + + $this->cpStatement(0,$stime); + echo "∟----CP周结统计ok".PHP_EOL; + + $this->promoteCompanyStatement(0,$stime); + echo "∟----推广公司周结统计ok".PHP_EOL; + if(!IS_SUBSITE){ + $this->promoteUserPool(0,$stime); + echo "∟----推广个人周结ok".PHP_EOL; + } + + } + if($company == "cp"){ + $this->cpStatement(0,$stime); + echo "∟----CP周结统计ok".PHP_EOL; + } + if($company == "pc"){ + $this->promoteCompanyStatement(0,$stime); + echo "∟----推广公司周结统计ok".PHP_EOL; + } + if($company == "pu"){ + $this->promoteUserPool(0,$stime); + echo "∟----推广个人周结ok".PHP_EOL; + } + + } + if($d == 1){ + if($company == "all"){ + echo $nowdate.":".PHP_EOL; + echo "--月结&补点begin".PHP_EOL; + + $this->cpStatement(1,$stime); + $this->cpStatement(2,$stime); + echo "∟----CP月结&补点统计ok".PHP_EOL; + + $this->promoteCompanyStatement(1,$stime); + $this->promoteCompanyStatement(2,$stime); + $this->officeCompanyStatement($stime); //官方结算 + echo "∟----官方/推广公司月结&补点统计ok".PHP_EOL; + if(!IS_SUBSITE){ + $this->promoteUserPool(1,$stime); + $this->promoteUserPool(2,$stime); + echo "∟----推广个人月结&补点统计ok".PHP_EOL; + } + } + if($company == "cp"){ + $this->cpStatement(1,$stime); + $this->cpStatement(2,$stime); + echo "∟----CP月结&补点统计ok".PHP_EOL; + } + if($company == "pc"){ + $this->promoteCompanyStatement(1,$stime); + $this->promoteCompanyStatement(2,$stime); + $this->officeCompanyStatement($stime); //官方结算 + echo "∟----官方/推广公司月结&补点统计ok".PHP_EOL; + } + if($company == "pu"){ + $this->promoteUserPool(1,$stime); + $this->promoteUserPool(2,$stime); + echo "∟----推广个人月结&补点统计ok".PHP_EOL; + } + } + }else{ + echo $nowdate."非周一和月初,无需任何处理".PHP_EOL; + } + } + /** + * 上游结算 + * @param [string] $type 0:周结 1:月结 2:周结补点 + */ + public function cpStatement($type,$stime,$company_id=false,$recount=true) + { + $t = $this->setBeginAndEndTime($type,$stime);; + $begintime = $t[0]; + $endtime = $t[1]; + if($company_id === false){ + //非重算 + $where = [ + "_string"=>"first_company_type = '1' OR second_company_type = '1'" + ]; + }else{ + $where = [ + "_string"=>"(first_company_type = '1' AND first_company_id in ({$company_id}) ) OR (second_company_type = '1' AND second_company_id in ({$company_id}) )" + ]; + } + //获取哪些要结算 + if($type == 1){ + $where['settlement_type']=2; + $cpDbRes = M("CompanyRelation","tab_")->where($where)->select(); + }else{ + $where['settlement_type']=1; + $cpDbRes = M("CompanyRelation","tab_")->where($where)->select(); + } + + $cpList=[]; + $js_id = [];//己方公司 + foreach ($cpDbRes as $k => $v) { + if($v['first_company_type'] == 1){ + $cpList[$v['first_company_id']] =$v; + $js_id[] =$v['second_company_id']; + }else{ + $cpList[$v['second_company_id']] =$v; + $js_id[] =$v['first_company_id']; + } + + } + if(count($js_id) ==0 || count($cpList) == 0){return ;} + + $cp_id = implode(",",array_flip(array_flip(array_keys($cpList))));//已绑定关系 + $js_id = implode(",",array_unique($js_id)); + //获取cp公司 + $cpmap = [ + "id"=>['in',$cp_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}" + ]; + $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,taxation_rate,company_type,ali_user,ali_account,has_advance_charge,has_server_fee,server_fee")->where($cpmap)->select(); + if(empty($tmpp)){ + return true; + } + $cp =[]; + foreach ($tmpp as $v) { + $cp[$v['id']]=$v; + } + $cp_id = implode(",",array_column($tmpp,"id")); //结算的id + 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); + //获取本地数据 + $locals = $this->getLocalStatementData($begintime,$endtime,$cp_id); + //获取聚合数据 + $sign = md5($begintime.$endtime."1".$this->token); + $arr = [ + "begintime"=>$begintime, + "endtime"=>$endtime, + "type"=>1, + "sign"=>$sign, + "cp_id"=>$cp_id + ]; + $dataurl .= $this->cpapihost."&".http_build_query($arr); + $html = file_get_contents($dataurl); + //防止并发压力 + sleep(3); + $rsp = json_decode($html,true); + if($rsp['code'] != 1){ + echo $rsp['error'].PHP_EOL;die; + }else{ + $rsp = $rsp['data']; + } + //整合数据本地 + + foreach($locals as $k=>$v){ + $cpList[$k]["list"] = $v["list"]; + } + //整合数据,聚合 + foreach($rsp as $k=>$v){ + + if(isset($cpList[$k]["list"])){ + //已经存在 + foreach($rsp[$k]["list"] as $ke=>$va){ + if(isset($cpList[$k]["list"][$ke])){ + $cpList[$k]["list"][$ke]['pay_money'] += $va['pay_money']; + $cpList[$k]["list"][$ke]['aggregate_money'] += $va['pay_money']; + }else{ + $va['aggregate_money'] = $va['pay_money']; + $va['platform_money'] = 0; + $cpList[$k]["list"][$ke] = $va; + } + } + }else{ + $cpList[$k]["list"] = $v["list"]; + } + + } + //比例计算及保存 + // TODO:此处不判断现游戏名=原包名,但却不是同一款游戏 + $verify_log=json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]); + $GameDb = M("Game","tab_"); + $StatementDb = SM("CompanyStatement","tab_"); + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); + foreach($cpList as $k=>$v){ + $add_data=[]; + $handleed_data = []; + //1.获取甲乙方信息 + if($v['first_company_type'] == 1){ + //甲方上游 + $cp[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; + $cp[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; + + $add_data['first_party_info'] = json_encode($cp[$v['first_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['second_party_info'] = json_encode($our[$v['second_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['company_id'] = $v['first_company_id']; + $add_data['company_name'] = $v['first_company_name']; + + }else{ + //乙方上游 + $cp[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; + $cp[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; + + $add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['second_party_info'] = json_encode($cp[$v['second_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['company_id'] = $v['second_company_id']; + $add_data['company_name'] = $v['second_company_name']; + } + $add_data['pay_type'] = $v['collection']; + $add_data['withdraw_type'] = $type; + $add_data['statement_begin_time'] = $begintime; + $add_data['statement_end_time'] = $endtime; + $add_data['statement_money'] = 0; + $add_data['pay_amount'] = 0; + $add_data['verify_log'] = $verify_log; + $add_data['op_time'] =time(); + $add_data['statement_info'] =[]; + $add_data['company_belong']=9;//上游 + $add_data['company_type']=$cp[$add_data['company_id']]['company_type']; + $add_data['is_payment']=$v['is_payment']; + //获取渠道及税费费率 + $promote_ratio = $cp[$add_data['company_id']]['channel_rate'] ?? 0; + $fax_ratio = $cp[$add_data['company_id']]['taxation_rate'] ?? 0; + //游戏统计 + if (isset($v['list'])) { + foreach ($v['list'] as $ke=>$va) { + $game =[]; + $game['pay_amount'] =$va['pay_money']; + $game['aggregate_amount'] =$va['aggregate_money']??0; + $game['other_amount'] = 0; + $game['platform_amount'] = $va['platform_money']??0; + + $game['game_name'] =$ke; + //获取游戏id及比例 + $game_id = $GameDb->where("relation_game_name='{$ke}' OR original_package_name='{$ke}'")->field("id,relation_game_id")->find(); + if (empty($game_id) && isset($va['unique_code']) && !empty($va['unique_code'])) { + $unique_code = $va['unique_code']; + $game_id = $GameDb->where("unique_code='{$unique_code }'")->field("id,relation_game_id")->find(); + } + if (empty($game_id)) { + $game['relation_game_id']=0; + $tratio = 0; + } else { + //获取比例 + $game['relation_game_id']=$game_id['relation_game_id']; + if ($type == 1) { + $tratio = getGameCpRadio($game_id['id'], $va['pay_money'], true); + } 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; + if ($tratio <= 0) { + continue; + } + } + } + $game['tratio'] = $tratio-0;; + if ($v['first_company_type'] == 1) { + $game['first_ratio']=$tratio-0; + $game['second_ratio']=100-$tratio; + } else { + $game['first_ratio']=100-$tratio; + $game['second_ratio']=$tratio-0; + } + $add_data['pay_amount'] += $va['pay_money']; + + $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']=$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; + + $RewardRecordRes = $this->getPromoteUserGameRewardRecordCp($add_data['company_id'],$statement_begin_time,$statement_end_time); + + if ( + ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') + || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') + ) { + $game['fine'] = 0; + $game['reward'] = 0; + } else { + $game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; + $game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; + } + + $add_data['statement_info'][] = $game; + } + }else{ + $add_data['statement_info'] = []; + } + $add_data['platform_amount'] = $add_data['pay_amount']; + if($type < 2){ + //非补点奖罚 + $rrmap = array( + "confirm_time" => ['between', [$begintime,$endtime]], + "company_type"=>1, + "company_id"=>$add_data['company_id'], + "settlement_type"=>2, + ); + $rfres = M("RewardDetail","tab_") + ->field(" + 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($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;; + } + //获取服务器费用 + $tmp_company_info= $cp[$add_data['company_id']]; + if($tmp_company_info['has_server_fee'] == 1 && $tmp_company_info['server_fee'] >0){ + $server_count = $tmp_company_info['server_fee']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"服务器费用", + 'pay_amount'=>$server_count, + 'sum_money'=>$server_count, + ); + $add_data['statement_money'] -= $server_count; + $add_data['pay_amount'] -= $server_count;; + } + } + $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); + if($type == 2 && $add_data['statement_money'] == 0){ + //金额为0不补点 + continue; + } + if($add_data['platform_amount'] == 0 && $add_data['statement_money'] == 0){ + //全等于0表示没有流水,小于0依旧要结算 + continue; + } + //添加 + if($recount && $company_id !== false){ + //非重算 + return $add_data; + } + //TODO: 这里需要获取联运结算的信息 + $StatementDb->add($add_data); + } + } + + /** + * 获取本地上游结算 + */ + public function getLocalStatementData($begintime,$endtime,$cp_id) + { + $game_where = "partner_id in ({$cp_id})"; + $game = M('game','tab_'); + $gameDbRes = $game->field("id,relation_game_name as game_name,partner_id as cp_id,original_package_name,select_package_name")->where($game_where)->select(); + $gameList=[]; + foreach ($gameDbRes as $k => $v) { + $gameList[$v['id']] =$v; + } + //获取所有id + $gmstr = implode(",",array_flip(array_flip(array_column($gameDbRes,'id')))); + //获取支付记录 + $paywhere = [ + "pay_status"=>1, + "pay_game_status"=>1, + "payed_time"=>["BETWEEN",[$begintime,$endtime]], + "game_id"=>["in",$gmstr] + ]; + D("Spend")->addSubsiteWhere($paywhere); + $paydb = M('spend','tab_'); + $paylist = $paydb->field("game_id,SUM(pay_amount) pay_amount")->where($paywhere)->group("game_id")->select(); + if(empty($paylist)){ + return []; + } + //绑定价格 + foreach ($paylist as $k => $v) { + $gameList[$v['game_id']]['pay_money'] =$v["pay_amount"]; + } + unset($paylist); + //按游戏名称及cp整理数据 + $cplList = []; + foreach ($gameList as $k => $v) { + if($v['pay_money'] <= 0) continue; //0值不发送 + if(empty($v['original_package_name'])){ + $game_name = $v['game_name']; + }else{ + if($v['select_package_name'] == 0){ + $game_name = $v['original_package_name']; + }else{ + $game_name = $v['game_name']; + } + } + $cp_id = $v['cp_id']; + unset($v['cp_id']); + $ymoney = $cplList[$cp_id]['list'][$game_name]["pay_money"]?:0; + $cplList[$cp_id]['list'][$game_name]["pay_money"] =$ymoney+$v["pay_money"]; + $cplList[$cp_id]['list'][$game_name]["platform_money"] = $cplList[$cp_id]['list'][$game_name]["pay_money"]; + $cplList[$cp_id]['list'][$game_name]["aggregate_money"] = 0; + } + return $cplList; + } + //官方结算 + public function officeCompanyStatement($stime,$recount=false) + { + + $t = $this->setBeginAndEndTime(1,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + //获取官方信息 + $pc_map = [ + "id"=>["IN",$pc_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}", + "company_type"=>1 + ]; + //获取pc公司 + $company = M("CompanyInfo","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where("partner = '海南万盟天下科技有限公司'")->find(); + $first_party_info = json_encode($company,JSON_UNESCAPED_UNICODE); + $company['partner'] = C("OFFICIEL_CHANNEL"); + $second_party_info = json_encode($company,JSON_UNESCAPED_UNICODE); + $add_data=[ + "first_party_info"=>$first_party_info, + "second_party_info"=>$second_party_info, + "pay_type"=>2, + "withdraw_type"=>1, + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + "statement_money"=>0, + "pay_amount"=>0, + "platform_amount"=>0, + "verify_log"=>json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]), + "op_time"=>time(), + "is_payment"=>2, + "statement_info"=>[], + "company_belong"=>0, + "company_name"=>C("OFFICIEL_CHANNEL"), + "company_id"=>0, + "company_type"=>1 + ]; + + //获取渠道及发票税率 + $fax_ratio = 0; //税费费率 + $company_belong = 0; + + + + $Promote = M("Promote","tab_"); + $Spend = M("Spend","tab_"); + $spenMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]], + "s.promote_id"=>0 + ]; + D("Spend")->addSubsiteWhere($spenMap,"s"); + $list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('relation_game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + if(empty($list)){return;} + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); + + foreach ($list as $k => $v) { + $v['fax_ratio'] = 0; + $v['statement_begin_time']=$statement_begin_time; + $v['statement_end_time']=$statement_end_time; + $v['ratio']=0; + $v['sum_money'] = 0; + $v['statement_type']=0; + + $add_data['platform_amount'] += $v['pay_amount']; + $add_data['pay_amount'] += $v['pay_amount']; + $add_data['statement_info'][] = $v; + } + $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); + if($recount){ + //非重算 + return $add_data; + } + SM("CompanyStatement","tab_")->add($add_data); + } + + /** + * 下游结算 + */ + public function promoteCompanyStatement($type,$stime,$company_id=false,$recount=true) + { + $t = $this->setBeginAndEndTime($type,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + + if($company_id === false){ + //非重算 + $where = [ + "_string"=>"first_company_type = '2' OR second_company_type = '2'" + ]; + }else{ + $where = [ + "_string"=>"(first_company_type = '2' AND first_company_id in ({$company_id}) ) OR (second_company_type = '2' AND second_company_id in ({$company_id}) )" + ]; + } + //获取哪些要结算 + if($type == 1){ + $where['settlement_type']=2; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + }else{ + $where['settlement_type']=1; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->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 ; + } + $pc_map = [ + "id"=>["IN",$pc_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}", + "company_type"=>1 + ]; + //获取pc公司 + $tmpp = M("PromoteCompany","tab_")->field("id,uid,company_name partner,settlement_contact link_man,address,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio") + ->where($pc_map) + ->select(); +// dump($tmpp); + if(empty($tmpp)){ + return true; + } + $pc =[]; + $Promote = M("Promote","tab_"); + foreach ($tmpp as $v) { + // //获取会长的支付宝账号 + // $p_map = [ + // "company_id"=>$v['id'], + // "withdraw_done"=>1 + // ]; + // $pres = $Promote->field("alipay_account,alipay_real_name")->where($p_map)->find(); + // if(!empty($pres) && !empty($pres['alipay_account']) && !empty($pres['alipay_real_name'])){ + // $v['ali_user'] = $pres['alipay_real_name']; + // $v['ali_account'] = $pres['alipay_account']; + // } + if($v['has_ratio']){ + $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); + } + $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); + + $this->getPromoteCompanySpend($pcList,array_unique(array_keys($pcList)),$begintime,$endtime); + + //数据整合 + $verify_log=json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]); + $StatementDb = SM("CompanyStatement","tab_"); + + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); + $RewardRecord = M("RewardDetail","tab_"); + foreach($pcList as $k=>$v){ + if(!isset($pc[$k])){continue;}//不存在的公司不结算 + if($pc[$k]['has_ratio'] == 1){ + $company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']); + }else{ + $company_ratio = 0; + } + $add_data=[]; + //1.获取甲乙方信息 + if($v['first_company_type'] > 0){ + //甲方合作 + $pc[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; + $pc[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; + + $add_data['first_party_info'] = json_encode($pc[$v['first_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['second_party_info'] = json_encode($our[$v['second_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['company_id'] = $v['first_company_id']; + $add_data['company_name'] = $v['first_company_name']; + + }else{ + //乙方合作 + $pc[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; + $pc[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; + $add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['second_party_info'] = json_encode($pc[$v['second_company_id']],JSON_UNESCAPED_UNICODE); + $add_data['company_id'] = $v['second_company_id']; + $add_data['company_name'] = $v['second_company_name']; + } + $add_data['pay_type'] = $v['collection']; + $add_data['withdraw_type'] = $type; + $add_data['statement_begin_time'] = $begintime; + $add_data['statement_end_time'] = $endtime; + $add_data['statement_money'] = 0; + $add_data['pay_amount'] = 0; + $add_data['verify_log'] = $verify_log; + $add_data['op_time'] =time(); + $add_data['is_payment']=$v['is_payment']; + $add_data['statement_info'] =[]; + + //获取渠道及发票税率 + $fax_ratio = $pc[$add_data['company_id']]['taxation_rate'] ?? 0; //税费费率 + $company_belong = $pc[$add_data['company_id']]['company_belong']; + $add_data['company_belong']=$company_belong; + $add_data['company_type']=$pc[$add_data['company_id']]['company_type']; + + if(!isset($v['game_list'])){continue;} + //获取多段比例 + $game_ratio_list = D("CompanyGameRatio")->getPromoteCompanyGameRatio($add_data['company_id'],$v['game_ids'],$begintime,$endtime,$company_belong); + + $handleed_data = []; + + foreach ($game_ratio_list as $t_game_id => $t_game_ratio) { + $game =[]; + $game['game_name'] =$v['game_list'][$t_game_id]['game_name']; + $game['relation_game_id'] =$v['game_list'][$t_game_id]['relation_game_id']; + if(isset($v['game_list'][$t_game_id]['all_pay_amount'])){ + $game_all_payment = $v['game_list'][$t_game_id]['all_pay_amount']-0; + }else{ +// $game_all_payment = $v['game_list'][$t_game_id]['pay_amount']-0; + $game_all_payment = $v['game_list'][$t_game_id]['ratio_pay_amount']-0; + } + + // dump($tratio); + $game['fax_ratio']=$fax_ratio-0; + + $game['statement_type']=0; + + if(count($t_game_ratio) == 1){ + $tmp_game_ratio = $t_game_ratio[0]; + + $game['pay_amount'] =$this->getRelationGameIdSpend($add_data['company_id'],$t_game_id,$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); + +// $game['pay_amount'] = $v['game_list'][$t_game_id]['pay_amount']; + $game['pay_amount'] -=0; + + $game['statement_begin_time']=$statement_begin_time; + $game['statement_end_time']=$statement_end_time; + $add_data['pay_amount'] += $game['pay_amount']; + + if($type == 1){ + $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio += $company_ratio; + +// if ($add_data['company_id'] == 5) { +// dump($game_all_payment); +// dump($this->getTurnoverType($t_game_id,$k,$begintime,$endtime)); +// dump($tmp_game_ratio); +// } + + }elseif($type == 0){ +// $tratio = $tmp_game_ratio['ratio']; + $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); + + if ($turnover_type == 2 || $turnover_type == 4) { + $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + } else { + $tratio = $tmp_game_ratio['ratio']; + } + }else{ + //补点 + $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); + if ($turnover_type == 2 || $turnover_type == 4) { + continue; + } + $tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio2 =$tmp_game_ratio['ratio']; + $tratio = $tratio1-$tratio2+$company_ratio; + if($tratio <= 0){ continue;} + } + if($v['type'] == 2){ + $game['increment_ratio']=$tratio; + }else{ + $game['ratio']=$tratio; + } + + $RewardRecordRes = $this->getPromoteUserGameRewardRecord($add_data['company_id'],$statement_begin_time,$statement_end_time); + + if ( + ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') + || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') + ) { + $game['fine'] = 0; + $game['reward'] = 0; + } else { + $game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; + $game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; + } + + $game['sum_money']=round($game['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率) + $add_data['statement_money'] += $game['sum_money']; + if ($game['pay_amount'] != '0') { + $add_data['statement_info'][] = $game; + } + }else{ + // dd($t_game_ratio); + for ($i=0; $i < count($t_game_ratio); $i++) { + $tmp_game_ratio = $t_game_ratio[$i]; + $temp_game = $game; + $temp_game['statement_begin_time']=date("Y.m.d",$tmp_game_ratio['begintime']); + $temp_game['statement_end_time']=date("Y.m.d",$tmp_game_ratio['endtime']); + // dd($t_game_id); + $temp_game['pay_amount'] =$this->getRelationGameIdSpend($add_data['company_id'],$t_game_id,$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); + $temp_game['pay_amount'] -=0; + $add_data['pay_amount'] += $temp_game['pay_amount']; + + if($type == 1){ + +// if ($add_data['company_id'] == 5) { +// dump($game_all_payment); +// dump($this->getTurnoverType($t_game_id,$k,$begintime,$endtime)); +// dump($tmp_game_ratio); +// } + + $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio += $company_ratio; + }elseif($type == 0){ +// $tratio = $t_game_ratio['ratio']; + $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); + + if ($turnover_type == 2 || $turnover_type == 4) { + $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + } else { + $tratio = $tmp_game_ratio['ratio']; + } + }else{ + $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); + if ($turnover_type == 2 || $turnover_type == 4) { + continue; + } + //补点 + $tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio2 =$tmp_game_ratio['ratio']; + $tratio = $tratio1-$tratio2+$company_ratio; + if($tratio <= 0){ continue;} + } + if($v['type'] == 2){ + $temp_game['increment_ratio']=$tratio; + }else{ + $temp_game['ratio']=$tratio; + } + + $RewardRecordRes = $this->getPromoteUserGameRewardRecord($add_data['company_id'],$temp_game['statement_begin_time'],$temp_game['statement_end_time']); + + if ( + ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') + || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') + ) { + $game['fine'] = 0; + $game['reward'] = 0; + } else { + $game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; + $game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; + } + + $temp_game['sum_money']=round($temp_game['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率) + $add_data['statement_money'] += $temp_game['sum_money']; + if ($temp_game['pay_amount'] != '0') { + $add_data['statement_info'][] = $temp_game; + } + } + } + } + $add_data['platform_amount'] = $add_data['pay_amount']; + if($type < 2){ + //非补点计算奖罚 + $rrmap = array( + "confirm_time" => ['between', [$begintime,$endtime]], + "company_type"=>2, + "company_id"=>$add_data['company_id'], + "settlement_type"=>2, + ); + $rfres = M("RewardDetail","tab_") + ->field(" + 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($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;; + } + //获取服务器费用 + $tmp_company_info= $pc[$add_data['company_id']]; + if($tmp_company_info['has_server_fee'] == 1 && $tmp_company_info['server_fee'] >0){ + $server_count = $tmp_company_info['server_fee']; + $add_data['statement_info'][] = array( + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time, + 'statement_type'=>1, + "game_name"=>"服务器费用", + 'pay_amount'=>$server_count, + 'sum_money'=>$server_count, + ); + $add_data['statement_money'] -= $server_count; + $add_data['pay_amount'] -= $server_count;; + } + } + + + $is_continue = false; + $statement_data = $add_data['statement_info']; + foreach ($statement_data as $skey => $sval) { + if ($sval) { + $is_continue = true; + } + } + + if (!$is_continue) { + continue; + } + + $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); + if($type == 2 && $add_data['statement_money'] == 0){ + //金额为0不补点 + continue; + } + if($add_data['platform_amount'] == 0){ + continue; + } + //添加 + if($recount === true && $company_id !== false){ + //非重算 + return $add_data; + } + $StatementDb->add($add_data); + } + } + //设定开始结束时间 + public function setBeginAndEndTime($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;//上个月的月末时间戳 + } + return [$begintime,$endtime]; + } + //获取推广公司推广金额 + public function getPromoteCompanySpend(&$pcList,$idarr,$begintime,$endtime){ + $res = []; + $all_res = []; + $cp_res = []; + $cp_all_res = []; + //获取推广员 + if(count($idarr) == 0){return $res;} + $Promote = M("Promote","tab_"); + $Spend = M("Spend","tab_"); + $spenMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]], + "s.is_check"=>1 + ]; + D("Spend")->addSubsiteWhere($spenMap); + $cpMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]] + ]; + D("Spend")->addSubsiteWhere($cpMap); + $cpAllMap =[ + "s.pay_status"=>1, + "s.payed_time"=>['elt',$endtime] + ]; + D("Spend")->addSubsiteWhere($cpAllMap); + + for ($i=0; $i field("group_concat(id) ids,count(id) count")->where("company_id = '{$company_id}'")->group("company_id")->find(); + if($pres['count'] ==0 ){continue;} + $spenMap['s.promote_id']=["in",$pres['ids']]; + //获取支付记录 + $list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + + $allSpendMap = $spenMap; + unset($allSpendMap["s.payed_time"]); + + $allspend_list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($allSpendMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + + foreach($allspend_list as $k=>$v){ + try { + $all_res[$company_id]["pay_amount"] += $v['pay_amount']; + } catch (\Throwable $th) { + $all_res[$company_id]["pay_amount"] = $v['pay_amount']; + } + if(isset($all_res[$company_id][$v['relation_game_id']])){ + // + $all_res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; + }else{ + unset($v['game_id']); + $all_res[$company_id][$v['relation_game_id']]= $v; + } + } + + + if(empty($list)){continue;} + + foreach($list as $k=>$v){ + + try { + $res[$company_id]["pay_amount"] += $v['pay_amount']; + } catch (\Throwable $th) { + $res[$company_id]["pay_amount"] = $v['pay_amount']; + } + if(isset($res[$company_id][$v['relation_game_id']])){ + // + + $res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; + + $res[$company_id][$v['relation_game_id']]['ratio_pay_amount'] += $v['pay_amount']; + }else{ + + unset($v['game_id']); + $v['ratio_pay_amount'] = $v['pay_amount']; + $res[$company_id][$v['relation_game_id']]= $v; + } + } + + $game_ids = implode(",",array_unique(array_column($list,"relation_game_id"))); + $game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime); + $sameGame = $this->getTheSameGame($game_ids); + + + if(!empty($sameGame)){ + foreach ($sameGame as $k => $v) { + + $temp = 0; + for ($j=0; $j < count($v); $j++) { + +// $turnover_where = [ +// "relation_game_id"=>$v[$j], +// "company_id"=>$company_id, +// "_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})" +// ]; +// $turnover_type = D("CompanyGameRatio")->field("turnover_type")->where($turnover_where)->find()['turnover_type']; + $turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime); + + if ($turnover_type == 2) { + $res[$company_id][$v[$j]]['ratio_pay_amount'] = $all_res[$company_id][$v[$j]]['pay_amount']; + $temp += $all_res[$company_id][$v[$j]]['pay_amount']; + } elseif($turnover_type == 3){ + if (empty($cp_res[$company_id])) { + $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + +// if ($company_id == 5) { +// dump($cpMap); +// } + + foreach($cpSpendList as $ck=>$cv){ + try { + $cp_res[$company_id]["pay_amount"] += $cv['pay_amount']; + } catch (\Throwable $th) { + $cp_res[$company_id]["pay_amount"] = $cv['pay_amount']; + } + if(isset($cp_res[$company_id][$cv['relation_game_id']])){ + // + $cp_res[$company_id][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + }else{ + unset($cv['game_id']); + $cp_res[$company_id][$cv['relation_game_id']]= $cv; + } + } + } + + + $res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_res[$company_id][$v[$j]]['pay_amount']; + $temp += $cp_res[$company_id][$v[$j]]['pay_amount']; + + } elseif($turnover_type == 4){ + + if (empty($cp_all_res[$company_id])) { + + $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + foreach ($cpAllSpendList as $ck => $cv) { + try { + $cp_all_res[$company_id]["pay_amount"] += $cv['pay_amount']; + } catch (\Throwable $th) { + $cp_all_res[$company_id]["pay_amount"] = $cv['pay_amount']; + } + if (isset($cp_all_res[$company_id][$cv['relation_game_id']])) { + // + $cp_all_res[$company_id][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + } else { + unset($cv['game_id']); + $cp_all_res[$company_id][$cv['relation_game_id']] = $cv; + } + } + } + + + $res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_all_res[$company_id][$v[$j]]['pay_amount']; + $temp += $cp_all_res[$company_id][$v[$j]]['pay_amount']; + + } else { +// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount']; + $temp += $res[$company_id][$v[$j]]['pay_amount']; + } + + + } + $sameGame[$k] = $temp; + } + foreach ($sameGame as $k => $v) { + $res[$company_id][$k]['all_pay_amount'] = $v; + // $game[$k]['pay_amount']= $v; + } + } + + } + + + foreach($res as $key=>$value){ + + foreach ($value as $k => $v){ + if ($k!='pay_amount') { + + $turnover_type = $this->getTurnoverType($k,$key,$begintime,$endtime); + + if ($turnover_type == 2) { + $res[$key][$k]['ratio_pay_amount'] = $all_res[$key][$k]['pay_amount']; + } elseif($turnover_type == 3){ + + if (empty($cp_res[$key])) { +// if ($key == 5) { +// dump(2); +// dump($cpMap); +// dump($cp_res); +// } + $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + + foreach($cpSpendList as $ck=>$cv){ + try { + $cp_res[$key]["pay_amount"] += $cv['pay_amount']; + } catch (\Throwable $th) { + $cp_res[$key]["pay_amount"] = $cv['pay_amount']; + } + if(isset($cp_res[$key][$cv['relation_game_id']])){ + // + $cp_res[$key][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + }else{ + unset($cv['game_id']); + $cp_res[$key][$cv['relation_game_id']]= $cv; + } + } + } + + $res[$key][$k]['ratio_pay_amount'] = $cp_res[$key][$k]['pay_amount']; + } elseif($turnover_type == 4){ + + if (empty($cp_all_res[$key])) { + + $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + foreach ($cpAllSpendList as $ck => $cv) { + try { + $cp_all_res[$key]["pay_amount"] += $cv['pay_amount']; + } catch (\Throwable $th) { + $cp_all_res[$key]["pay_amount"] = $cv['pay_amount']; + } + if (isset($cp_all_res[$key][$cv['relation_game_id']])) { + // + $cp_all_res[$key][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + } else { + unset($cv['game_id']); + $cp_all_res[$key][$cv['relation_game_id']] = $cv; + } + } + } + + $res[$key][$k]['ratio_pay_amount'] = $cp_all_res[$key][$k]['pay_amount']; + } + + } + } + + } + + foreach($res as $k=>$v){ + $pcList[$k]["pay_amount"] = $v['pay_amount']; + unset($v['pay_amount']); + $pcList[$k]['game_list'] = $v; + $pcList[$k]['game_ids'] = implode(",",array_keys($pcList[$k]['game_list'])); + } + + } + /** + * 返回结算流水类型 + */ + public function getTurnoverType($relation_game_id = 0, $company_id = 0, $begin_time = 0, $end_time = 0){ + $company_belong = M("promote_company","tab_")->field("company_belong")->where(['id'=>$company_id])->find(); + + if (!$company_belong) { + return 0; + } + + $turnover_where = [ + "relation_game_id"=>$relation_game_id, + "company_id"=>$company_id, + "_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})" + ]; + $turnover_type = D("CompanyGameRatio")->field("turnover_type")->where($turnover_where)->find(); + + if (!$turnover_type) { + $turnover_where = [ + "company_belong"=>$company_belong['company_belong'], + "relation_game_id"=>$relation_game_id, + "company_id"=>0, + "_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})" + ]; + $turnover_type = D("CompanyGameRatio")->field("turnover_type")->where($turnover_where)->find(); + } + + //判断特殊比例是否存在,存在直接返回结算流水类型 + if (!$turnover_type) { + + //判断公司内外团类型是否存在,不存在直接返回0 + if (!$company_belong) { + return 0; + } else { + $company_belong = $company_belong['company_belong']; + } + $mould_where = [ + "relation_game_id"=>$relation_game_id, + "company_belong"=>$company_belong, + "_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})" + ]; + $mould_data = M("game_ratio_mould","tab_")->where($mould_where)->find(); + //判断游戏比例模板是否存在,不存在直接返回0,否则返回查询的类型 + if ($mould_data) { + return $mould_data['turnover_type']; + } else { + return 0; + } + + } else { + return $turnover_type['turnover_type']; + } + + } + + //获取推广公司推广金额 + protected function getPuPromoteSpend(&$pcList,$idarr,$begintime,$endtime){ + $res = []; + //获取推广员 + if(count($idarr) == 0){return $res;} + $Promote = M("Promote","tab_"); + $Spend = M("Spend","tab_"); + $spenMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]], + "s.is_check"=>1 + ]; + D("Spend")->addSubsiteWhere($spenMap,"s"); + $cpallgame = []; + $cpgame = []; + $cpMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]] + ]; + D("Spend")->addSubsiteWhere($cpMap,"s"); + $cpAllMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['elt',$endtime] + ]; + D("Spend")->addSubsiteWhere($cpAllMap,"s"); +// unset($cpAllMap["s.payed_time"]); + + for ($i=0; $i field("id,account")->where("company_id = '{$company_id}'")->select(); + if(empty($pres)){continue;} + $spenMap['s.promote_id']=["in",array_column($pres,"id")]; + $promote_a = []; + foreach($pres as $key=>$value){ + $promote_a[$value['id']] = $value['account']; + } + unset($pres); + //获取支付记录 + $list = $Spend + ->alias('s') + ->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id") + ->where($spenMap) + ->group('p_id,game_id') + ->join("tab_promote promote ON s.promote_id = promote.id","left") + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + + $all_spendMap = $spenMap; + unset($all_spendMap['s.payed_time']); + + $all_list = $Spend + ->alias('s') + ->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id") + ->where($all_spendMap) + ->group('p_id,game_id') + ->join("tab_promote promote ON s.promote_id = promote.id","left") + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + +// if ($company_id == 64) { +// dump($all_list); +// } + + if(empty($list)){continue;} + $game = []; + foreach($list as $k=>$v){ + if(isset($game[$v['relation_game_id']])){ + $game[$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; + }else{ + $game[$v['relation_game_id']]['pay_amount'] = $v['pay_amount']; + } + } + + $allgame = []; + foreach($all_list as $k=>$v){ + if(isset($allgame[$v['relation_game_id']])){ + $allgame[$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; + }else{ + $allgame[$v['relation_game_id']]['pay_amount'] = $v['pay_amount']; + } + } + + //同cp,同一个原包名的共享总流水分成 + $game_ids = implode(",",array_keys($game)); + $game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime); + $sameGame = $this->getTheSameGame($game_ids); + + if(!empty($sameGame)){ + foreach ($sameGame as $k => $v) { + $temp = 0; + for ($j=0; $j < count($v); $j++) { + $turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime); + if ($turnover_type == 2) { + $temp += $allgame[$v[$j]]['pay_amount']; + } elseif($turnover_type == 3) { + + if (empty($cpgame)) { + $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); +// if ($company_id == 43) { +// dump($cpMap); +// } + foreach($cpSpendList as $ck=>$cv){ + if(isset($cpgame[$cv['relation_game_id']])){ + $cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + }else{ + $cpgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; + } + } + } + + $temp += $cpgame[$v[$j]]['pay_amount']; + } elseif($turnover_type == 4) { + + if (empty($cpallgame)) { + $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + + foreach($cpAllSpendList as $ck=>$cv){ + if(isset($cpallgame[$cv['relation_game_id']])){ + $cpallgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + }else{ + $cpallgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; + } + } + } + + $temp += $cpallgame[$v[$j]]['pay_amount']; + } else { +// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount']; + $temp += $game[$v[$j]]['pay_amount']; + } +// $temp += $game[$v[$j]]['pay_amount']; + } + $sameGame[$k] = $temp; + } + foreach ($sameGame as $k => $v) { + $game[$k]['pay_amount']= $v; + } + } + $pcList[$company_id]['game_ids'] = implode(",",array_keys($game)); + + foreach($list as $k=>$v){ + try { + $res[$company_id]["pay_amount"] += $v['pay_amount']; + } catch (\Throwable $th) { + $res[$company_id]["pay_amount"] = $v['pay_amount']; + } + $p_account = $promote_a[$v['p_id']]; + + if(isset($res[$company_id][$p_account][$v['relation_game_id']])){ + // + $res[$company_id][$p_account][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; + }else{ + unset($v['game_id']); + $res[$company_id][$p_account][$v['relation_game_id']]= $v; + + $turnover_type = $this->getTurnoverType($v['relation_game_id'],$company_id,$begintime,$endtime); + + if ($turnover_type == 2) { +// $temp += $allgame[$v[$j]]['pay_amount']; + $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $allgame[$v['relation_game_id']]['pay_amount']; + } elseif($turnover_type == 3) { + + if (empty($cpgame)) { + $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); +// if ($company_id == 43) { +// dump($cpMap); +// } + + foreach($cpSpendList as $ck=>$cv){ + if(isset($cpgame[$cv['relation_game_id']])){ + $cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + }else{ + $cpgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; + } + } + } + + $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpgame[$v['relation_game_id']]['pay_amount']; + } elseif($turnover_type == 4) { + + if (empty($cpallgame)) { + $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') + ->join("left join tab_game g on s.game_id = g.id") + ->select(); + + foreach($cpAllSpendList as $ck=>$cv){ + if(isset($cpallgame[$cv['relation_game_id']])){ + $cpallgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; + }else{ + $cpallgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; + } + } + } + + $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpallgame[$v['relation_game_id']]['pay_amount']; + } else { +// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount']; + $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount']; + } + +// $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount']; + $res[$company_id][$p_account][$v['relation_game_id']]['game_type_name'] = $this->getGameTypeName($v['relation_game_id']); + } + } + } + + foreach($res as $k=>$v){ + $pcList[$k]["pay_amount"] = $v['pay_amount']; + unset($v['pay_amount']); + foreach($v as $ke=>$va){ + $tmp = [ + "account"=>$ke, + 'game_list'=>$va + ]; + $pcList[$k]['list'][] = $tmp; + } + } + } + public function promoteUserPool($type,$stime,$recount = false){ + $t = $this->setBeginAndEndTime($type,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + + $user = [ + "pay_amount"=>0, + "statement_money"=>0, + "lack_statement_money"=>0, + "withdraw_type"=>$type, + "platform_amount"=>0, + "create_lack_ids"=>[], + "del_lack_ids"=>[], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + "fine"=>0, + "reward"=>0, + "verify_status"=>0, + "company_type"=>2, + "verify_log"=>json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]), + "op_time"=>time(), + "statement_num"=>"PL_".date('Ymd').date('His').sp_random_num(3) + ]; + // $users = $user = $basedata; + // $users['is_payment'] = 1; + // $users['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3); + + // $user['is_payment'] = 2; + // $user['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3); + + + + if($type == 0){//周结 + $this->doPromoteUserPool($user,0,$stime,$recount); + }else if($type == 1){ + $users['withdraw_type'] = 1; + $user['withdraw_type'] = 1; + //月结&补点 + $this->doPromoteUserPool($user,1,$stime,$recount); + + }else{ + $users['withdraw_type'] = 2; + $user['withdraw_type'] = 2; + $this->doPromoteUserPool($user,2,$stime,$recount); + } + + $this->savePromotateUserPool($user); + + } + + /** + * 下游个人汇总单 + */ + public function doPromoteUserPool(&$user,$type,$stime,$recount = false) + { + $t = $this->setBeginAndEndTime($type,$stime); + $begintime = $t[0]; + $endtime = $t[1]; + + $where = [ + "_string"=>"first_company_type = '2' OR second_company_type = '2'" + ]; + //获取哪些要结算 + if($type == 1){//月结 + $where['settlement_type']=2; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + }else{ + $where['settlement_type']=1; + $pcDbRes = M("CompanyRelation","tab_")->where($where)->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公司 + $pc_id = implode(",",array_flip(array_flip(array_keys($pcList)))); + $pu_map = [ + "id"=>["IN",$pc_id], + "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}", + "company_type"=>2 + ]; + $tmpp = M("PromoteCompany","tab_") + ->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio") + ->where($pu_map) + ->select(); + if(count($tmpp)<1){return;} + + $pc =[]; + $Promote = M("Promote","tab_"); + foreach ($tmpp as $v) { + $p_map = [ + "company_id"=>$v['id'], + "withdraw_done"=>1 + ]; + // $pres = $Promote->field("alipay_account,alipay_real_name")->where($p_map)->find(); + // if(!empty($pres) && !empty($pres['alipay_account']) && !empty($pres['alipay_real_name'])){ + // $v['ali_user'] = $pres['alipay_real_name']; + // $v['ali_account'] = $pres['alipay_account']; + // } + if($v['has_ratio']){ + $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); + } + + $pc[$v['id']]=$v; + $pc[$v['id']]['is_payment']=$pcList[$v['id']]['is_payment']; + } + unset($tmpp); + + $this->getPuPromoteSpend($pc,array_unique(array_keys($pc)),$begintime,$endtime); +// dump($pc);die(); + + $StatementDb = SM("CompanyStatement","tab_"); + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); + // $RewardRecord = M("RewardRecord","tab_"); + $LackStatement = SM("company_lack_statement_info","tab_"); + $StatementInfo = SM("company_statement_info","tab_"); + + foreach($pc as $k=>&$v){ + $fax_ratio = $v['taxation_rate']; + $RewardRecordRes = $this->getPromoteUserRewardRecord($v['id'],$begintime,$endtime); + if($v['has_ratio'] == 1){ + $company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']); + }else{ + $company_ratio = 0; + } + //获取其他信息 + $v = $this->getCompanyOtherInfo($v,$k); + $countdata = &$user; + $v['statement_money'] = 0; + $v['pay_amount'] = 0; + if($type < 2 && $RewardRecordRes){ + $v['fine'] = $RewardRecordRes['fine']; + $v['reward'] = $RewardRecordRes['reward']; + $v['statement_money'] -= $v['fine']; + $v['statement_money'] += $v['reward']; + }else{ + $v['fine'] = 0; + $v['reward'] = 0; + } + $v['platform_amount'] = 0; + if(!isset($v['list'])){continue;} + $company_belong = $pc[$v['id']]['company_belong']; + //服务器费用 + if ($type < 2) { + if ($v['has_server_fee'] == 1 && $v['server_fee'] > 0) { + $v['statement_info'][] = [ + "game_name"=>"服务器费用", + "sum_money"=>-$v['server_fee'], + "pay_amount"=>-$v['server_fee'], + 'statement_type'=>1, + "statement_begin_time"=>$statement_begin_time, + "statement_end_time"=>$statement_end_time + ]; + $v['pay_amount'] -= $v['server_fee']; + $v['statement_money'] -= $v['server_fee']; + } + } + $promoteCompanyGameRatio = D("CompanyGameRatio")->getPromoteCompanyGameRatio($v['id'],$v['game_ids'],$begintime,$endtime,$company_belong); + + $handleed_data = []; + + foreach($v['list'] as $ke=>$va){ + $templist = $va['game_list']; + $va['game_list'] = []; + foreach($templist as $p_id => $p_info){ + + $ratioCount = count($promoteCompanyGameRatio[$p_info['relation_game_id']]); + $isMoreRatio = $ratioCount > 1 ? true : false; + + if(!$isMoreRatio){ + $tmp_game_ratio = $promoteCompanyGameRatio[$p_info['relation_game_id']][0]; + if($type == 1){ + $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio += $company_ratio; + }elseif($type == 0){ +// $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); +// $tratio = $tmp_game_ratio['ratio']; + $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); + +// if ($v['id'] == 5) { +// dump($p_info['all_pay_amount']); +// dump($turnover_type); +// dump($tmp_game_ratio); +// } + + if ($turnover_type == 2||$turnover_type == 4) { + $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + } else { + $tratio = $tmp_game_ratio['ratio']; + } + }else{ + $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); + if ($turnover_type == 2||$turnover_type == 4) { + continue; + } + //补点 + $tratio1 =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio2 =$tmp_game_ratio['ratio']; + $tratio = $tratio1-$tratio2+$company_ratio; + if($tratio <= 0){ continue;} + } + $tratio -= 0; + if($type == 2){ + $p_info['increment_ratio']=$tratio; + }else{ + $p_info['ratio']=$tratio; + } + + $p_info['pay_amount'] = $this->getRelationGameIdPromoteSpend($p_info["p_id"],$p_info['relation_game_id'],$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); + + $p_info['pay_amount'] = number_format($p_info['pay_amount'],2,'.',''); + + $v['platform_amount'] += $p_info['pay_amount']; + $p_info['sum_money']=round($p_info['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例 + $v['pay_amount'] += $p_info['sum_money']; + $v['statement_money'] += $p_info['sum_money']; + $p_info['fax_ratio']=$fax_ratio; + $p_info['statement_begin_time']=$statement_begin_time; + $p_info['statement_end_time']=$statement_end_time; + + $RewardRecordRes = $this->getPromoteUserGameRewardRecord($v['id'],$statement_begin_time,$statement_end_time); + + if ( + ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') + || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') + ) { + $p_info['fine'] = 0; + $p_info['reward'] = 0; + } else { + $p_info['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; + $p_info['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; + $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; + } +// if ($p_info['relation_game_id'] == 191 && $v['id'] == 334) { +// dump($RewardRecordRes); +// } + + + + $p_info['statement_type']=0; + + if ($p_info['pay_amount'] !='0') { + $va['game_list'][] = $p_info; + } + + + }else{ + for ($i=0; $i < $ratioCount; $i++) { + $temp_game = []; + $tmp_game_ratio = $promoteCompanyGameRatio[$p_info['relation_game_id']][$i]; + if($type == 1){ + $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio += $company_ratio; + }elseif($type == 0){ + + $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); +// if ($v['id'] == 5) { +// dump($p_info['all_pay_amount']); +// dump($turnover_type); +// dump($tmp_game_ratio); +// } + if ($turnover_type == 2 || $turnover_type == 4) { + $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + } else { + $tratio = $tmp_game_ratio['ratio']; + } + + + }else{ + $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); + if ($turnover_type == 2 || $turnover_type == 4) { + continue; + } + //补点 + $tratio1 =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); + $tratio2 =$tmp_game_ratio['ratio']; + $tratio = $tratio1-$tratio2+$company_ratio; + if($tratio <= 0){ continue;} + } + $tratio -= 0; + if($type == 2){ + $temp_game['increment_ratio']=$tratio; + }else{ + $temp_game['ratio']=$tratio; + } + $temp_game['pay_amount'] = $this->getRelationGameIdPromoteSpend($p_info["p_id"],$p_info['relation_game_id'],$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); + $temp_game['pay_amount'] -=0; + $temp_game['pay_amount'] = number_format($temp_game['pay_amount'],2,'.',''); + + $v['platform_amount'] += $temp_game['pay_amount']; + $temp_game['sum_money']=round($temp_game['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例 + $v['pay_amount'] += $temp_game['sum_money']; + $v['statement_money'] += $temp_game['sum_money']; + + $temp_game['fax_ratio']=$fax_ratio-0; + $temp_game['statement_begin_time']=date("Y.m.d",$tmp_game_ratio['begintime']); + $temp_game['statement_end_time']=date("Y.m.d",$tmp_game_ratio['endtime']); + $temp_game['statement_type']=0; + + $RewardRecordRes = $this->getPromoteUserGameRewardRecord($v['id'],$temp_game['statement_begin_time'],$temp_game['statement_end_time']); + + if ( + ($handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] || $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] == '0') + || ($handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] || $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] == '0') + ) { + $temp_game['fine'] = 0; + $temp_game['reward'] = 0; + } else { + $temp_game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; + $temp_game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; + $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] = (string)$RewardRecordRes['fine']; + $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] = (string)$RewardRecordRes['reward']; + } +// if ($p_info['relation_game_id'] == 191 && $v['id'] == 334) { +// dump($RewardRecordRes); +// } + + $temp_game['statement_type']=0; + + $temp_game['relation_game_id']=$p_info["relation_game_id"]; + $temp_game['game_name']=$p_info["game_name"]; + $temp_game['game_type_name']=$p_info["game_type_name"]; + $temp_game['all_pay_amount']=$p_info["all_pay_amount"]; + + if ($temp_game['pay_amount'] != '0') { + $va['game_list'][] = $temp_game; + } + + } + } + } + $v['statement_info'][] = $va; + } + $company_info = [ + 'account'=>$v['account'], + "company_relation_str"=>$v['company_relation_str'], + "company_belong_str"=>$v['company_belong_str'], + "company_type_str"=>$v['company_type_str'], + "nickname"=>$v['nickname'], + "payee_name"=>$v['payee_name'], + "bank_account"=>$v['bank_account'], + "opening_bank"=>$v['opening_bank'], + "ali_user"=>$v['ali_user'], + "ali_account"=>$v['ali_account'] + ]; + if($v['platform_amount'] < 300){ + $lackcompany =[ + "company_id"=>$k, + "company_type"=>2, + "company_name"=>$v['partner'], + "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), + "statement_money"=>$v['statement_money'], + "pay_amount"=>$v['pay_amount'], + "platform_amount"=>$v['platform_amount'], + "fine"=>$v['fine'], + "reward"=>$v['reward'], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + + "statement_pool_num"=>$countdata['statement_num'],//母单 + + "is_payment"=>$v['is_payment'], + "statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE) + ]; + } + $is_continue = false; + $statement_data = $v['statement_info']; + foreach ($statement_data as $skey => $sval) { + if ($sval['game_list']) { + $is_continue = true; + } +// dump($sval); + } + + if (!$is_continue) { + continue; + } + + //无需补点不统计其他金额 + if($type == 2 && $v['statement_money'] == 0){ + continue ; + } + //聚合未结算数据 + $lsres = $LackStatement->where("company_id='{$k}' and is_pool = 0")->select(); + $del_lack_ids = []; + if(count($lsres) > 0){ + //进行聚合 + foreach($lsres as $key=>$val){ + + $del_lack_ids[] = $val['id']; + $v['statement_money'] += $val['statement_money']; + $v['pay_amount'] += $val['pay_amount']; + $v['fine'] += $val['fine']; + $v['reward'] += $val['reward']; + $v['platform_amount'] += $val['platform_amount']; + $t_statement_info = json_decode($val['statement_info'],true); + $statement_info = []; + foreach($t_statement_info as $p=>$info){ + $statement_info[$info['account']] = $info['game_list']; + } + foreach($v['statement_info'] as $p=>$info){ + if(isset($statement_info[$info['account']])){ + $v['statement_info'][$p]['game_list'] = array_merge($statement_info[$info['account']],$v['statement_info'][$p]['game_list']); + unset($statement_info[$info['account']]); + } + } + if(!empty($statement_info)){ + foreach($statement_info as $p=>$info){ + $v['statement_info'][] = ["account"=>$p,"game_list"=>$info]; + } + } + } + } + if($v['platform_amount'] == 0 && $v['statement_money'] == 0){ + continue ; + } + + if($v['platform_amount'] < 300){ + //存未满 + // if($lackcompany['pay_amount'] != 0){ + $lask_id = $LackStatement->add($lackcompany); + $countdata['create_lack_ids'][] =$lask_id; + $countdata['lack_statement_money'] +=$lackcompany['statement_money']; + $countdata['lack_platform_amount'] +=$lackcompany['platform_amount']; + // } + + }else{ + // if($v['pay_amount'] != 0){ + //存成功配置单号 + $company =[ + "pool_id"=>0, + "company_id"=>$k, + "company_type"=>2, + "company_name"=>$v['partner'], + "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), + "statement_money"=>$v['statement_money'], + "pay_amount"=>$v['pay_amount'], + "platform_amount"=>$v['platform_amount'], + "fine"=>$v['fine'], + "reward"=>$v['reward'], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + "statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE), + "statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5) + ]; + if($v['is_payment'] == 1){ + $company['verify_status'] = 0; + }else{ + $company['verify_status'] = 2; + } + $companyid = $StatementInfo->add($company); + $countdata['info_ids'][] =$companyid; + $countdata['del_lack_ids'] =array_merge($countdata['del_lack_ids'],$del_lack_ids); + $countdata['statement_money'] +=$v['statement_money']; + $countdata['pay_amount'] +=$v['pay_amount']; + $countdata['platform_amount'] +=$v['platform_amount']; + $countdata['fine'] +=$v['fine']; + $countdata['reward'] +=$v['reward']; + // } + } + } + } + /** + * 保存信息汇总信息 + */ + public function savePromotateUserPool($data){ + if(IS_CLI){ + $op_name ="system"; + }else{ + $op_name =$_SESSION['onethink_admin']['user_auth']["username"]; + } + if(empty($data['create_lack_ids']) && empty($data['del_lack_ids']) && empty($data['info_ids'])){ //补点为空不重算 + return ; + } + if($data['statement_money'] == 0){ + $data['verify_status'] = 5; + $data['verify_log'] = json_encode(["create_user"=>$op_name,"create_time"=>date("Y-m-d H:i:s"),"verify_user"=>"system","verify_time"=>date("Y-m-d H:i:s"),"payment_user"=>"system","payment_time"=>date("Y-m-d H:i:s")]); + }else{ + $data['verify_log'] = json_encode(["create_user"=>$op_name,"create_time"=>date("Y-m-d H:i:s")]); + } + $data['create_lack_ids'] = implode(",",$data['create_lack_ids']); + $data['del_lack_ids'] = implode(",",$data['del_lack_ids']); + $info = implode(",",$data['info_ids']); + unset($data['info_ids']); + $id = SM("company_statement_pool","tab_")->add($data); + //回写 + if(!empty($info)){ + $save["pool_id"]=$id; + SM("company_statement_info","tab_")->where("id in ({$info})")->save($save); + } + if(!empty($data['del_lack_ids'])){ + SM("company_lack_statement_info","tab_")->where("id in ({$data['del_lack_ids']})")->save(["is_pool"=>1]); + } + } + + /** + * 获取公司额为信息 + */ + public function getCompanyOtherInfo($company_info,$company_id) + { + $pl = M("promote_company","tab_") + ->alias('pc') + ->field("p.account,p.company_relation,IFNULL(s.real_name,'-') nickname") + ->join("left join (select company_id,account,company_relation,admin_id from tab_promote where level = 1 group by company_id ) p on p.company_id = pc.id")//获取会长 + ->join("left join sys_member s on s.uid = p.admin_id") + ->where("pc.id = {$company_id}") + ->find(); + $company = array_merge($company_info,$pl); + $company['company_relation_str'] =getCompanyRelation($company['company_relation']); + $company['company_belong_str'] =getCompanyBlong($company['company_belong']); + $company['company_type_str'] = "个人"; + return $company; + + } + /** + * 获取游戏分类名称 + */ + public function getGameTypeName($relation_game_id){ + return M("Game","tab_")->field("game_type_name")->where("relation_game_id = '{$relation_game_id}'")->find()['game_type_name']; + } + /** + * 获取公司比例加成 + * @param [type] $paymount 支付金额 + * @param [type] $turnover_ratio 梯度 + */ + protected function getCompanyRatio($paymount,$turnover_ratio) + { + $ratio = 0; + foreach($turnover_ratio as $k=>$v){ + if($v['instanceof'] == 1){ + if($paymount >= $v['turnover']){ + $ratio = $v['ratio']; + } + }else{ + if($paymount > $v['turnover']){ + $ratio = $v['ratio']; + } + } + } + return $ratio; + } + + /** + * 获取游戏奖罚 + */ + protected function getPromoteUserGameRewardRecord($cpmpamy_id,$begintime,$endtime) + { + + $begintime = strtotime(str_replace('.','-',$begintime)); + $endtime = strtotime(str_replace('.','-',$endtime))+86499; + + //获取所有公司的奖罚 + $rrmap = array( + "d.confirm_time" => ['between', [$begintime,$endtime]], + "d.company_type"=>2, + "d.company_id"=>$cpmpamy_id, + "d.settlement_type"=>2, +// "relation_game_id"=>$relation_game_id, + ); + + $rfres = M("RewardDetail","tab_") + ->alias("d") + ->field(" + IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward, + IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine") + ->join('tab_reward_record as r on d.record_id = r.id', 'LEFT') + ->where($rrmap) + ->group("company_id") + ->find(); + +// $rfres = M('reward_record', 'tab_') +// ->alias('r') +// ->field(" +// IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward, +// IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine") +// ->where($rrmap) +// ->join('tab_reward_detail as d on d.record_id = r.id', 'LEFT') +// ->group("company_id") +// ->find(); +// if ($relation_game_id == 191 && $cpmpamy_id == 334) { +// dump($rfres); +// } + + if(empty($rfres)){ + return false; + }else{ + return $rfres; + } + } + + /** + * 获取上游游戏奖罚 + */ + protected function getPromoteUserGameRewardRecordCp($cpmpamy_id,$begintime,$endtime) + { + + $begintime = strtotime(str_replace('.','-',$begintime)); + $endtime = strtotime(str_replace('.','-',$endtime))+86499; + + //获取所有公司的奖罚 + $rrmap = array( + "d.confirm_time" => ['between', [$begintime,$endtime]], + "d.company_type"=>1, + "d.company_id"=>$cpmpamy_id, + "d.settlement_type"=>2, +// "relation_game_id"=>$relation_game_id, + ); + + $rfres = M("RewardDetail","tab_") + ->alias("d") + ->field(" + IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward, + IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine") + ->join('tab_reward_record as r on d.record_id = r.id', 'LEFT') + ->where($rrmap) + ->group("company_id") + ->find(); + + if(empty($rfres)){ + return false; + }else{ + return $rfres; + } + } + + /** + * 获取公司奖罚 + */ + protected function getPromoteUserRewardRecord($cpmpamy_id,$begintime,$endtime) + { + //获取所有公司的奖罚 + $rrmap = array( + "d.confirm_time" => ['between', [$begintime,$endtime]], + "d.company_type"=>2, + "d.company_id"=>$cpmpamy_id, + "d.settlement_type"=>2, + ); + $rfres = M("RewardDetail","tab_") + ->alias("d") + ->field(" + IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward, + IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine") + ->where($rrmap) + ->group("company_id") + ->find(); + if(empty($rfres)){ + return false; + }else{ + return $rfres; + } + } + /** + * 获取比例 + * + * @param [type] $amount 总额 + * @param [type] $ratio 默认比例 + * @param [type] $turnover_ratio 比例梯度 + * @return void + */ + protected function getTurnoverRatio($amount,$ratio,$turnover_ratio) + { + if(empty($turnover_ratio)){ + return $ratio; + } + if(!is_array($turnover_ratio)){ + $turnover_ratio = json_decode($turnover_ratio,true); + } + foreach($turnover_ratio as $k=>$v){ + if($v['instanceof'] == 1){ + if($amount >= $v['turnover']){ + $ratio = $v['ratio']; + } + }else{ + if($amount > $v['turnover']){ + $ratio = $v['ratio']; + } + } + } + return $ratio; + } + + protected function getRelationGameIdSpend($company_id,$relation_game_id,$begintime,$endtime) + { + $res = []; + //获取推广员 + $Promote = M("Promote","tab_"); + $Spend = M("Spend","tab_"); + $spenMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]], + "s.is_check"=>1 + ]; + + $company_id = $company_id; + $pres = $Promote->field("group_concat(id) ids,count(id) count")->where("company_id = '{$company_id}'")->group("company_id")->find(); + if($pres['count'] ==0 ){return 0;} + $spenMap['s.promote_id']=["in",$pres['ids']]; + //游戏 + + $game_id = D("Game")->changeRelationGameidToGameid($relation_game_id); + // dd($game_id); + $spenMap['s.game_id'] =['in',$game_id]; + D("Spend")->addSubsiteWhere($spenMap); + //获取支付记录 + $pay_amount = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount')->where($spenMap)->find(); + return $pay_amount['pay_amount'] ?? 0; + } + + protected function getRelationGameIdPromoteSpend($promote_id,$relation_game_id,$begintime,$endtime) + { + $res = []; + //获取推广员 + $Promote = M("Promote","tab_"); + $Spend = M("Spend","tab_"); + $spenMap = [ + "s.pay_status"=>1, + "s.payed_time"=>['between', [$begintime,$endtime]], + "s.is_check"=>1 + ]; + D("Spend")->addSubsiteWhere($spenMap); + + $Pmap = [ + "chain"=>["LIKE","%/{$promote_id}/%"], + "_logic"=>"OR", + "id"=>$promote_id + ]; + $pres = $Promote->field("group_concat(id) ids,count(id) count")->where($Pmap)->group("company_id")->find(); + if($pres['count'] ==0 ){return 0;} + $spenMap['s.promote_id']=["in",$pres['ids']]; + //游戏 + + $game_id = D("Game")->changeRelationGameidToGameid($relation_game_id); + // dd($game_id); + $spenMap['s.game_id'] =['in',$game_id]; + //获取支付记录 + $pay_amount = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount')->where($spenMap)->find(); + return $pay_amount['pay_amount'] ?? 0; + } + /** + * 获取游戏是否有特殊比例,返回没有特殊比例的游戏 + * return string "148,157" + */ + protected function getModuleRatioGame($company_id,$relation_game_ids,$begintime,$endtime){ + + $where = [ + "relation_game_id"=>["in",$relation_game_ids], + "company_id"=>$company_id, + "_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})" + ]; + $dbres = D("CompanyGameRatio")->field("relation_game_id")->where($where)->select(); + + if (!$dbres) { + $company_belong = M("promote_company","tab_")->field("company_belong")->where(['id'=>$company_id])->find(); + + $where = [ + "company_id"=>0, + "company_belong"=>$company_belong['company_belong'], + "relation_game_id"=>["in",$relation_game_ids], + "_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})" + ]; + $dbres = D("CompanyGameRatio")->field("relation_game_id")->where($where)->select(); + } + + if(is_string($relation_game_ids)) $relation_game_ids = explode(",",$relation_game_ids); + + $array_mer = []; + + foreach ($relation_game_ids as $key => $value) { + $turnover_type = $this->getTurnoverType($value,$company_id,$begintime,$endtime); + + if ($turnover_type == 2 || $turnover_type == 3 || $turnover_type == 4) { + + $mercy_game = M("game",'tab_')->field("original_package_name")->where(['relation_game_id'=>$value])->find()['original_package_name']; + + $original_game_id = M("game",'tab_') + ->field("relation_game_id") + ->where(['original_package_name'=>$mercy_game,'relation_game_id'=>['neq',$value]]) + ->group("relation_game_id") + ->select(); + + foreach ($original_game_id as $k => $v) { + + if(!in_array($v['relation_game_id'], $relation_game_ids)){ + + $array_mer[] = $v['relation_game_id']; + + } + + } + + } + + } + + $relation_game_ids = array_merge($relation_game_ids,$array_mer); + + + if(empty($dbres)){ + return implode(",",$relation_game_ids); + }else{ + $dbres = array_column($dbres,"relation_game_id"); + $diff = array_diff($relation_game_ids,$dbres); + + return implode(",",$diff); + } + } + + /** + * 识别游戏为同款游戏,共享流水分成比例 + * return [ + * 148 =>["148","157"], + * 157=>["148","157"] + * ] + */ + protected function getTheSameGame($relation_game_ids) + { + if(empty($relation_game_ids)) return []; + $where = [ + "id"=>["in",$relation_game_ids] + ]; + $Gameinfo = D("Game")->field("relation_game_id,partner_id,original_package_name")->where($where)->select(); + if(empty($Gameinfo)){ + return []; + } + $data = []; + foreach ($Gameinfo as $k => $v) { + if(empty($v['original_package_name'])) continue; + if(!isset($data[$v['partner_id']])){ + $data[$v['partner_id']] = []; + } + if(!isset($data[$v['partner_id']][$v['original_package_name']])){ + $data[$v['partner_id']][$v['original_package_name']] = [$v['relation_game_id']]; + }else{ + $data[$v['partner_id']][$v['original_package_name']][] = $v['relation_game_id']; + } + } + $senddata = []; + foreach ($data as $k => $partenr) { + foreach($partenr as $ke => $game){ + $gamecount = count($game); + if($gamecount > 1){ + for ($i=0; $i < $gamecount; $i++) { + $senddata[$game[$i]] = $game; + } + } + } + } + return $senddata; + } + + /** + * 重算接口 + * 不进行结算方式重算 + * @param [type] $id 原数据id + * @param string $admin_user 操作用户 + * @return void bool + */ + public function updateCompanyStatementData($id,$admin_user='system') + { + //获取数据 + $StatementDb = SM("CompanyStatement","tab_"); + $dbres = $StatementDb->where("id='{$id}'")->find(); + //获取时间 + $stime = $dbres['statement_end_time']-0+1; + $company_id = $dbres['company_id']; + + if($company_id == 0){ + $savedata = $this->officeCompanyStatement($stime,true); + }else{ + if($dbres['company_belong'] == 9){ + //上游 + $savedata = $this->cpStatement($dbres['withdraw_type'],$stime,$company_id); + }else{ + $savedata = $this->promoteCompanyStatement($dbres['withdraw_type'],$stime,$company_id); + } + } + //重写用户 + $savedata['verify_log'] = json_encode(["create_user"=>$admin_user,"create_time"=>date("Y-m-d H:i:s")]); + $savedata['verify_status'] = 0; + $savedata['confirm_status'] = 0; + $savedata['confirm_log'] = ''; + $savedata['id'] = $dbres['id']; + return $StatementDb->save($savedata); + } + +} diff --git a/Application/Admin/View/CompanyStatement/subViewCpStatement.html b/Application/Admin/View/CompanyStatement/subViewCpStatement.html new file mode 100644 index 000000000..32cc52863 --- /dev/null +++ b/Application/Admin/View/CompanyStatement/subViewCpStatement.html @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
甲方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
乙方: +
+ +
+
联系人: + +
联系电话: + +
邮寄地址: + +
公司税号: + +
+
+
+
+ +
+
+

支付给:{$data.company} + +

+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
结算时间合作产品渠道费率税费费率结算金额
{$it.statement_begin_time}-{$it.statement_end_time}{$it.game_name}{$it.promote_ratio|showNumPercent}{$it.fax_ratio|showNumPercent}{$data['statement_count']['statement_money']}
本月分成总金额(人民币大写):{$data.statement_count.big_ratio_money}
+
+
+ +
+
+ + + + + + + + + + + + + + + +
收款方名称: + +
银行账号: + +
开户行: + +
+
+
+ + + + + + + + + + + + + + + +
付款方名称: + +
银行账号: + +
开户行: + +
+
+
+
+ + diff --git a/Public/Admin/excel/sub_up_stream.xls b/Public/Admin/excel/sub_up_stream.xls new file mode 100644 index 0000000000000000000000000000000000000000..252db0ef0f46e35e8ae241e22931ab3e9e58b867 GIT binary patch literal 20480 zcmeHP30#d?|3A;|*1fkyi%N^?mQ+$Hm9kZ`Yf*}%(n5r2gb2}C#uhRe`(QMdVeE_{ zONgvvCu0U_qQ*WilZgJm-+AtH_j`x;eLw&I|9wAmp3ZZg=XZYR`&-WToO7S2%a=^= zf3w@Bk|>2BqC-A3iin;Zoq=nNG?)+~h6}v^(Ad~WX>fwezr%l!2i}9O&QNbU5cv>w zA!3~iAPOOhAnHRjfM^KO2x1e6#t@+i5L1X|5Sv0YhiC!O5@IumRuHWr+Ca30*c_rA zM0&l10Lbx}gM1tVvG07Wd@OE*1t3I_abP(oI|ejBf26aSA91#U z5%{m{=lss4@~|Qy^kO|-Qet#ba6F$OdeHeR36JdJABQs`4Zc5KPDaT=Y?o3A_LXwKidjtXp z&Q1e)A(U?+Jv-5J6F4*E04?(~rTDbwSq;HNLPb~HKM8;S4xu(SW2X(9@+X;wur5FL(0!6cntZ?HQ+dF;1ANkAE>4V zJ)maQ(NV6x1{^=NbRNvMs_iyI3%;oue!dp|PHOmBKdbkrpBj6SKUj%w&u38Wv4nnOvFhJpd`L}RU5&U32UrkRfw91KlGhQir3oV13)QjJ~8aH`g+q}!@P?(z z=o0_nY>t8NPU{7ibCiFnsp)cqiLX`n0P8&DivHc}j^Tu%vpYqdDI z;A2y8T51{-&X8EP{%eEg?J@qMnbB_NyNr6i+pViY`Mo%Rq zNa_c;P{L>1t)mLPwFZ4`DP2{cAPxKu8t5Jx=v;eN){|{Ns&d?;LspXhhC;cM;to7 z4V17;+6jvTn^Q{sEFFky=`bHjwkEjtrU^$t^#uGt9xsH15W-{il+kf*DWeOe{EBoD zr9<-$G&2nmhln{GeR$Rx%YeO|OiT&VC3eZ^rYye-oiPP{)bKkh@EcHkklRTShqYHu zA1OZ8i#obQ(yQaz_?lB;N!Odk^y>IaEjL#{mp@)Y!!(Qy}2X0MTyUn8ABkot%9 zKh~oeBkzA1-Grh3m(;I}ZmPiFL|VTRKS=nc?I%#tKXNz<^=?dYpqFv{5**xyrT*_^ zrr;me&sdLil9$>gqcaNpGC!Lt(B<$I{4B#!^rwuj*xuNBq5f3BkhX&0(?mnRVEqRCO6}Z~!_nBz75&fpjp8Wz zpX*1C3Us;lj1SAw`jyee3jAj92v5gPB|W9}K2;H4O7Emtk5amlT{1r_`b~~5_5W0% zIhiUQPeFS!olHJ6tXH1UljJGTdqEx#wi#hV71?0thfVP323^9a7U&K6S_@b!N$3Lw z7!J)%DKm^_suQ0lROU_i1m46?;7$4j-oc;1oAL>~saklI9hyaXY4sHGU_U#bG=3?x zAz#YXD+9aJJQ6s#Y##6u(aS3ZyWX}*2 zUw~<=2*r14Y(lh^U`2@N{xDOtI6YcL8=g66gE^cwP4oGn4WF3j>rt&NP%FPr(#jRI z(pG{MC4gVW7{WYD`ci16XclAJ$dG4P_tZbl@^z>tR;Wq4PtwE(bOVUj(TLexHMV@tVwYOH}=)4}QZO7QzvJ#?z`D)|_(fIcwFfEh2*hj9{ycPZ&YQ ziWOpT>z6`%MQ`aeZR8U!mn#BG62c5y&?k0Iy2o&pB0K{q!sW6>M9|*AR>V=URmT`? z#T=H^m^kA2Q#J4064w+KU#zGS&%aTZ$nrU*oMd+RsIkLDYKIS&pr*Hw6+!PQn{FyC z!g+d1WHz}2(i|RkZIFWrVaK+Wo^u)+W1Nga3n6;wZZyS*2Y7tHhvOl5pl%| zD_ZcwN_FAzqg-7rRjP{{hAc>cDg+Ka$`GwoAh_Yi5q_D|TI1?QGIy=MlR>xF?mKnR zt+o1&gSLQQW>kEKJxAGaPZh(t-r@-R`C8kfx{laJt9CNzP6(~}0Yx3OH$ZDE!S(UZ zs)pkrtZcZCis9`L0fq@j5~SU5bz{1(R>Nh`!P*U12kocTa1PoCwwK`12cNISFh~s% zT0*22(G%{dvtgO=qTw>R9Hd5t>F{yQPsp6e2O*ep0e95KXQYo#Z=;z9Uj}1&WSr(e z6H>HMxyvl`;BG!d+{cyYq}LItV^W8wXM0T=ooRF-LjNQzVJq{#nOJx`U`UBu_q09d zca;1|x~{S5QojD`x;wY3t7ZoLbkF?8>M)~tk2M0L`RNzE<{o%4)nl{mmY;hyKjo2G zS#I&Lc9PZEeG8l3>wRWibY6=ag|oNs|5bc*f9o5L&pmz}e9(Dh=LJ3EYOd9_deHrG zYZrZ9;CluQl&KwVx9svAcm+-jt8;XoirPM?@YDE+EZYE+Bh6~24}5ZD$W7e(D{N~>!ja+Uz@u0X>$3qrpcZYnwVZ@cN&+krl`&qA7{@|<0RqeX3=G7b6 zWyiJdw_#-Y8As2wWanqAE2}QNFgkcB`*mvQks%j!Q%98VOxpU^K2pc>OTXXWOzb&x zvDdq`g>FWs>8+l<8RyZkt;Av4XSz?%Sh-f{yo-IZevw1i%BQjJPWh?MUb_u9zsNi> zX@>LE>gblg)$ki!_U-AvyG3y)kOHPQ_ zjHzv(>*wXV{g&{$HUYs8$t>*|^XwR?BpyZhW<|9j?KaEGaN zgN{61H9MdoYvCw>>}h=G~pXM~X5SAg7-S3(i!yf4lJt(_7qTT(d5{ z_FJqjo^m&+ct`)b7rPhEGWvYW%m!gh>w;UC!#9*wXU{Slsn=j~wxWA>;G@syJvI=n zT;!cTIJhkI$ILNf2ku<*%2w>~Y@frG+_V-4onw|?>RPs9-jm%U0($g*c%n&fo7EMI zPnq{I&pohm{PD#rj&!{~@r+KNfKBi0j}JI>$#O=?`ZX>a(?8$h>ig_Wwf}|h-`f3D z%TL|jR{UhyU{~kPF^B(QefNA$`Ms*LgSkxxlud5>EZFTzXTPwlAr%&nJ%2wEdMqxZ zar(~7tN;81#)XaMGy7~inKJFc%}39NR=u1O>SlMY{i!*j>q>R~)_+E3o{LQGFgDlj zeA=5WIc>vJDxDVXTUfrbVb+;RR>g*q&;66z&+As%!EEqp{x3GKcU?Ph;#z!m*@=dm z@!P($9p+`vJ6kZ z?`>v06n_)<=YWCx>^!_$*DZ+MzMG6pA8>!xZ^sXAtqS-(h1cV=(V^yZ-23KkZFc*{ z*{Q2n-Zc;3#@qU$U-6dw^i6l>KR#Xk-HqyvIg7#*oC~t|_O3ZoWABn?{$N9g8#TEZ zhezzVbAIWdSFvvM2U__JTHd(uRQGX4Ioo~?iHT{I@%z`~8y@E9^l=G^FJD*s)Go-y z`ud_M*Mx2@Ce>T?TATG|fm_(=*-sozA2GK!6m9Dg>ip2YW$*I1^KGt$#B6t5l`z_X zU-@;*TYB-ix6X9A`qa7VEMIUnyu@dN)7R5=XJ6WXqCR$Ya`W#!ZW~_hTyU~!R`~FS zCNs=N?HlQy?`ZmB{^n&peVtzn*kisY{rz^oO`$m#Z_POL#UEq4?X|M7J7xZl<~ueX z{GBcigyYJzCJ3@zEIcsvYPxm{1Y0lF(FBzMB%VEV@>-+7(uf4YHcPk)e$Kow# z8~2{{zOc6M@##A~s=M>Y1S}07@mtzATiR5`94XwAzV*8O<^4a_-(+V+^^XQ-O0%Lm zml$0sT(=YWY{4b2YWbBP0VM8<&_CgAKC5oVL}6CewL>OLTz;KPU_K>BTANkeYWY4ws(Cpw%Q0g)P6N~)$!3kK3Npf&oXk}?T$ltrOa5A z74Xzz_>wTU2p8vmZeBhsvYWW}DOz)Rer$dIj=m;k6Y|!-T+K{9 z<$NT~WXcUOZHG4vY zEo*0#FDlFGSlOB)xk%T5_i;9twYB$B!u5JH|by4Qx7T^9NaQ<#z z(4x{k3%?en1h4NpF3CLL^yD<>pC+BVJfS|{GgB~N@s##KtGYG+azI`Af~MQ9nw+@r zv1`RDJO6ubw?oft9Cx&6aqFnd0^bkDxuTAu74=z<`$mN^JagFB=bjCfT?HAi zogjvDut=@rSOE3y5xXTD@V60jfvl4%3RUi=ScVlEC@n)<;l~R@2=)O{TN!*#W&Xvnm zjEsQ`mdfWC{3ran09jyZh&gx*mpcl}61?L=;@}d&n@p~Yfqgm)=%H%5FjUpG(8%x-6`Vp~6XWKw9`* z8`zs!8`h&L(Xwsl!Y&u z&7|D3=-CCh7gYtq-_c-KxLz7mTNG4V9PB1VsR?c+cl`})E18T*F{-A}B1T*G81(=ttiDG0%^BQt`oq^}4D!=&Zg_A90qdMczflwNaInPd9$3*N zgfS*aV<>G3?U{EJOQQQyZG?>4%3a& zgp_uG(m4G@YH0d$v{I%!Eo-2LhV9#ca57jvZ21P{9vwM38Tj3c0ojY6_))*ShnhfN z^+EzUN=G9d(wp>=JF+agR0O;%+!yMM<%LB!@IyuMUN#pzR4=_$k{J;mySgJ3!r+z?ZF?9hmf@11YJtN?b^{p;o z4v^y$!u*4l>jG_pNL~cdg;psMA_VwcDg?Vt8ori9g^K`e2z8qX)E-I? z)@>qCCmqCbd_uTGwQz7^9Vi0K$rKYCI3E! zijG6wREmk+b{KsIMoa@KCcIRvfN4N6ae`s_I7|b;WIK_86canh2s#lR1@~i<9tj^( z;=$@?2v{Q}`8cQw;cg^M3Ho4-6`dM0;q89*7z1zgk0H|_?-oocUY20~Ma zg~JVUBj{BuY?L=AK|C|^1N1J2gn+J{AY!nC>eevk3qA{|qtWA8;eo{^3z(y_lG9aE%ZigcW@kd7(RF-1DgTqqxB zEbRZ7>H-Z@DQQm!1Aa`gWvDOdju)XSxfvh+Un1I$!3 z<>>Sl{KwrlG_wBEk^(aDH#+=P%F2=AvF)-!(mvIcSK|LmJwBHIuk_TE|FQT=d}t>j zGW#^ytwL9WgMQ}t93*;5?-lrEPZlU$Tfl~mPj1Qq)xJM_-5>RRGfcKEfmiTd_uj^h zvo(-GAH(5#JwyokTi}EUyCC8`bQmJeMQ0%5eDnk&&PlkxE`Z1f44j+bvkW>vIYWwb zlQ*O|KXrl>=c`_j;<_XjQrsa(gcNrNhC+%uWI~Gb)>25hK=lCONauqPY&TrC@-<>> z{-+q)%gSS-ZA0MoyUDN=7y;KP2lc?0#6lqE@3y(*a_cmM*TiXQ4gL=mdYv&o@a?mU z4EhX%a*8-;Zv>zYfmLi4tY5QW8N&Xzmq|cN2mi* Date: Wed, 24 Feb 2021 16:32:44 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SubCompanyStatementSetController.class.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index 9fbce7e8c..d528b68a5 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -264,7 +264,30 @@ class SubCompanyStatementSetController extends Controller { $StatementDb = SM("CompanyStatement","tab_"); $statement_begin_time = date("Y.m.d",$begintime); $statement_end_time = date("Y.m.d",$endtime); + $MainStatementDb = M("CompanyStatement","tab_"); //主站结算单 + // dd($cpList); foreach($cpList as $k=>$v){ + // + $company_id = ($v['first_company_type'] == 1 ? $v['first_company_id'] : $v['second_company_id']); + $mainWhere = [ + "company_id" => $company_id, + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime + ]; + $add_data = $MainStatementDb->where($mainWhere)->find(); + if(empty($add_data)) return false; //主站必须有数据 + $add_data['statement_info'] = json_decode($add_data['statement_info'],true); + if (isset($v['list'])) { + dd($v['list']); + dd($add_data); + }else{ + continue; + } + + + + + //条件ok $add_data=[]; $handleed_data = []; //1.获取甲乙方信息 From 4024e45c64b3cd0cbb77fee08b1e515bc4e0d6eb Mon Sep 17 00:00:00 2001 From: chenzhi Date: Wed, 24 Feb 2021 18:36:09 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E7=AB=99?= =?UTF-8?q?=E4=B8=8A=E6=B8=B8=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SubCompanyStatementSetController.class.php | 210 ++---------------- 1 file changed, 18 insertions(+), 192 deletions(-) diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index d528b68a5..cf06e334e 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -268,213 +268,39 @@ class SubCompanyStatementSetController extends Controller { // dd($cpList); foreach($cpList as $k=>$v){ // - $company_id = ($v['first_company_type'] == 1 ? $v['first_company_id'] : $v['second_company_id']); + $sub_company_id = ($v['first_company_type'] == 1 ? $v['first_company_id'] : $v['second_company_id']); + $ratio_str = ($v['first_company_type'] == 1 ? 'first_ratio' : 'second_ratio'); $mainWhere = [ - "company_id" => $company_id, + "company_belong"=>9, + "company_id" => $sub_company_id, "statement_begin_time"=>$begintime, "statement_end_time"=>$endtime ]; $add_data = $MainStatementDb->where($mainWhere)->find(); - if(empty($add_data)) return false; //主站必须有数据 + if(empty($add_data)) continue; //主站必须有数据 $add_data['statement_info'] = json_decode($add_data['statement_info'],true); - if (isset($v['list'])) { - dd($v['list']); - dd($add_data); - }else{ - continue; - } - - - - - //条件ok - $add_data=[]; - $handleed_data = []; - //1.获取甲乙方信息 - if($v['first_company_type'] == 1){ - //甲方上游 - $cp[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; - $cp[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; - - $add_data['first_party_info'] = json_encode($cp[$v['first_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['second_party_info'] = json_encode($our[$v['second_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['company_id'] = $v['first_company_id']; - $add_data['company_name'] = $v['first_company_name']; - - }else{ - //乙方上游 - $cp[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; - $cp[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; - - $add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['second_party_info'] = json_encode($cp[$v['second_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['company_id'] = $v['second_company_id']; - $add_data['company_name'] = $v['second_company_name']; + foreach ($add_data['statement_info'] as $index => $item) { + $igm = $item['game_name']; + if(isset($v['list'][$igm])){ + $add_data['statement_info'][$index]['platform_money'] = $v['list'][$igm]['platform_money']; + $add_data['statement_info'][$index]['aggregate_money'] = $v['list'][$igm]['aggregate_money']; + $add_data['statement_info'][$index]['ratio'] = $add_data['statement_info'][$index][$ratio_str]; + }else{ + $add_data['statement_info'][$index]['platform_money'] = 0; + $add_data['statement_info'][$index]['aggregate_money'] = 0; + } } - $add_data['pay_type'] = $v['collection']; - $add_data['withdraw_type'] = $type; - $add_data['statement_begin_time'] = $begintime; - $add_data['statement_end_time'] = $endtime; - $add_data['statement_money'] = 0; - $add_data['pay_amount'] = 0; + unset($add_data['id'],$add_data['remark'],$add_data['confirm_status'],$add_data['confirm_log']); $add_data['verify_log'] = $verify_log; $add_data['op_time'] =time(); - $add_data['statement_info'] =[]; - $add_data['company_belong']=9;//上游 - $add_data['company_type']=$cp[$add_data['company_id']]['company_type']; - $add_data['is_payment']=$v['is_payment']; - //获取渠道及税费费率 - $promote_ratio = $cp[$add_data['company_id']]['channel_rate'] ?? 0; - $fax_ratio = $cp[$add_data['company_id']]['taxation_rate'] ?? 0; - //游戏统计 - if (isset($v['list'])) { - foreach ($v['list'] as $ke=>$va) { - $game =[]; - $game['pay_amount'] =$va['pay_money']; - $game['aggregate_amount'] =$va['aggregate_money']??0; - $game['other_amount'] = 0; - $game['platform_amount'] = $va['platform_money']??0; - - $game['game_name'] =$ke; - //获取游戏id及比例 - $game_id = $GameDb->where("relation_game_name='{$ke}' OR original_package_name='{$ke}'")->field("id,relation_game_id")->find(); - if (empty($game_id) && isset($va['unique_code']) && !empty($va['unique_code'])) { - $unique_code = $va['unique_code']; - $game_id = $GameDb->where("unique_code='{$unique_code }'")->field("id,relation_game_id")->find(); - } - if (empty($game_id)) { - $game['relation_game_id']=0; - $tratio = 0; - } else { - //获取比例 - $game['relation_game_id']=$game_id['relation_game_id']; - if ($type == 1) { - $tratio = getGameCpRadio($game_id['id'], $va['pay_money'], true); - } 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; - if ($tratio <= 0) { - continue; - } - } - } - $game['tratio'] = $tratio-0;; - if ($v['first_company_type'] == 1) { - $game['first_ratio']=$tratio-0; - $game['second_ratio']=100-$tratio; - } else { - $game['first_ratio']=100-$tratio; - $game['second_ratio']=$tratio-0; - } - $add_data['pay_amount'] += $va['pay_money']; - - $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']=$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; - - $RewardRecordRes = $this->getPromoteUserGameRewardRecordCp($add_data['company_id'],$statement_begin_time,$statement_end_time); - - if ( - ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') - || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') - ) { - $game['fine'] = 0; - $game['reward'] = 0; - } else { - $game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; - $game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; - } - - $add_data['statement_info'][] = $game; - } - }else{ - $add_data['statement_info'] = []; - } - $add_data['platform_amount'] = $add_data['pay_amount']; - if($type < 2){ - //非补点奖罚 - $rrmap = array( - "confirm_time" => ['between', [$begintime,$endtime]], - "company_type"=>1, - "company_id"=>$add_data['company_id'], - "settlement_type"=>2, - ); - $rfres = M("RewardDetail","tab_") - ->field(" - 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($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;; - } - //获取服务器费用 - $tmp_company_info= $cp[$add_data['company_id']]; - if($tmp_company_info['has_server_fee'] == 1 && $tmp_company_info['server_fee'] >0){ - $server_count = $tmp_company_info['server_fee']; - $add_data['statement_info'][] = array( - "statement_begin_time"=>$statement_begin_time, - "statement_end_time"=>$statement_end_time, - 'statement_type'=>1, - "game_name"=>"服务器费用", - 'pay_amount'=>$server_count, - 'sum_money'=>$server_count, - ); - $add_data['statement_money'] -= $server_count; - $add_data['pay_amount'] -= $server_count;; - } - } $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); - if($type == 2 && $add_data['statement_money'] == 0){ - //金额为0不补点 - continue; - } - if($add_data['platform_amount'] == 0 && $add_data['statement_money'] == 0){ - //全等于0表示没有流水,小于0依旧要结算 - continue; - } + //添加 if($recount && $company_id !== false){ //非重算 return $add_data; } - //TODO: 这里需要获取联运结算的信息 + // var_dump($add_data); $StatementDb->add($add_data); } } From a439946207a531af1a1cda927632cbef1e8529b2 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Thu, 25 Feb 2021 14:21:32 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E7=AB=99?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SubCompanyStatementSetController.class.php | 100 ++++++------------ 1 file changed, 32 insertions(+), 68 deletions(-) diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index cf06e334e..f7d81e92e 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -70,78 +70,41 @@ class SubCompanyStatementSetController extends Controller { $stime = strtotime($stime); } $nowdate = date("Y-m-d",$stime); - $w = (int)date("w",$stime); $d = (int)date("d",$stime); - if($w == 1 || $d == 1){ - if($w == 1){ - if($company == "all"){ - echo $nowdate.":".PHP_EOL; - echo "--周结begin".PHP_EOL; - - $this->cpStatement(0,$stime); - echo "∟----CP周结统计ok".PHP_EOL; - - $this->promoteCompanyStatement(0,$stime); - echo "∟----推广公司周结统计ok".PHP_EOL; - if(!IS_SUBSITE){ - $this->promoteUserPool(0,$stime); - echo "∟----推广个人周结ok".PHP_EOL; - } - - } - if($company == "cp"){ - $this->cpStatement(0,$stime); - echo "∟----CP周结统计ok".PHP_EOL; - } - if($company == "pc"){ - $this->promoteCompanyStatement(0,$stime); - echo "∟----推广公司周结统计ok".PHP_EOL; - } - if($company == "pu"){ - $this->promoteUserPool(0,$stime); - echo "∟----推广个人周结ok".PHP_EOL; - } - + if($d == 1){ + if($company == "all"){ + echo $nowdate.":".PHP_EOL; + echo "--月结&补点begin".PHP_EOL; + + $this->cpStatement(1,$stime); + echo "∟----CP月结&补点统计ok".PHP_EOL; + + $this->promoteCompanyStatement(1,$stime); + $this->promoteCompanyStatement(2,$stime); + + $this->officeCompanyStatement($stime); //官方结算 + echo "∟----官方/推广公司月结统计ok".PHP_EOL; + + $this->promoteUserPool(1,$stime); + echo "∟----推广个人月结统计ok".PHP_EOL; } - if($d == 1){ - if($company == "all"){ - echo $nowdate.":".PHP_EOL; - echo "--月结&补点begin".PHP_EOL; - - $this->cpStatement(1,$stime); - $this->cpStatement(2,$stime); - echo "∟----CP月结&补点统计ok".PHP_EOL; - - $this->promoteCompanyStatement(1,$stime); - $this->promoteCompanyStatement(2,$stime); - $this->officeCompanyStatement($stime); //官方结算 - echo "∟----官方/推广公司月结&补点统计ok".PHP_EOL; - if(!IS_SUBSITE){ - $this->promoteUserPool(1,$stime); - $this->promoteUserPool(2,$stime); - echo "∟----推广个人月结&补点统计ok".PHP_EOL; - } - } - if($company == "cp"){ - $this->cpStatement(1,$stime); - $this->cpStatement(2,$stime); - echo "∟----CP月结&补点统计ok".PHP_EOL; - } - if($company == "pc"){ - $this->promoteCompanyStatement(1,$stime); - $this->promoteCompanyStatement(2,$stime); - $this->officeCompanyStatement($stime); //官方结算 - echo "∟----官方/推广公司月结&补点统计ok".PHP_EOL; - } - if($company == "pu"){ - $this->promoteUserPool(1,$stime); - $this->promoteUserPool(2,$stime); - echo "∟----推广个人月结&补点统计ok".PHP_EOL; - } + if($company == "cp"){ + $this->cpStatement(1,$stime); + echo "∟----CP月结&补点统计ok".PHP_EOL; + } + if($company == "pc"){ + $this->promoteCompanyStatement(1,$stime); + $this->promoteCompanyStatement(2,$stime); + $this->officeCompanyStatement($stime); //官方结算 + echo "∟----官方/推广公司月结&补点统计ok".PHP_EOL; + } + if($company == "pu"){ + $this->promoteUserPool(1,$stime); + echo "∟----推广个人月结&补点统计ok".PHP_EOL; } }else{ - echo $nowdate."非周一和月初,无需任何处理".PHP_EOL; + echo $nowdate."非月初,无需任何处理".PHP_EOL; } } /** @@ -425,6 +388,8 @@ class SubCompanyStatementSetController extends Controller { $v['ratio']=0; $v['sum_money'] = 0; $v['statement_type']=0; + $v['platform_money'] = $v['pay_amount']; + $v['aggregate_money'] = 0; $add_data['platform_amount'] += $v['pay_amount']; $add_data['pay_amount'] += $v['pay_amount']; @@ -1426,7 +1391,6 @@ class SubCompanyStatementSetController extends Controller { $user['withdraw_type'] = 1; //月结&补点 $this->doPromoteUserPool($user,1,$stime,$recount); - }else{ $users['withdraw_type'] = 2; $user['withdraw_type'] = 2; From 7d650a9595bd99b7a1a18d6986fff02f28c9215a Mon Sep 17 00:00:00 2001 From: chenzhi Date: Fri, 26 Feb 2021 10:58:18 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=AD=90=E7=AB=99=E5=86=85=E5=9B=A2?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SubCompanyStatementSetController.class.php | 470 +++--------------- 1 file changed, 75 insertions(+), 395 deletions(-) diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index f7d81e92e..13ab86908 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -406,390 +406,99 @@ class SubCompanyStatementSetController extends Controller { /** * 下游结算 */ - public function promoteCompanyStatement($type,$stime,$company_id=false,$recount=true) + public function promoteCompanyStatement($type,$stime,$recount_company_id=false,$recount=true) { $t = $this->setBeginAndEndTime($type,$stime); $begintime = $t[0]; $endtime = $t[1]; + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); + $verify_log=json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]); - if($company_id === false){ - //非重算 - $where = [ - "_string"=>"first_company_type = '2' OR second_company_type = '2'" - ]; - }else{ - $where = [ - "_string"=>"(first_company_type = '2' AND first_company_id in ({$company_id}) ) OR (second_company_type = '2' AND second_company_id in ({$company_id}) )" - ]; - } - //获取哪些要结算 - if($type == 1){ - $where['settlement_type']=2; - $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); - }else{ - $where['settlement_type']=1; - $pcDbRes = M("CompanyRelation","tab_")->where($where)->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 ; - } - $pc_map = [ - "id"=>["IN",$pc_id], - "_string"=>"(validity_start_time > 0 AND validity_end_time = 0 ) OR validity_end_time >= {$endtime}", - "company_type"=>1 + //获取主站数据begin + $MainStatementDb = M("CompanyStatement","tab_"); //主站结算单 + $mainWhere = [ + "company_belong"=>["neq",9], + "withdraw_type"=>["neq",3], + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime ]; - //获取pc公司 - $tmpp = M("PromoteCompany","tab_")->field("id,uid,company_name partner,settlement_contact link_man,address,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio") - ->where($pc_map) - ->select(); -// dump($tmpp); - if(empty($tmpp)){ - return true; + if($recount_company_id !== false){ + $mainWhere['company_id'] = $recount_company_id; } - $pc =[]; - $Promote = M("Promote","tab_"); - foreach ($tmpp as $v) { - // //获取会长的支付宝账号 - // $p_map = [ - // "company_id"=>$v['id'], - // "withdraw_done"=>1 - // ]; - // $pres = $Promote->field("alipay_account,alipay_real_name")->where($p_map)->find(); - // if(!empty($pres) && !empty($pres['alipay_account']) && !empty($pres['alipay_real_name'])){ - // $v['ali_user'] = $pres['alipay_real_name']; - // $v['ali_account'] = $pres['alipay_account']; - // } - if($v['has_ratio']){ - $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); - } - $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); - - $this->getPromoteCompanySpend($pcList,array_unique(array_keys($pcList)),$begintime,$endtime); - - //数据整合 - $verify_log=json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]); + $statementList = $MainStatementDb->where($mainWhere)->select(); $StatementDb = SM("CompanyStatement","tab_"); - - $statement_begin_time = date("Y.m.d",$begintime); - $statement_end_time = date("Y.m.d",$endtime); - $RewardRecord = M("RewardDetail","tab_"); - foreach($pcList as $k=>$v){ - if(!isset($pc[$k])){continue;}//不存在的公司不结算 - if($pc[$k]['has_ratio'] == 1){ - $company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']); - }else{ - $company_ratio = 0; - } - $add_data=[]; - //1.获取甲乙方信息 - if($v['first_company_type'] > 0){ - //甲方合作 - $pc[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; - $pc[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; - - $add_data['first_party_info'] = json_encode($pc[$v['first_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['second_party_info'] = json_encode($our[$v['second_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['company_id'] = $v['first_company_id']; - $add_data['company_name'] = $v['first_company_name']; - - }else{ - //乙方合作 - $pc[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; - $pc[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; - $add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['second_party_info'] = json_encode($pc[$v['second_company_id']],JSON_UNESCAPED_UNICODE); - $add_data['company_id'] = $v['second_company_id']; - $add_data['company_name'] = $v['second_company_name']; - } - $add_data['pay_type'] = $v['collection']; - $add_data['withdraw_type'] = $type; - $add_data['statement_begin_time'] = $begintime; - $add_data['statement_end_time'] = $endtime; - $add_data['statement_money'] = 0; - $add_data['pay_amount'] = 0; - $add_data['verify_log'] = $verify_log; - $add_data['op_time'] =time(); - $add_data['is_payment']=$v['is_payment']; - $add_data['statement_info'] =[]; - - //获取渠道及发票税率 - $fax_ratio = $pc[$add_data['company_id']]['taxation_rate'] ?? 0; //税费费率 - $company_belong = $pc[$add_data['company_id']]['company_belong']; - $add_data['company_belong']=$company_belong; - $add_data['company_type']=$pc[$add_data['company_id']]['company_type']; - - if(!isset($v['game_list'])){continue;} - //获取多段比例 - $game_ratio_list = D("CompanyGameRatio")->getPromoteCompanyGameRatio($add_data['company_id'],$v['game_ids'],$begintime,$endtime,$company_belong); - - $handleed_data = []; - - foreach ($game_ratio_list as $t_game_id => $t_game_ratio) { - $game =[]; - $game['game_name'] =$v['game_list'][$t_game_id]['game_name']; - $game['relation_game_id'] =$v['game_list'][$t_game_id]['relation_game_id']; - if(isset($v['game_list'][$t_game_id]['all_pay_amount'])){ - $game_all_payment = $v['game_list'][$t_game_id]['all_pay_amount']-0; - }else{ -// $game_all_payment = $v['game_list'][$t_game_id]['pay_amount']-0; - $game_all_payment = $v['game_list'][$t_game_id]['ratio_pay_amount']-0; + $RewardRecord = SM("RewardDetail","tab_"); + if(empty($statementList)) return false; + foreach ($statementList as $k => $v) { + $v['statement_info'] = json_decode($v['statement_info'],true); + $v['statement_money'] = 0; + $v['pay_amount'] = 0; + $v['verify_status'] = 0; + $v['verify_log'] = $verify_log; + $company_id = $v['company_id']; + unset($v['id'],$v['remark'],$v['confirm_status'],$v['confirm_log']); + foreach ($v['statement_info'] as $gameindex => &$game) { + if($game['statement_type'] > 0){ + unset($v['statement_info'][$gameindex]); + continue; } - - // dump($tratio); - $game['fax_ratio']=$fax_ratio-0; - - $game['statement_type']=0; - - if(count($t_game_ratio) == 1){ - $tmp_game_ratio = $t_game_ratio[0]; - - $game['pay_amount'] =$this->getRelationGameIdSpend($add_data['company_id'],$t_game_id,$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); - -// $game['pay_amount'] = $v['game_list'][$t_game_id]['pay_amount']; - $game['pay_amount'] -=0; - - $game['statement_begin_time']=$statement_begin_time; - $game['statement_end_time']=$statement_end_time; - $add_data['pay_amount'] += $game['pay_amount']; - - if($type == 1){ - $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio += $company_ratio; - -// if ($add_data['company_id'] == 5) { -// dump($game_all_payment); -// dump($this->getTurnoverType($t_game_id,$k,$begintime,$endtime)); -// dump($tmp_game_ratio); -// } - - }elseif($type == 0){ -// $tratio = $tmp_game_ratio['ratio']; - $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); - - if ($turnover_type == 2 || $turnover_type == 4) { - $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - } else { - $tratio = $tmp_game_ratio['ratio']; - } - }else{ - //补点 - $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); - if ($turnover_type == 2 || $turnover_type == 4) { - continue; - } - $tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio2 =$tmp_game_ratio['ratio']; - $tratio = $tratio1-$tratio2+$company_ratio; - if($tratio <= 0){ continue;} - } - if($v['type'] == 2){ - $game['increment_ratio']=$tratio; - }else{ - $game['ratio']=$tratio; - } - - $RewardRecordRes = $this->getPromoteUserGameRewardRecord($add_data['company_id'],$statement_begin_time,$statement_end_time); - - if ( - ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') - || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') - ) { - $game['fine'] = 0; - $game['reward'] = 0; - } else { - $game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; - $game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; - } - - $game['sum_money']=round($game['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率) - $add_data['statement_money'] += $game['sum_money']; - if ($game['pay_amount'] != '0') { - $add_data['statement_info'][] = $game; - } - }else{ - // dd($t_game_ratio); - for ($i=0; $i < count($t_game_ratio); $i++) { - $tmp_game_ratio = $t_game_ratio[$i]; - $temp_game = $game; - $temp_game['statement_begin_time']=date("Y.m.d",$tmp_game_ratio['begintime']); - $temp_game['statement_end_time']=date("Y.m.d",$tmp_game_ratio['endtime']); - // dd($t_game_id); - $temp_game['pay_amount'] =$this->getRelationGameIdSpend($add_data['company_id'],$t_game_id,$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); - $temp_game['pay_amount'] -=0; - $add_data['pay_amount'] += $temp_game['pay_amount']; - - if($type == 1){ - -// if ($add_data['company_id'] == 5) { -// dump($game_all_payment); -// dump($this->getTurnoverType($t_game_id,$k,$begintime,$endtime)); -// dump($tmp_game_ratio); -// } - - $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio += $company_ratio; - }elseif($type == 0){ -// $tratio = $t_game_ratio['ratio']; - $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); - - if ($turnover_type == 2 || $turnover_type == 4) { - $tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - } else { - $tratio = $tmp_game_ratio['ratio']; - } - }else{ - $turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime); - if ($turnover_type == 2 || $turnover_type == 4) { - continue; - } - //补点 - $tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio2 =$tmp_game_ratio['ratio']; - $tratio = $tratio1-$tratio2+$company_ratio; - if($tratio <= 0){ continue;} - } - if($v['type'] == 2){ - $temp_game['increment_ratio']=$tratio; - }else{ - $temp_game['ratio']=$tratio; - } - - $RewardRecordRes = $this->getPromoteUserGameRewardRecord($add_data['company_id'],$temp_game['statement_begin_time'],$temp_game['statement_end_time']); - - if ( - ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') - || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') - ) { - $game['fine'] = 0; - $game['reward'] = 0; - } else { - $game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; - $game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; - } - - $temp_game['sum_money']=round($temp_game['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率) - $add_data['statement_money'] += $temp_game['sum_money']; - if ($temp_game['pay_amount'] != '0') { - $add_data['statement_info'][] = $temp_game; - } - } + $relation_game_id = $game['relation_game_id']; + $game['pay_amount'] = $this->getRelationGameIdSpend($company_id,$relation_game_id,$begintime,$endtime); + if($game['pay_amount'] <= 0){ + unset($v['statement_info'][$gameindex]); + continue; } + $v['pay_amount'] += $game['pay_amount']; + $game['sum_money'] = round($game['pay_amount']*$game['ratio']*(100-$game['fax_ratio'])/100/100,2); + $v['statement_money'] += $game['sum_money']; } - $add_data['platform_amount'] = $add_data['pay_amount']; - if($type < 2){ - //非补点计算奖罚 - $rrmap = array( - "confirm_time" => ['between', [$begintime,$endtime]], - "company_type"=>2, - "company_id"=>$add_data['company_id'], - "settlement_type"=>2, + $v['platform_amount'] = $v['pay_amount']; + //奖罚 + $rrmap = ["confirm_time" => ['between', [$begintime,$endtime]],"company_type"=>2,"company_id"=>$company_id,"settlement_type"=>2]; + $rfres = $RewardRecord->field("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($rrmap)->find(); + + if($rfres['reward_count'] > 0){ + $reward_count = $rfres['reward_count']; + $v['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, ); - $rfres = M("RewardDetail","tab_") - ->field(" - 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($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;; - } - //获取服务器费用 - $tmp_company_info= $pc[$add_data['company_id']]; - if($tmp_company_info['has_server_fee'] == 1 && $tmp_company_info['server_fee'] >0){ - $server_count = $tmp_company_info['server_fee']; - $add_data['statement_info'][] = array( - "statement_begin_time"=>$statement_begin_time, - "statement_end_time"=>$statement_end_time, - 'statement_type'=>1, - "game_name"=>"服务器费用", - 'pay_amount'=>$server_count, - 'sum_money'=>$server_count, - ); - $add_data['statement_money'] -= $server_count; - $add_data['pay_amount'] -= $server_count;; - } + $v['statement_money'] += $reward_count; + $v['pay_amount'] += $reward_count; } - - - $is_continue = false; - $statement_data = $add_data['statement_info']; - foreach ($statement_data as $skey => $sval) { - if ($sval) { - $is_continue = true; - } - } - - if (!$is_continue) { - continue; - } - - $add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE); - if($type == 2 && $add_data['statement_money'] == 0){ + if($rfres['fine_count'] > 0){ + $fine_count = $rfres['fine_count']; + $v['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, + ); + $v['statement_money'] -= $fine_count; + $v['pay_amount'] -= $fine_count;; + } + $v['statement_info'] = json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE); + if($type == 2 && $v['statement_money'] == 0){ //金额为0不补点 continue; } - if($add_data['platform_amount'] == 0){ + if($v['platform_amount'] == 0){ continue; } //添加 - if($recount === true && $company_id !== false){ + if($recount === true && $recount_company_id !== false){ //非重算 - return $add_data; + return $v; } - $StatementDb->add($add_data); + + $StatementDb->add($v); } } //设定开始结束时间 @@ -1152,7 +861,6 @@ class SubCompanyStatementSetController extends Controller { "s.payed_time"=>['elt',$endtime] ]; D("Spend")->addSubsiteWhere($cpAllMap,"s"); -// unset($cpAllMap["s.payed_time"]); for ($i=0; $i join("left join tab_game g on s.game_id = g.id") ->select(); -// if ($company_id == 64) { -// dump($all_list); -// } - if(empty($list)){continue;} $game = []; foreach($list as $k=>$v){ @@ -1228,9 +932,6 @@ class SubCompanyStatementSetController extends Controller { $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') ->join("left join tab_game g on s.game_id = g.id") ->select(); -// if ($company_id == 43) { -// dump($cpMap); -// } foreach($cpSpendList as $ck=>$cv){ if(isset($cpgame[$cv['relation_game_id']])){ $cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; @@ -1259,10 +960,8 @@ class SubCompanyStatementSetController extends Controller { $temp += $cpallgame[$v[$j]]['pay_amount']; } else { -// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount']; $temp += $game[$v[$j]]['pay_amount']; } -// $temp += $game[$v[$j]]['pay_amount']; } $sameGame[$k] = $temp; } @@ -1290,7 +989,6 @@ class SubCompanyStatementSetController extends Controller { $turnover_type = $this->getTurnoverType($v['relation_game_id'],$company_id,$begintime,$endtime); if ($turnover_type == 2) { -// $temp += $allgame[$v[$j]]['pay_amount']; $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $allgame[$v['relation_game_id']]['pay_amount']; } elseif($turnover_type == 3) { @@ -1298,10 +996,6 @@ class SubCompanyStatementSetController extends Controller { $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') ->join("left join tab_game g on s.game_id = g.id") ->select(); -// if ($company_id == 43) { -// dump($cpMap); -// } - foreach($cpSpendList as $ck=>$cv){ if(isset($cpgame[$cv['relation_game_id']])){ $cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; @@ -1330,11 +1024,8 @@ class SubCompanyStatementSetController extends Controller { $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpallgame[$v['relation_game_id']]['pay_amount']; } else { -// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount']; $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount']; } - -// $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount']; $res[$company_id][$p_account][$v['relation_game_id']]['game_type_name'] = $this->getGameTypeName($v['relation_game_id']); } } @@ -1413,14 +1104,8 @@ class SubCompanyStatementSetController extends Controller { $where = [ "_string"=>"first_company_type = '2' OR second_company_type = '2'" ]; - //获取哪些要结算 - if($type == 1){//月结 - $where['settlement_type']=2; - $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); - }else{ - $where['settlement_type']=1; - $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); - } + $pcDbRes = M("CompanyRelation","tab_")->where($where)->select(); + $pcList=[]; $js_id = [];//己方公司 @@ -1453,11 +1138,6 @@ class SubCompanyStatementSetController extends Controller { "company_id"=>$v['id'], "withdraw_done"=>1 ]; - // $pres = $Promote->field("alipay_account,alipay_real_name")->where($p_map)->find(); - // if(!empty($pres) && !empty($pres['alipay_account']) && !empty($pres['alipay_real_name'])){ - // $v['ali_user'] = $pres['alipay_real_name']; - // $v['ali_account'] = $pres['alipay_account']; - // } if($v['has_ratio']){ $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); } @@ -1468,7 +1148,7 @@ class SubCompanyStatementSetController extends Controller { unset($tmpp); $this->getPuPromoteSpend($pc,array_unique(array_keys($pc)),$begintime,$endtime); -// dump($pc);die(); + dump($pc);die(); $StatementDb = SM("CompanyStatement","tab_"); $statement_begin_time = date("Y.m.d",$begintime); From c285a88c8d4708d9428b60957f74316835954ed8 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Fri, 26 Feb 2021 11:15:25 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E7=AB=99?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/Conf/config.php | 2 - ...SubCompanyStatementSetController.class.php | 258 ------------------ 2 files changed, 260 deletions(-) diff --git a/Application/Admin/Conf/config.php b/Application/Admin/Conf/config.php index 2b3384f87..cf0381a21 100644 --- a/Application/Admin/Conf/config.php +++ b/Application/Admin/Conf/config.php @@ -119,8 +119,6 @@ return array( "sys_auth_group", "tab_index_chart", "tab_company_statement", - "tab_company_lack_statement_info", - "tab_company_statement_info", "tab_company_statement_pool", "tab_financial_summary", "tab_pay_statement_info", diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index 13ab86908..6917e7377 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -523,264 +523,6 @@ class SubCompanyStatementSetController extends Controller { } return [$begintime,$endtime]; } - //获取推广公司推广金额 - public function getPromoteCompanySpend(&$pcList,$idarr,$begintime,$endtime){ - $res = []; - $all_res = []; - $cp_res = []; - $cp_all_res = []; - //获取推广员 - if(count($idarr) == 0){return $res;} - $Promote = M("Promote","tab_"); - $Spend = M("Spend","tab_"); - $spenMap = [ - "s.pay_status"=>1, - "s.payed_time"=>['between', [$begintime,$endtime]], - "s.is_check"=>1 - ]; - D("Spend")->addSubsiteWhere($spenMap); - $cpMap = [ - "s.pay_status"=>1, - "s.payed_time"=>['between', [$begintime,$endtime]] - ]; - D("Spend")->addSubsiteWhere($cpMap); - $cpAllMap =[ - "s.pay_status"=>1, - "s.payed_time"=>['elt',$endtime] - ]; - D("Spend")->addSubsiteWhere($cpAllMap); - - for ($i=0; $i field("group_concat(id) ids,count(id) count")->where("company_id = '{$company_id}'")->group("company_id")->find(); - if($pres['count'] ==0 ){continue;} - $spenMap['s.promote_id']=["in",$pres['ids']]; - //获取支付记录 - $list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - - $allSpendMap = $spenMap; - unset($allSpendMap["s.payed_time"]); - - $allspend_list = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($allSpendMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - - foreach($allspend_list as $k=>$v){ - try { - $all_res[$company_id]["pay_amount"] += $v['pay_amount']; - } catch (\Throwable $th) { - $all_res[$company_id]["pay_amount"] = $v['pay_amount']; - } - if(isset($all_res[$company_id][$v['relation_game_id']])){ - // - $all_res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; - }else{ - unset($v['game_id']); - $all_res[$company_id][$v['relation_game_id']]= $v; - } - } - - - if(empty($list)){continue;} - - foreach($list as $k=>$v){ - - try { - $res[$company_id]["pay_amount"] += $v['pay_amount']; - } catch (\Throwable $th) { - $res[$company_id]["pay_amount"] = $v['pay_amount']; - } - if(isset($res[$company_id][$v['relation_game_id']])){ - // - - $res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; - - $res[$company_id][$v['relation_game_id']]['ratio_pay_amount'] += $v['pay_amount']; - }else{ - - unset($v['game_id']); - $v['ratio_pay_amount'] = $v['pay_amount']; - $res[$company_id][$v['relation_game_id']]= $v; - } - } - - $game_ids = implode(",",array_unique(array_column($list,"relation_game_id"))); - $game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime); - $sameGame = $this->getTheSameGame($game_ids); - - - if(!empty($sameGame)){ - foreach ($sameGame as $k => $v) { - - $temp = 0; - for ($j=0; $j < count($v); $j++) { - -// $turnover_where = [ -// "relation_game_id"=>$v[$j], -// "company_id"=>$company_id, -// "_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})" -// ]; -// $turnover_type = D("CompanyGameRatio")->field("turnover_type")->where($turnover_where)->find()['turnover_type']; - $turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime); - - if ($turnover_type == 2) { - $res[$company_id][$v[$j]]['ratio_pay_amount'] = $all_res[$company_id][$v[$j]]['pay_amount']; - $temp += $all_res[$company_id][$v[$j]]['pay_amount']; - } elseif($turnover_type == 3){ - if (empty($cp_res[$company_id])) { - $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - -// if ($company_id == 5) { -// dump($cpMap); -// } - - foreach($cpSpendList as $ck=>$cv){ - try { - $cp_res[$company_id]["pay_amount"] += $cv['pay_amount']; - } catch (\Throwable $th) { - $cp_res[$company_id]["pay_amount"] = $cv['pay_amount']; - } - if(isset($cp_res[$company_id][$cv['relation_game_id']])){ - // - $cp_res[$company_id][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - }else{ - unset($cv['game_id']); - $cp_res[$company_id][$cv['relation_game_id']]= $cv; - } - } - } - - - $res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_res[$company_id][$v[$j]]['pay_amount']; - $temp += $cp_res[$company_id][$v[$j]]['pay_amount']; - - } elseif($turnover_type == 4){ - - if (empty($cp_all_res[$company_id])) { - - $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - foreach ($cpAllSpendList as $ck => $cv) { - try { - $cp_all_res[$company_id]["pay_amount"] += $cv['pay_amount']; - } catch (\Throwable $th) { - $cp_all_res[$company_id]["pay_amount"] = $cv['pay_amount']; - } - if (isset($cp_all_res[$company_id][$cv['relation_game_id']])) { - // - $cp_all_res[$company_id][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - } else { - unset($cv['game_id']); - $cp_all_res[$company_id][$cv['relation_game_id']] = $cv; - } - } - } - - - $res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_all_res[$company_id][$v[$j]]['pay_amount']; - $temp += $cp_all_res[$company_id][$v[$j]]['pay_amount']; - - } else { -// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount']; - $temp += $res[$company_id][$v[$j]]['pay_amount']; - } - - - } - $sameGame[$k] = $temp; - } - foreach ($sameGame as $k => $v) { - $res[$company_id][$k]['all_pay_amount'] = $v; - // $game[$k]['pay_amount']= $v; - } - } - - } - - - foreach($res as $key=>$value){ - - foreach ($value as $k => $v){ - if ($k!='pay_amount') { - - $turnover_type = $this->getTurnoverType($k,$key,$begintime,$endtime); - - if ($turnover_type == 2) { - $res[$key][$k]['ratio_pay_amount'] = $all_res[$key][$k]['pay_amount']; - } elseif($turnover_type == 3){ - - if (empty($cp_res[$key])) { -// if ($key == 5) { -// dump(2); -// dump($cpMap); -// dump($cp_res); -// } - $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - - foreach($cpSpendList as $ck=>$cv){ - try { - $cp_res[$key]["pay_amount"] += $cv['pay_amount']; - } catch (\Throwable $th) { - $cp_res[$key]["pay_amount"] = $cv['pay_amount']; - } - if(isset($cp_res[$key][$cv['relation_game_id']])){ - // - $cp_res[$key][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - }else{ - unset($cv['game_id']); - $cp_res[$key][$cv['relation_game_id']]= $cv; - } - } - } - - $res[$key][$k]['ratio_pay_amount'] = $cp_res[$key][$k]['pay_amount']; - } elseif($turnover_type == 4){ - - if (empty($cp_all_res[$key])) { - - $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - foreach ($cpAllSpendList as $ck => $cv) { - try { - $cp_all_res[$key]["pay_amount"] += $cv['pay_amount']; - } catch (\Throwable $th) { - $cp_all_res[$key]["pay_amount"] = $cv['pay_amount']; - } - if (isset($cp_all_res[$key][$cv['relation_game_id']])) { - // - $cp_all_res[$key][$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - } else { - unset($cv['game_id']); - $cp_all_res[$key][$cv['relation_game_id']] = $cv; - } - } - } - - $res[$key][$k]['ratio_pay_amount'] = $cp_all_res[$key][$k]['pay_amount']; - } - - } - } - - } - - foreach($res as $k=>$v){ - $pcList[$k]["pay_amount"] = $v['pay_amount']; - unset($v['pay_amount']); - $pcList[$k]['game_list'] = $v; - $pcList[$k]['game_ids'] = implode(",",array_keys($pcList[$k]['game_list'])); - } - - } /** * 返回结算流水类型 */ From 3263c108c3c28a5c74e70a226924fc3e9fe87ea5 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Sat, 27 Feb 2021 13:39:48 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Admin/Conf/config.php | 1 + ...SubCompanyStatementSetController.class.php | 650 +++--------------- 2 files changed, 95 insertions(+), 556 deletions(-) diff --git a/Application/Admin/Conf/config.php b/Application/Admin/Conf/config.php index cf0381a21..aad877cab 100644 --- a/Application/Admin/Conf/config.php +++ b/Application/Admin/Conf/config.php @@ -117,6 +117,7 @@ return array( /*分库的表格*/ 'SUBSITE_TABLE'=>[ "sys_auth_group", + "sub_user_statement", "tab_index_chart", "tab_company_statement", "tab_company_statement_pool", diff --git a/Application/Admin/Controller/SubCompanyStatementSetController.class.php b/Application/Admin/Controller/SubCompanyStatementSetController.class.php index 6917e7377..7018a81e3 100644 --- a/Application/Admin/Controller/SubCompanyStatementSetController.class.php +++ b/Application/Admin/Controller/SubCompanyStatementSetController.class.php @@ -502,7 +502,7 @@ class SubCompanyStatementSetController extends Controller { } } //设定开始结束时间 - public function setBeginAndEndTime($type,$stime){ + protected function setBeginAndEndTime($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; @@ -526,7 +526,7 @@ class SubCompanyStatementSetController extends Controller { /** * 返回结算流水类型 */ - public function getTurnoverType($relation_game_id = 0, $company_id = 0, $begin_time = 0, $end_time = 0){ + protected function getTurnoverType($relation_game_id = 0, $company_id = 0, $begin_time = 0, $end_time = 0){ $company_belong = M("promote_company","tab_")->field("company_belong")->where(['id'=>$company_id])->find(); if (!$company_belong) { @@ -581,6 +581,8 @@ class SubCompanyStatementSetController extends Controller { //获取推广公司推广金额 protected function getPuPromoteSpend(&$pcList,$idarr,$begintime,$endtime){ $res = []; + $statement_begin_time = date("Y.m.d",$begintime); + $statement_end_time = date("Y.m.d",$endtime); //获取推广员 if(count($idarr) == 0){return $res;} $Promote = M("Promote","tab_"); @@ -591,19 +593,6 @@ class SubCompanyStatementSetController extends Controller { "s.is_check"=>1 ]; D("Spend")->addSubsiteWhere($spenMap,"s"); - $cpallgame = []; - $cpgame = []; - $cpMap = [ - "s.pay_status"=>1, - "s.payed_time"=>['between', [$begintime,$endtime]] - ]; - D("Spend")->addSubsiteWhere($cpMap,"s"); - $cpAllMap = [ - "s.pay_status"=>1, - "s.payed_time"=>['elt',$endtime] - ]; - D("Spend")->addSubsiteWhere($cpAllMap,"s"); - for ($i=0; $i alias('s') - ->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id") + ->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,g.game_type_name") ->where($spenMap) - ->group('p_id,game_id') - ->join("tab_promote promote ON s.promote_id = promote.id","left") + ->group('game_id') ->join("left join tab_game g on s.game_id = g.id") ->select(); - $all_spendMap = $spenMap; - unset($all_spendMap['s.payed_time']); - - $all_list = $Spend - ->alias('s') - ->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id") - ->where($all_spendMap) - ->group('p_id,game_id') - ->join("tab_promote promote ON s.promote_id = promote.id","left") - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - - if(empty($list)){continue;} + if(empty($list)){unset($pcList[$company_id]);continue;} $game = []; foreach($list as $k=>$v){ if(isset($game[$v['relation_game_id']])){ $game[$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; }else{ - $game[$v['relation_game_id']]['pay_amount'] = $v['pay_amount']; + $game[$v['relation_game_id']] = $v; } } - - $allgame = []; - foreach($all_list as $k=>$v){ - if(isset($allgame[$v['relation_game_id']])){ - $allgame[$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; - }else{ - $allgame[$v['relation_game_id']]['pay_amount'] = $v['pay_amount']; - } - } - //同cp,同一个原包名的共享总流水分成 $game_ids = implode(",",array_keys($game)); $game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime); @@ -665,45 +631,7 @@ class SubCompanyStatementSetController extends Controller { foreach ($sameGame as $k => $v) { $temp = 0; for ($j=0; $j < count($v); $j++) { - $turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime); - if ($turnover_type == 2) { - $temp += $allgame[$v[$j]]['pay_amount']; - } elseif($turnover_type == 3) { - - if (empty($cpgame)) { - $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - foreach($cpSpendList as $ck=>$cv){ - if(isset($cpgame[$cv['relation_game_id']])){ - $cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - }else{ - $cpgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; - } - } - } - - $temp += $cpgame[$v[$j]]['pay_amount']; - } elseif($turnover_type == 4) { - - if (empty($cpallgame)) { - $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - - foreach($cpAllSpendList as $ck=>$cv){ - if(isset($cpallgame[$cv['relation_game_id']])){ - $cpallgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - }else{ - $cpallgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; - } - } - } - - $temp += $cpallgame[$v[$j]]['pay_amount']; - } else { - $temp += $game[$v[$j]]['pay_amount']; - } + $temp += $game[$v[$j]]['pay_amount']; } $sameGame[$k] = $temp; } @@ -711,78 +639,26 @@ class SubCompanyStatementSetController extends Controller { $game[$k]['pay_amount']= $v; } } - $pcList[$company_id]['game_ids'] = implode(",",array_keys($game)); - - foreach($list as $k=>$v){ - try { - $res[$company_id]["pay_amount"] += $v['pay_amount']; - } catch (\Throwable $th) { - $res[$company_id]["pay_amount"] = $v['pay_amount']; - } - $p_account = $promote_a[$v['p_id']]; - - if(isset($res[$company_id][$p_account][$v['relation_game_id']])){ - // - $res[$company_id][$p_account][$v['relation_game_id']]['pay_amount'] += $v['pay_amount']; - }else{ - unset($v['game_id']); - $res[$company_id][$p_account][$v['relation_game_id']]= $v; - - $turnover_type = $this->getTurnoverType($v['relation_game_id'],$company_id,$begintime,$endtime); - - if ($turnover_type == 2) { - $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $allgame[$v['relation_game_id']]['pay_amount']; - } elseif($turnover_type == 3) { - - if (empty($cpgame)) { - $cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - foreach($cpSpendList as $ck=>$cv){ - if(isset($cpgame[$cv['relation_game_id']])){ - $cpgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - }else{ - $cpgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; - } - } - } - - $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpgame[$v['relation_game_id']]['pay_amount']; - } elseif($turnover_type == 4) { - - if (empty($cpallgame)) { - $cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id') - ->join("left join tab_game g on s.game_id = g.id") - ->select(); - - foreach($cpAllSpendList as $ck=>$cv){ - if(isset($cpallgame[$cv['relation_game_id']])){ - $cpallgame[$cv['relation_game_id']]['pay_amount'] += $cv['pay_amount']; - }else{ - $cpallgame[$cv['relation_game_id']]['pay_amount'] = $cv['pay_amount']; - } - } - } - - $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpallgame[$v['relation_game_id']]['pay_amount']; - } else { - $res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount']; - } - $res[$company_id][$p_account][$v['relation_game_id']]['game_type_name'] = $this->getGameTypeName($v['relation_game_id']); - } - } - } - - foreach($res as $k=>$v){ - $pcList[$k]["pay_amount"] = $v['pay_amount']; - unset($v['pay_amount']); - foreach($v as $ke=>$va){ - $tmp = [ - "account"=>$ke, - 'game_list'=>$va - ]; - $pcList[$k]['list'][] = $tmp; + // if($company_id == 23) dd($game); + //计算比例 + $pay_amount = 0; + $sum_money = 0; + $statementInfo = []; + foreach ($game as $k => $v) { + $company_belong = $pcList[$company_id]['company_belong']; + $gameOther =$this->getPuGameRatio($company_id,$company_belong,$k,$v['pay_amount'],$begintime,$endtime); + $v['ratio'] = $gameOther[0]; + $v['sum_money'] = $gameOther[1]; + $v['statement_begin_time'] = $statement_begin_time; + $v['statement_end_time'] = $statement_end_time; + $statementInfo[] = $v; + + $pay_amount += $v['pay_amount']; + $sum_money += $v['sum_money']; } + $pcList[$company_id]['statement_info'] = $statementInfo; + $pcList[$company_id]['pay_amount'] = $pay_amount; + $pcList[$company_id]['sum_money'] = $sum_money; } } public function promoteUserPool($type,$stime,$recount = false){ @@ -790,48 +666,14 @@ class SubCompanyStatementSetController extends Controller { $begintime = $t[0]; $endtime = $t[1]; - $user = [ - "pay_amount"=>0, - "statement_money"=>0, - "lack_statement_money"=>0, - "withdraw_type"=>$type, - "platform_amount"=>0, - "create_lack_ids"=>[], - "del_lack_ids"=>[], - "statement_begin_time"=>$begintime, - "statement_end_time"=>$endtime, - "fine"=>0, - "reward"=>0, - "verify_status"=>0, - "company_type"=>2, - "verify_log"=>json_encode(["create_user"=>"system","create_time"=>date("Y-m-d H:i:s")]), - "op_time"=>time(), - "statement_num"=>"PL_".date('Ymd').date('His').sp_random_num(3) - ]; - // $users = $user = $basedata; - // $users['is_payment'] = 1; - // $users['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3); - - // $user['is_payment'] = 2; - // $user['statement_num'] = "PL_".date('Ymd').date('His').sp_random_num(3); - - - - if($type == 0){//周结 - $this->doPromoteUserPool($user,0,$stime,$recount); - }else if($type == 1){ - $users['withdraw_type'] = 1; - $user['withdraw_type'] = 1; - //月结&补点 - $this->doPromoteUserPool($user,1,$stime,$recount); - }else{ - $users['withdraw_type'] = 2; - $user['withdraw_type'] = 2; - $this->doPromoteUserPool($user,2,$stime,$recount); + $statementInfo = $this->doPromoteUserPool($user,1,$stime,$recount); + if($recount){ + SM("user_statement","sub_")->where([ + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime + ])->delete(); } - - $this->savePromotateUserPool($user); - + SM("user_statement","sub_")->add($statementInfo); } /** @@ -868,7 +710,7 @@ class SubCompanyStatementSetController extends Controller { "company_type"=>2 ]; $tmpp = M("PromoteCompany","tab_") - ->field("id,uid,company_name partner,settlement_contact link_man,contact_phone link_phone,bank_name opening_bank,bank_address payee_name,bank_card bank_account,fax_ratio,taxation_rate,company_belong,company_type,ali_user,ali_account,has_server_fee,server_fee,has_ratio,turnover_ratio") + ->field("id,company_name partner,company_belong,company_type") ->where($pu_map) ->select(); if(count($tmpp)<1){return;} @@ -876,374 +718,29 @@ class SubCompanyStatementSetController extends Controller { $pc =[]; $Promote = M("Promote","tab_"); foreach ($tmpp as $v) { - $p_map = [ - "company_id"=>$v['id'], - "withdraw_done"=>1 - ]; - if($v['has_ratio']){ - $v['turnover_ratio'] = json_decode($v['turnover_ratio'],true); - } - $pc[$v['id']]=$v; - $pc[$v['id']]['is_payment']=$pcList[$v['id']]['is_payment']; } unset($tmpp); - $this->getPuPromoteSpend($pc,array_unique(array_keys($pc)),$begintime,$endtime); - dump($pc);die(); - - $StatementDb = SM("CompanyStatement","tab_"); - $statement_begin_time = date("Y.m.d",$begintime); - $statement_end_time = date("Y.m.d",$endtime); - // $RewardRecord = M("RewardRecord","tab_"); - $LackStatement = SM("company_lack_statement_info","tab_"); - $StatementInfo = SM("company_statement_info","tab_"); - foreach($pc as $k=>&$v){ - $fax_ratio = $v['taxation_rate']; - $RewardRecordRes = $this->getPromoteUserRewardRecord($v['id'],$begintime,$endtime); - if($v['has_ratio'] == 1){ - $company_ratio = $this->getCompanyRatio($v['pay_amount'],$pc[$k]['turnover_ratio']); - }else{ - $company_ratio = 0; - } - //获取其他信息 - $v = $this->getCompanyOtherInfo($v,$k); - $countdata = &$user; - $v['statement_money'] = 0; - $v['pay_amount'] = 0; - if($type < 2 && $RewardRecordRes){ - $v['fine'] = $RewardRecordRes['fine']; - $v['reward'] = $RewardRecordRes['reward']; - $v['statement_money'] -= $v['fine']; - $v['statement_money'] += $v['reward']; - }else{ - $v['fine'] = 0; - $v['reward'] = 0; - } - $v['platform_amount'] = 0; - if(!isset($v['list'])){continue;} - $company_belong = $pc[$v['id']]['company_belong']; - //服务器费用 - if ($type < 2) { - if ($v['has_server_fee'] == 1 && $v['server_fee'] > 0) { - $v['statement_info'][] = [ - "game_name"=>"服务器费用", - "sum_money"=>-$v['server_fee'], - "pay_amount"=>-$v['server_fee'], - 'statement_type'=>1, - "statement_begin_time"=>$statement_begin_time, - "statement_end_time"=>$statement_end_time - ]; - $v['pay_amount'] -= $v['server_fee']; - $v['statement_money'] -= $v['server_fee']; - } - } - $promoteCompanyGameRatio = D("CompanyGameRatio")->getPromoteCompanyGameRatio($v['id'],$v['game_ids'],$begintime,$endtime,$company_belong); - - $handleed_data = []; - - foreach($v['list'] as $ke=>$va){ - $templist = $va['game_list']; - $va['game_list'] = []; - foreach($templist as $p_id => $p_info){ - - $ratioCount = count($promoteCompanyGameRatio[$p_info['relation_game_id']]); - $isMoreRatio = $ratioCount > 1 ? true : false; - - if(!$isMoreRatio){ - $tmp_game_ratio = $promoteCompanyGameRatio[$p_info['relation_game_id']][0]; - if($type == 1){ - $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio += $company_ratio; - }elseif($type == 0){ -// $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); -// $tratio = $tmp_game_ratio['ratio']; - $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); - -// if ($v['id'] == 5) { -// dump($p_info['all_pay_amount']); -// dump($turnover_type); -// dump($tmp_game_ratio); -// } - - if ($turnover_type == 2||$turnover_type == 4) { - $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - } else { - $tratio = $tmp_game_ratio['ratio']; - } - }else{ - $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); - if ($turnover_type == 2||$turnover_type == 4) { - continue; - } - //补点 - $tratio1 =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio2 =$tmp_game_ratio['ratio']; - $tratio = $tratio1-$tratio2+$company_ratio; - if($tratio <= 0){ continue;} - } - $tratio -= 0; - if($type == 2){ - $p_info['increment_ratio']=$tratio; - }else{ - $p_info['ratio']=$tratio; - } - - $p_info['pay_amount'] = $this->getRelationGameIdPromoteSpend($p_info["p_id"],$p_info['relation_game_id'],$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); - - $p_info['pay_amount'] = number_format($p_info['pay_amount'],2,'.',''); - - $v['platform_amount'] += $p_info['pay_amount']; - $p_info['sum_money']=round($p_info['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例 - $v['pay_amount'] += $p_info['sum_money']; - $v['statement_money'] += $p_info['sum_money']; - $p_info['fax_ratio']=$fax_ratio; - $p_info['statement_begin_time']=$statement_begin_time; - $p_info['statement_end_time']=$statement_end_time; - - $RewardRecordRes = $this->getPromoteUserGameRewardRecord($v['id'],$statement_begin_time,$statement_end_time); - - if ( - ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] == '0') - || ($handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] || $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] == '0') - ) { - $p_info['fine'] = 0; - $p_info['reward'] = 0; - } else { - $p_info['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; - $p_info['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['fine'] = (string)$RewardRecordRes['fine']; - $handleed_data[$v['id'].$statement_begin_time.$statement_end_time]['reward'] = (string)$RewardRecordRes['reward']; - } -// if ($p_info['relation_game_id'] == 191 && $v['id'] == 334) { -// dump($RewardRecordRes); -// } - - - - $p_info['statement_type']=0; - - if ($p_info['pay_amount'] !='0') { - $va['game_list'][] = $p_info; - } - - - }else{ - for ($i=0; $i < $ratioCount; $i++) { - $temp_game = []; - $tmp_game_ratio = $promoteCompanyGameRatio[$p_info['relation_game_id']][$i]; - if($type == 1){ - $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio += $company_ratio; - }elseif($type == 0){ - - $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); -// if ($v['id'] == 5) { -// dump($p_info['all_pay_amount']); -// dump($turnover_type); -// dump($tmp_game_ratio); -// } - if ($turnover_type == 2 || $turnover_type == 4) { - $tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - } else { - $tratio = $tmp_game_ratio['ratio']; - } - - - }else{ - $turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime); - if ($turnover_type == 2 || $turnover_type == 4) { - continue; - } - //补点 - $tratio1 =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']); - $tratio2 =$tmp_game_ratio['ratio']; - $tratio = $tratio1-$tratio2+$company_ratio; - if($tratio <= 0){ continue;} - } - $tratio -= 0; - if($type == 2){ - $temp_game['increment_ratio']=$tratio; - }else{ - $temp_game['ratio']=$tratio; - } - $temp_game['pay_amount'] = $this->getRelationGameIdPromoteSpend($p_info["p_id"],$p_info['relation_game_id'],$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']); - $temp_game['pay_amount'] -=0; - $temp_game['pay_amount'] = number_format($temp_game['pay_amount'],2,'.',''); - - $v['platform_amount'] += $temp_game['pay_amount']; - $temp_game['sum_money']=round($temp_game['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例 - $v['pay_amount'] += $temp_game['sum_money']; - $v['statement_money'] += $temp_game['sum_money']; - - $temp_game['fax_ratio']=$fax_ratio-0; - $temp_game['statement_begin_time']=date("Y.m.d",$tmp_game_ratio['begintime']); - $temp_game['statement_end_time']=date("Y.m.d",$tmp_game_ratio['endtime']); - $temp_game['statement_type']=0; - - $RewardRecordRes = $this->getPromoteUserGameRewardRecord($v['id'],$temp_game['statement_begin_time'],$temp_game['statement_end_time']); - - if ( - ($handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] || $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] == '0') - || ($handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] || $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] == '0') - ) { - $temp_game['fine'] = 0; - $temp_game['reward'] = 0; - } else { - $temp_game['fine'] = $RewardRecordRes['fine']?$RewardRecordRes['fine']:0; - $temp_game['reward'] = $RewardRecordRes['reward']?$RewardRecordRes['reward']:0; - $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['fine'] = (string)$RewardRecordRes['fine']; - $handleed_data[$v['id'].$temp_game['statement_begin_time'].$temp_game['statement_end_time']]['reward'] = (string)$RewardRecordRes['reward']; - } -// if ($p_info['relation_game_id'] == 191 && $v['id'] == 334) { -// dump($RewardRecordRes); -// } - - $temp_game['statement_type']=0; - - $temp_game['relation_game_id']=$p_info["relation_game_id"]; - $temp_game['game_name']=$p_info["game_name"]; - $temp_game['game_type_name']=$p_info["game_type_name"]; - $temp_game['all_pay_amount']=$p_info["all_pay_amount"]; - - if ($temp_game['pay_amount'] != '0') { - $va['game_list'][] = $temp_game; - } - - } - } - } - $v['statement_info'][] = $va; - } - $company_info = [ - 'account'=>$v['account'], - "company_relation_str"=>$v['company_relation_str'], - "company_belong_str"=>$v['company_belong_str'], - "company_type_str"=>$v['company_type_str'], - "nickname"=>$v['nickname'], - "payee_name"=>$v['payee_name'], - "bank_account"=>$v['bank_account'], - "opening_bank"=>$v['opening_bank'], - "ali_user"=>$v['ali_user'], - "ali_account"=>$v['ali_account'] - ]; - if($v['platform_amount'] < 300){ - $lackcompany =[ - "company_id"=>$k, - "company_type"=>2, - "company_name"=>$v['partner'], - "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), - "statement_money"=>$v['statement_money'], - "pay_amount"=>$v['pay_amount'], - "platform_amount"=>$v['platform_amount'], - "fine"=>$v['fine'], - "reward"=>$v['reward'], - "statement_begin_time"=>$begintime, - "statement_end_time"=>$endtime, - - "statement_pool_num"=>$countdata['statement_num'],//母单 - - "is_payment"=>$v['is_payment'], - "statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE) - ]; - } - $is_continue = false; - $statement_data = $v['statement_info']; - foreach ($statement_data as $skey => $sval) { - if ($sval['game_list']) { - $is_continue = true; - } -// dump($sval); - } - - if (!$is_continue) { - continue; - } - - //无需补点不统计其他金额 - if($type == 2 && $v['statement_money'] == 0){ - continue ; - } - //聚合未结算数据 - $lsres = $LackStatement->where("company_id='{$k}' and is_pool = 0")->select(); - $del_lack_ids = []; - if(count($lsres) > 0){ - //进行聚合 - foreach($lsres as $key=>$val){ - - $del_lack_ids[] = $val['id']; - $v['statement_money'] += $val['statement_money']; - $v['pay_amount'] += $val['pay_amount']; - $v['fine'] += $val['fine']; - $v['reward'] += $val['reward']; - $v['platform_amount'] += $val['platform_amount']; - $t_statement_info = json_decode($val['statement_info'],true); - $statement_info = []; - foreach($t_statement_info as $p=>$info){ - $statement_info[$info['account']] = $info['game_list']; - } - foreach($v['statement_info'] as $p=>$info){ - if(isset($statement_info[$info['account']])){ - $v['statement_info'][$p]['game_list'] = array_merge($statement_info[$info['account']],$v['statement_info'][$p]['game_list']); - unset($statement_info[$info['account']]); - } - } - if(!empty($statement_info)){ - foreach($statement_info as $p=>$info){ - $v['statement_info'][] = ["account"=>$p,"game_list"=>$info]; - } - } - } - } - if($v['platform_amount'] == 0 && $v['statement_money'] == 0){ - continue ; - } - - if($v['platform_amount'] < 300){ - //存未满 - // if($lackcompany['pay_amount'] != 0){ - $lask_id = $LackStatement->add($lackcompany); - $countdata['create_lack_ids'][] =$lask_id; - $countdata['lack_statement_money'] +=$lackcompany['statement_money']; - $countdata['lack_platform_amount'] +=$lackcompany['platform_amount']; - // } - - }else{ - // if($v['pay_amount'] != 0){ - //存成功配置单号 - $company =[ - "pool_id"=>0, - "company_id"=>$k, - "company_type"=>2, - "company_name"=>$v['partner'], - "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE), - "statement_money"=>$v['statement_money'], - "pay_amount"=>$v['pay_amount'], - "platform_amount"=>$v['platform_amount'], - "fine"=>$v['fine'], - "reward"=>$v['reward'], - "statement_begin_time"=>$begintime, - "statement_end_time"=>$endtime, - "statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE), - "statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5) - ]; - if($v['is_payment'] == 1){ - $company['verify_status'] = 0; - }else{ - $company['verify_status'] = 2; - } - $companyid = $StatementInfo->add($company); - $countdata['info_ids'][] =$companyid; - $countdata['del_lack_ids'] =array_merge($countdata['del_lack_ids'],$del_lack_ids); - $countdata['statement_money'] +=$v['statement_money']; - $countdata['pay_amount'] +=$v['pay_amount']; - $countdata['platform_amount'] +=$v['platform_amount']; - $countdata['fine'] +=$v['fine']; - $countdata['reward'] +=$v['reward']; - // } - } + $StatementDb = SM("user_statement","sub_"); + $res = [ + "statement_begin_time"=>$begintime, + "statement_end_time"=>$endtime, + "statement_money"=>0, + "pay_amount"=>0, + "op_time"=>time(), + "remark"=>'' + ]; + $statementInfo = []; + foreach($pc as $k=>$v){ + $res['pay_amount'] += $v['pay_amount']; + $res['statement_money'] += $v['sum_money']; + unset($v['pay_amount'],$v['sum_money']); + $statementInfo[] = $v; } + $res['statement_info'] = json_encode($statementInfo,JSON_UNESCAPED_UNICODE); + return $res; } /** * 保存信息汇总信息 @@ -1632,6 +1129,47 @@ class SubCompanyStatementSetController extends Controller { } return $senddata; } + /** + * 获取下游个人游戏分成比例,不计其他,只计算最后一条 + */ + protected function getPuGameRatio($company_id,$company_belong,$relation_game_ids,$pay_amount,$begin_time,$end_time){ + $flag = false; + $ratio = 0; + $turnover_ratio = ''; + $where = [ + "relation_game_id"=>$relation_game_ids, + "company_id"=>$company_id, + "_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})" + ]; + $dbres = M("CompanyGameRatio","tab_")->where($where)->order('begin_time desc')->find(); + !empty($dbres) && $flag = true; + if(!$flag){ + $where = [ + "relation_game_id"=>$relation_game_ids, + "company_belong"=>$company_belong, + "_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})" + ]; + $dbres = M("CompanyGameRatio","tab_")->where($where)->order('begin_time desc')->find(); + !empty($dbres) && $flag = true; + } + if(!$flag){ + $where = [ + "relation_game_id"=>$relation_game_ids, + "company_belong"=>$company_belong, + "_string"=>"begin_time <={$end_time} AND ( end_time = 0 OR end_time >= {$begin_time})" + ]; + $dbres = M("GameRatioMould","tab_")->where($where)->order('begin_time desc')->find(); + !empty($dbres) && $flag = true; + } + if($flag){ + $ratio = $dbres['ratio']; + $turnover_ratio = $dbres['turnover_ratio']; + } + $ratio = $this->getTurnoverRatio($pay_amount,$ratio,$turnover_ratio); + $sum_money = round($pay_amount * $ratio / 100,2); + return [$ratio,$sum_money]; + } + /** * 重算接口 From 0b4e9fa9a1cd02b775171ca597a28aee0487d2a9 Mon Sep 17 00:00:00 2001 From: chenzhi Date: Sat, 27 Feb 2021 17:17:34 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/AdminController.class.php | 2 +- .../QueryController.class - 副本.php | 327 ------------------ .../SubUserStatementController.class.php | 112 ++++++ .../Admin/Model/CmdTasksModel.class.php | 8 +- .../Admin/View/SubUserStatement/lists.html | 264 ++++++++++++++ .../View/SubUserStatement/viewPuPool.html | 149 ++++++++ 6 files changed, 531 insertions(+), 331 deletions(-) delete mode 100644 Application/Admin/Controller/QueryController.class - 副本.php create mode 100644 Application/Admin/Controller/SubUserStatementController.class.php create mode 100644 Application/Admin/View/SubUserStatement/lists.html create mode 100644 Application/Admin/View/SubUserStatement/viewPuPool.html diff --git a/Application/Admin/Controller/AdminController.class.php b/Application/Admin/Controller/AdminController.class.php index c74e8a4e6..e1fa9e103 100644 --- a/Application/Admin/Controller/AdminController.class.php +++ b/Application/Admin/Controller/AdminController.class.php @@ -48,7 +48,7 @@ class AdminController extends Controller { if ( false === $access ) { $this->error('403:禁止访问'); }elseif(null === $access ){ - $access_controller = ['Ajax', 'Finance', 'FinancePromote', 'PayChannel','FinanceCompare',"AggregateFinanceStatement"]; + $access_controller = ['Ajax', 'Finance', 'FinancePromote', 'PayChannel','FinanceCompare',"AggregateFinanceStatement","SubUserStatement"]; if(!in_array(CONTROLLER_NAME, $access_controller)){//ajax放行 //检测访问权限 $rule = strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME); diff --git a/Application/Admin/Controller/QueryController.class - 副本.php b/Application/Admin/Controller/QueryController.class - 副本.php deleted file mode 100644 index 01d19002a..000000000 --- a/Application/Admin/Controller/QueryController.class - 副本.php +++ /dev/null @@ -1,327 +0,0 @@ -assign('group',$group); - if(isset($_REQUEST['total_status'])){ - unset($_REQUEST['total_status']); - } - if ($group == 1) { - if($_REQUEST['unum']==1){ - $order='unum'; - $order_type=SORT_ASC; - }else if($_REQUEST['unum']==0){ - $order='unum'; - $order_type=SORT_DESC; - } - if($_REQUEST['spay_amount']==1){ - $order='spay_amount'; - $order_type=SORT_ASC; - }else if($_REQUEST['spay_amount']==0){ - $order='spay_amount'; - $order_type=SORT_DESC; - } - $model = array( - 'title' => '渠道结算', - 'template_list' =>'settlement', - 'order' => $order, - 'order_type'=>$order_type//0倒序 1 正序 - ); - $start=$_REQUEST['timestart']; - $end=$_REQUEST['timeend']; - if(I('group')!=''){ - if($start==''||$end==''&&$_REQUEST['promote_account']==''){ - $this->error('结算周期、所属渠道不能为空!','',1); - } - if($start==''||$end==''){ - $this->error('请选择结算周期!','',1); - } - if($_REQUEST['promote_account']==''){ - $this->error('请选择渠道!','',1); - } - } - if($start && $end){ - if((strtotime($end)+24*60*60-1)error('时间选择不正确!',U('Query/settlement'),''); - } - $umap['register_time']=array('BETWEEN',array(strtotime($start),strtotime($end)+24*60*60-1)); - if(isset($_REQUEST['game_name'])&&$_REQUEST['game_name']!=''){ - $umap['fgame_name']=$_REQUEST['game_name']; - $smap['tab_spend.game_name']=$_REQUEST['game_name']; - } - if(isset($_REQUEST['promote_account'])&&$_REQUEST['promote_account']!=''){ - $allid=get_subordinate_promote($_REQUEST['promote_account'],'parent_name'); - $allid[]=$_REQUEST['promote_account']; - $umap['tab_user.promote_account']=array('in',implode(',',$allid)); - $smap['tab_spend.promote_account']=array('in',implode(',',$allid)); - }else{ - $this->error('未选择渠道!','',1); - } - $umap['is_check']=1; - $smap['pay_time']=array('BETWEEN',array(strtotime($start),strtotime($end)+24*60*60-1)); - $smap['is_check']=1; - $map['umap']=$umap; - $map['smap']=$smap; - $user = A('Settlement','Event'); - $user->settlement($model,$p,$map); - }else{ - $this->assign('setdate',date("Y-m-d",strtotime("-1 day"))); - $this->display(); - } - } - if ($group == 2) { - if(isset($_REQUEST['timestart'])&&isset($_REQUEST['timeend'])){ - $map['create_time']=array('BETWEEN',array(strtotime($_REQUEST['timestart']),strtotime($_REQUEST['timeend'])+24*60*60-1)); - } - if(isset($_REQUEST['game_name'])){ - if($_REQUEST['game_name']=='全部'){ - unset($_REQUEST['game_name']); - }else{ - $map['game_name'] = $_REQUEST['game_name']; - } - } - if(isset($_REQUEST['promote_account'])){ - if($_REQUEST['promote_account']=='全部'){ - unset($_REQUEST['promote_account']); - }else{ - $map['promote_account'] = $_REQUEST['promote_account']; - } - } - if(!empty($_REQUEST['settlement_number'])){ - $map['settlement_number'] = $_REQUEST['settlement_number']; - } - $model = array( - 'm_name' => 'settlement', - 'order' => 'create_time desc ', - 'title' => '结算账单', - 'template_list' =>'settlement', - ); - $user = A('Bill','Event'); - $user->money_list($model,$p,$map); - } - } - public function cpsettlement($p=0) { - $group = I('group',1); - $this->assign('group',$group); - if(isset($_REQUEST['timestart'])&&$_REQUEST['timestart']!=''&&$_REQUEST['group']==1){ - $starttime=strtotime($_REQUEST['timestart'].'-01'); - if($starttime>=strtotime(date('Y-m-01'))){ - $this->error('时间选择不正确','',1);exit; - } - $endtime=strtotime($_REQUEST['timestart']."+1 month -1 day")+24*3600-1; - if(isset($_REQUEST['game_name'])&&$_REQUEST['game_name']!='全部'){ - $map['g.game_name']=$_REQUEST['game_name']; - } - if(isset($_REQUEST['selle_status'])){ - if($_REQUEST['selle_status']=="未结算"){ - $map['s.selle_status']=0; - }else if($_REQUEST['selle_status']=="已结算"){ - $map['s.selle_status']=1; - } - } - $map['s.pay_status']=1; - $map['pay_time']=array('BETWEEN',array($starttime,$endtime)); - $model = array( - 'm_name' => 'Spend as s', - 'order' => 's.id', - 'title' => '渠道结算', - 'group' => 'g.developers,g.id', - 'fields' =>'sum(s.pay_amount) as total,s.selle_ratio,s.id,g.developers,s.selle_status,g.id as gid,g.game_name,s.pay_status,s.pay_amount', - 'template_list' =>'cpsettlement', - ); - - $user = A('Spend','Event'); - $user->cpsettl_list($model,$p,$map); - }else if($_REQUEST['group']==2){ - if(isset($_REQUEST['timestart'])&&$_REQUEST['timestart']!=''){ - $starttime=strtotime($_REQUEST['timestart'].'-01'); - if($starttime>=strtotime(date('Y-m-01'))){ - $this->error('时间选择不正确','',1);exit; - } - $starttime=strtotime($_REQUEST['timestart'].'-01'); - $endtime=strtotime($_REQUEST['timestart']."+1 month -1 day")+24*3600-1; - $map['pay_time']=array('BETWEEN',array($starttime,$endtime)); - } - $map['s.pay_status']=1; - $map['s.selle_status']=1;//已结算 - $model = array( - 'm_name' => 'Spend as s', - 'order' => 's.id', - 'title' => '渠道结算', - 'group' => 'g.developers,g.id', - 'fields' =>'sum(s.pay_amount) as total, s.id,s.selle_ratio,g.developers,s.selle_status,s.selle_time,g.id as gid,g.game_name,s.pay_status,s.pay_amount', - 'template_list' =>'cpsettlement', - ); - - $user = A('Spend','Event'); - $user->cpsettl_list($model,$p,$map); - }else{ - $this->meta_title = '渠道结算列表'; - $this->display(); - } - } - public function generatesettlement(){ - //批量结算要加判断 - $data['game_id']=$_REQUEST['game_id']; - $data['game_name']=get_game_name($_REQUEST['game_id']); - $data['promote_id']=$_REQUEST['promote_id']; - $data['promote_account']=get_promote_name($_REQUEST['promote_id']); - $data['total_money']=$_REQUEST['spay_amount']; - $data['total_number']=$_REQUEST['unum']; - $data['starttime']=strtotime($_REQUEST['starttime']); - $data['endtime']=strtotime($_REQUEST['endtime'])+24*60*60-1; - $data['pattern']=$_REQUEST['cooperation']=='CPS'?0:1; - $data['ratio']=$_REQUEST['cps_ratio']; - $data['money']=$_REQUEST['cpa_price']; - $data['create_time']=time(); - $data['settlement_number']='JS-'.date('Ymd').date('His').sp_random_string(4); - if(get_settlement($data['starttime'],$data['promote_id'],$data['game_id'])){ - $this->error('该结算周期不可结算,请重新选择'); - } - if($data['pattern']){ - $data['sum_money']=$data['total_number']*$data['money']; - }else{ - $data['sum_money']=$data['total_money']*$data['ratio']/100; - } - if($data['game_id']==''||$data['promote_id']==''||$data['starttime']==''||$data['endtime']==''){ - $this->error('必要参数不存在'); - } - $map['fgame_id']=$data['game_id']; - // $map['is_check']=1; - $map['register_time']=array('BETWEEN',array($data['starttime'],$data['endtime'])); - $allid=get_subordinate_promote($data['promote_account'],'parent_name'); - $allid[]=$data['promote_account']; - $map['promote_id']=array('in',$data['promote_id']); - $u=M('User','tab_'); - $user=$u->where($map)->setField('settle_check',1); - unset($map['register_time']); - $map['pay_time']=array('BETWEEN',array($data['starttime'],$data['endtime'])); - $s=M('spend','tab_'); - $spend=$s->where($map)->setField('settle_check',1); - $result=M('settlement','tab_')->add($data); - if($result){ - $this->success('结算成功'); - }else{ - $this->error('结算失败'); - } - } - public function generatecpsettlement() {//cp结算 - $game_id = I('request.ids'); - if(empty($game_id)){ - $this->error('请选择要操作的数据'); - } - $starttime=strtotime($_REQUEST['timestart'].'-01'); - $endtime=strtotime($_REQUEST['timestart']."+1 month -1 day")+24*3600-1; - $map['s.pay_status']=1; - $map['s.selle_status']=0; - if(is_array($game_id)){ - $map['s.game_id']=array('in',$game_id); - }else{ - $map['s.game_id']=$game_id; - } - $map['pay_time']=array('BETWEEN',array($starttime,$endtime)); - $spe=M('spend as s','tab_'); - $smap= array('s.selle_time'=>$_REQUEST['timestart'],'s.selle_status'=>1); - $data=$spe - ->field('s.id,s.selle_status,s.selle_time') - ->join('tab_game as g on g.id=s.game_id','LEFT') - ->where($map) - ->setField($smap); - if($data){ - $this->success('结算成功'); - }else{ - $this->error('结算失败'); - } - - } - public function changeratio(){ - $gid = I('request.game_id'); - if(empty($gid)){ - $this->ajaxReturn(0,"请选择要操作的数据",0);exit; - } - $starttime=strtotime($_REQUEST['timestart'].'-01'); - $endtime=strtotime($_REQUEST['timestart']."+1 month -1 day")+24*3600-1; - $map['s.pay_status']=1; - $map['s.selle_status']=0; - $map['s.game_id']=$_REQUEST['game_id']; - $map['pay_time']=array('BETWEEN',array($starttime,$endtime)); - $spe=M('spend as s','tab_'); - $data=$spe - ->field('s.id,s.selle_status,s.selle_ratio') - ->join('tab_game as g on g.id=s.game_id','LEFT') - ->where($map) - ->setField('s.selle_ratio',$_POST['ratio']); - if($data){ - $this->ajaxReturn($data); - }else{ - $this->ajaxReturn(-1); - } - } - public function withdraw() { - - if(isset($_REQUEST['settlement_number'])){ - $map['settlement_number']=$_REQUEST['settlement_number']; - } - if(isset($_REQUEST['status'])){ - $map['status']=$_REQUEST['status']; - } - if(isset($_REQUEST['promote_account'])){ - if($_REQUEST['promote_account']=='全部'){ - unset($_REQUEST['promote_account']); - }else{ - $map['promote_account'] = $_REQUEST['promote_account']; - } - } - - - $model = array( - 'm_name' => 'withdraw', - 'order' => 'create_time desc ', - 'title' => '渠道提现', - 'template_list' =>'withdraw', - ); - - $user = A('Bill','Event'); - $user->money_list($model,$p,$map); - - } - - public function set_withdraw_status($model='withdraw') { - $withdraw=M('withdraw',"tab_"); - $seet=M('settlement',"tab_"); - $count=count($_REQUEST['ids']); - if($count>1){ - for ($i=0; $i <$count; $i++) { - $map['id']=$_REQUEST['ids'][$i]; - $dind=$withdraw->where($map)->find(); - $se_map['settlement_number']=$dind['settlement_number']; - $seet->where($se_map)->save(array("ti_status"=>$_REQUEST['status'])); - $withdraw->where($map)->save(array("end_time"=>time())); - } - }else{ - $map['id']=$_REQUEST['ids']; - $dind=$withdraw->where($map)->find(); - $se_map['settlement_number']=$dind['settlement_number']; - $seet->where($se_map)->save(array("ti_status"=>$_REQUEST['status'])); - $withdraw->where($map)->save(array("end_time"=>time())); - } - - parent::set_status($model); - } - - - protected function upPromote($promote_id){ - $model = D('Promote'); - $data['id'] = $promote_id; - $data['money'] = 0; - return $model->save($data); - } -} \ No newline at end of file diff --git a/Application/Admin/Controller/SubUserStatementController.class.php b/Application/Admin/Controller/SubUserStatementController.class.php new file mode 100644 index 000000000..5982d820b --- /dev/null +++ b/Application/Admin/Controller/SubUserStatementController.class.php @@ -0,0 +1,112 @@ +DBModel = M("UserStatement","sub_",SUBSITE_DB);//指定子库 + parent::_initialize(); + } + + public function lists() { + $params = I('get.'); + $page = $params['p'] ? intval($params['p']) : 1; + $row = $params['row'] ? intval($params['row']) : 10; + + //权限分配 + $map = [ + "_string"=>"1=1" + ]; + if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { + $time_start = strtotime($_REQUEST['time_start']); + $time_end = strtotime($_REQUEST['time_end'])+ 86399; + $map["_string"] = "(statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (statement_begin_time <= {$time_end} AND statement_end_time >= {$time_end})"; + } elseif (isset($_REQUEST['time_start'])) { + $time_start = strtotime($_REQUEST['time_start']); + $map["_string"] = "(statement_begin_time >= {$time_start} ) OR (statement_end_time >= {$time_start})"; + } elseif (isset($_REQUEST['time_end'])) { + $time_end = strtotime($_REQUEST['time_end'])+ 86399; + $map["_string"] = "(statement_begin_time <= {$time_end} ) OR (statement_end_time <= {$time_end})"; + } + + $data = $this->DBModel->where($map)->page($page,$row)->field("statement_info",true)->order("statement_begin_time desc")->select(); + foreach ($data as $k => &$v) { + $v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']); + $v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']); + $v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}"; + } + + $count = $this->DBModel->where($map)->count(); + + $params['p'] = $page; + $params['row'] = $row; + $page = set_pagination($count, $row, $params); + if ($page) { + $this->assign('_page', $page); + } + $this->assign('data',$data); + $this->display(); + } + + public function updateStatement() + { + if(!isset($_REQUEST['id'])){ + $this->error('参数错误'); + } + $id = $_REQUEST['id']; + $temp = $this->DBModel->where(['id'=>$id])->getField('statement_end_time'); + $temp = date('Y-m-d',$temp-0+1); + + $params = "php ".SUBSITE_INDEX." SubCompanyStatementSet/setFreeDateCount/begin/{$temp}/end/{$temp}/company/pu"; + $r = D("CmdTasks")->addTask("SubCompanyStatementSet",$params,true); + if($r){ + $this->DBModel->where(['id'=>$id])->delete(); + $this->ajaxReturn(["status"=>1,"info"=>"旧数据已删除且重算登记成功,请稍后刷新页面查看最新数据"]); + }else{ + $this->ajaxReturn(["status"=>0,"info"=>"重算登记错误"]); + } + } + + + public function viewStatement() + { + $is_export= false; + if (isset($_REQUEST['export']) && $_REQUEST['export']==1){ + $is_export = true; + } + + if(!isset($_REQUEST['id'])){ + $this->error('参数错误'); + } + $id = $_REQUEST['id']; + + $data = $this->DBModel->where(['id'=>$id])->getField("statement_info"); + $data = json_decode($data,true); + $line = 2; + foreach ($data as $k => &$v) { + $v['row'] = count($v['statement_info']); + if ($is_export) { + foreach ($v['statement_info'] as $key => &$val) { + $val['sum_money'] = "=ROUND(F{$line}*G{$line},2)"; + $line++; + } + } + } + if ($is_export) { + $title = $data[0]['statement_info'][0]['statement_begin_time']."-".$data[0]['statement_info'][0]['statement_end_time']."个人汇总单"; + $this->assign("title",$title); + } + $this->assign("data",$data); + $this->assign("is_export",$is_export); + $this->display("viewPuPool"); + } + +} diff --git a/Application/Admin/Model/CmdTasksModel.class.php b/Application/Admin/Model/CmdTasksModel.class.php index 13705325f..a968f0903 100644 --- a/Application/Admin/Model/CmdTasksModel.class.php +++ b/Application/Admin/Model/CmdTasksModel.class.php @@ -49,10 +49,12 @@ class CmdTasksModel extends Model{ } } //插入任务 - public function addTask($type,$params,$need_path=true) + public function addTask($type,$params,$repeat=false,$need_path=true) { - if(!$this->isCanAddTask($type)) return false; - + if(!$repeat){ + if(!$this->isCanAddTask($type)) return false; + } + if($need_path){ if(IS_WIN){ $p = explode(':',ROOTTTTT); diff --git a/Application/Admin/View/SubUserStatement/lists.html b/Application/Admin/View/SubUserStatement/lists.html new file mode 100644 index 000000000..c2f88c7b2 --- /dev/null +++ b/Application/Admin/View/SubUserStatement/lists.html @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + +
+ +
+
+ +  -  +
+ + +
+
+ +
+ 搜索 +
+ +
+
+ +
+
+ 导出 +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
结算时间结算金额操作
aOh! 暂时还没有内容!
{$data.valid}{$data.statement_money} + 查看 + 重算 +
+
+ +
+
+ + + + {$_page|default=''} +
+
+ + + + if(C('COLOR_STYLE')=='blue_color') echo ' + + '; + + + + + + + + + + diff --git a/Application/Admin/View/SubUserStatement/viewPuPool.html b/Application/Admin/View/SubUserStatement/viewPuPool.html new file mode 100644 index 000000000..a7e03e13c --- /dev/null +++ b/Application/Admin/View/SubUserStatement/viewPuPool.html @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
序号下游名称产品产品类型结算时间平台流水分成比例分成结算金额
aOh! 暂时还没有内容!
{$key-0+1}{$com.partner}{$st.game_name}{$st.game_type_name}{$st.statement_begin_time}-{$st.statement_end_time}{$st.pay_amount}{$st.ratio}%{$st.sum_money}
+
+
+ + +