优化个人结算

master
chenzhi 4 years ago
parent 7f01c3ff39
commit f70d8cb8a7

@ -75,8 +75,8 @@ class CompanyStatementSetController extends Controller {
// $this->promoteCompanyStatement(0,$stime);
// echo "∟----推广公司周结统计ok".PHP_EOL;
// $this->promoteUserPool(0,$stime);
// echo "∟----推广个人周结ok".PHP_EOL;
$this->promoteUserPool(0,$stime);
echo "∟----推广个人周结ok".PHP_EOL;
}
if($d == 1){
echo $nowdate.":".PHP_EOL;
@ -86,13 +86,13 @@ class CompanyStatementSetController extends Controller {
// $this->cpStatement(2,$stime);
// echo "∟----CP月结&补点统计ok".PHP_EOL;
$this->promoteCompanyStatement(1,$stime);
$this->promoteCompanyStatement(2,$stime);
echo "∟----推广公司月结&补点统计ok".PHP_EOL;
// $this->promoteCompanyStatement(1,$stime);
// $this->promoteCompanyStatement(2,$stime);
// echo "∟----推广公司月结&补点统计ok".PHP_EOL;
// $this->promoteUserPool(1,$stime);
// $this->promoteUserPool(2,$stime);
// echo "∟----推广个人月结&补点统计ok".PHP_EOL;
$this->promoteUserPool(1,$stime);
$this->promoteUserPool(2,$stime);
echo "∟----推广个人月结&补点统计ok".PHP_EOL;
}
}else{
echo $nowdate."非周一和月初,无需任何处理".PHP_EOL;
@ -509,7 +509,7 @@ class CompanyStatementSetController extends Controller {
$statement_begin_time = date("Y-m-d",$begintime);
$statement_end_time = date("Y-m-d",$endtime);
$RewardRecord = M("RewardRecord","tab_");
$RewardRecord = M("RewardDetail","tab_");
foreach($pcList as $k=>$v){
if(!isset($pc[$k])){continue;}//不存在的公司不结算
@ -597,7 +597,7 @@ class CompanyStatementSetController extends Controller {
if($type < 2){
//非补点计算奖罚
$rrmap = array(
"reward_time" => ['between', [$begintime,$endtime]],
"confirm_time" => ['between', [$begintime,$endtime]],
"company_type"=>2,
"company_id"=>$add_data['company_id'],
"settlement_type"=>2,
@ -767,13 +767,18 @@ class CompanyStatementSetController extends Controller {
if($type == 0){//周结
$this->doPromoteUserPool($user,$users,$type,$stime,$recount);
}else{
}else if($type == 1){
$users['withdraw_type'] = 1;
$user['withdraw_type'] = 1;
//月结&补点
$this->doPromoteUserPool($user,$users,1,$stime,$recount);
}else{
$users['withdraw_type'] = 1;
$user['withdraw_type'] = 1;
$this->doPromoteUserPool($user,$users,2,$stime,$recount);
}
$this->savePromotateUserPool($users);
$this->savePromotateUserPool($user);
}
@ -812,13 +817,28 @@ class CompanyStatementSetController extends Controller {
}
//获取pc公司
$pc_id = implode(",",array_flip(array_flip(array_keys($pcList))));
$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"=>2])
->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'];
}
@ -828,11 +848,18 @@ class CompanyStatementSetController extends Controller {
$StatementDb = M("CompanyStatement","tab_");
$statement_begin_time = date("Y-m-d",$begintime);
$statement_end_time = date("Y-m-d",$endtime);
$RewardRecord = M("RewardRecord","tab_");
// $RewardRecord = M("RewardRecord","tab_");
$LackStatement = M("company_lack_statement_info","tab_");
$StatementInfo = M("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);
if($v['is_payment'] == 1){
@ -846,6 +873,21 @@ class CompanyStatementSetController extends Controller {
$v['reward'] = 0;
$v['platform_amount'] = 0;
if(!isset($v['list'])){continue;}
//服务器费用
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'];
}
}
foreach($v['list'] as $ke=>$va){
$game =[];
$game['pay_amount'] =$va['pay_amount'];
@ -856,13 +898,14 @@ class CompanyStatementSetController extends Controller {
if($type == 1){
$tratio = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);
$tratio += $company_ratio;
}elseif($type == 0){
$tratio = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong);
}else{
//补点
$tratio1 = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);;
$tratio2 = getGamePromoteCompanyRadio($v['id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong);
$tratio = $tratio1-$tratio2;
$tratio = $tratio1-$tratio2+$company_ratio;
if($tratio <= 0){
continue;
}
@ -877,22 +920,20 @@ class CompanyStatementSetController extends Controller {
//判断是否是个人
if($type < 2){
//非补点
$rrmap = array(
"reward_time" => ['between', [$begintime,$endtime]],
"company_type"=>2,
"company_id"=>$k,
"relation_game_id"=>$va['relation_game_id']
);
$rrfres =$RewardRecord->field("IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count,IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count")->where($rrmap)->find();
$v['fine'] += $rrfres['fine_count'];
$v['reward'] += $rrfres['reward_count'];
if($RewardRecordRes){
$rrfres = $RewardRecordRes[$va['relation_game_id']];
}else{
$rrfres = [
'reward_count'=>0,
'fine_count'=>0,
];
}
$game['reward'] = $rrfres['reward_count'];
$game['fine'] = $rrfres['fine_count'];
$game['sum_money']=round($va['pay_amount']*$tratio/100,2)+$game['reward']-$game['fine'];
}else{
$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-税费费率)
}
$v['statement_money'] += $game['sum_money'];
@ -1052,6 +1093,11 @@ 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'];
}
/**
* 获取公司比例加成
* @param [type] $paymount 支付金额
* @param [type] $turnover_ratio 梯度
*/
protected function getCompanyRatio($paymount,$turnover_ratio)
{
$ratio = 0;
@ -1067,6 +1113,42 @@ class CompanyStatementSetController extends Controller {
}
}
return $ratio;
}
/**
* 获取公司比例加成
* @param [type] $paymount 支付金额
* @param [type] $turnover_ratio 梯度
*/
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_count,
IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine_count,
r.relation_game_id
")
->where($rrmap)
->join("tab_reward_record as r on d.record_id = r.id")
->group("record_id,company_id")
->select();
if(empty($rfres)){
return false;
}else{
$s = [];
foreach($rfres as $k=>$v){
$s[$v['relation_game_id']] = $v;
}
return $s;
}
}
/**

Loading…
Cancel
Save