From 4024e45c64b3cd0cbb77fee08b1e515bc4e0d6eb Mon Sep 17 00:00:00 2001 From: chenzhi Date: Wed, 24 Feb 2021 18:36:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=90=E7=AB=99=E4=B8=8A?= =?UTF-8?q?=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); } }