优化下游公司结算

master
chenzhi 4 years ago
parent 8e77f3ed4d
commit d946a4c91c

@ -470,11 +470,25 @@ class CompanyStatementSetController extends Controller {
return ;
}
//获取pc公司
$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,company_belong,company_type,ali_user,ali_account")
$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(["id"=>['in',$pc_id],"company_type"=>1])
->select();
$pc =[];
$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;
}
@ -486,8 +500,10 @@ class CompanyStatementSetController extends Controller {
$our[$v['id']]=$v;
}
unset($tmpp);
unset($js_id);
$this->getPromoteCompanySpend($pcList,array_unique(array_keys($pcList)),$begintime,$endtime);
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 = M("CompanyStatement","tab_");
@ -498,8 +514,13 @@ class CompanyStatementSetController extends Controller {
foreach($pcList as $k=>$v){
if(!isset($pc[$k])){continue;}//不存在的公司不结算
if(!isset($pc[$k])){continue;}//不存在的公司不结算
if($pc[$k]['has_ratio'] == 1){
$company_ratio = $this->getCompanyRatio($v['paymount'],$pc[$k]['turnover_ratio']);
}else{
$company_ratio = 0;
}
$add_data=[];
//1.获取甲乙方信息
if($v['first_company_type'] > 0){
@ -533,7 +554,7 @@ class CompanyStatementSetController extends Controller {
$add_data['statement_info'] =[];
//获取渠道及发票税率
$fax_ratio = $pc[$add_data['company_id']]['fax_ratio'] ?? 0;
$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'];
@ -546,14 +567,15 @@ class CompanyStatementSetController extends Controller {
//获取比例
$game['relation_game_id']=$va['relation_game_id'];
if($type == 1){
$tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);
$tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);
$tratio += $company_ratio;
}elseif($type == 0){
$tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong);
}else{
//补点
$tratio1 = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);;
$tratio2 = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong);
$tratio = $tratio1-$tratio2;
$tratio = $tratio1-$tratio2+$company_ratio;
if($tratio <= 0){ continue;}
}
@ -564,7 +586,7 @@ class CompanyStatementSetController extends Controller {
}
$add_data['pay_amount'] += $va['pay_amount'];
$game['sum_money']=round($va['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*1-渠道费)*分成比例*(1-税费费率)
$game['sum_money']=round($va['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率)
$add_data['statement_money'] += $game['sum_money'];
$game['fax_ratio']=$fax_ratio;
@ -580,12 +602,13 @@ class CompanyStatementSetController extends Controller {
$rrmap = array(
"reward_time" => ['between', [$begintime,$endtime]],
"company_type"=>2,
"company_id"=>$add_data['company_id']
"company_id"=>$add_data['company_id'],
"settlement_type"=>2,
);
$rfres = M("RewardRecord","tab_")
$rfres = M("RewardDetail","tab_")
->field("
IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count,
IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count
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){
@ -613,7 +636,22 @@ class CompanyStatementSetController extends Controller {
);
$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;;
}
}
$add_data['statement_info'] = json_encode($add_data['statement_info'],JSON_UNESCAPED_UNICODE);
@ -667,7 +705,6 @@ class CompanyStatementSetController extends Controller {
"s.pay_time"=>['between', [$begintime,$endtime]],
];
for ($i=0; $i <count($idarr); $i++) {
$company_id = $idarr[$i];
$pres = $Promote->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']];
@ -677,6 +714,11 @@ class CompanyStatementSetController extends Controller {
->select();
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'];
@ -687,7 +729,10 @@ class CompanyStatementSetController extends Controller {
}
}
foreach($res as $k=>$v){
$pcList[$k]["pay_amount"] = $v['pay_amount'];
unset($v['pay_amount']);
$pcList[$k]['list'] = $v;
}
}
public function promoteUserPool($type,$stime,$recount = false){
@ -1007,7 +1052,23 @@ class CompanyStatementSetController extends Controller {
*/
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'];
}
}
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;
}
/**
* 重算接口

Loading…
Cancel
Save