下游个人聚合

master
chenzhi 5 years ago
parent 7d3e90514f
commit 0f632f386b

@ -417,7 +417,7 @@ class CompanyStatementController extends ThinkController
"op_time"=>time(), "op_time"=>time(),
"company_list"=>[] "company_list"=>[]
]; ];
$datas = ["ups","up","downs","down","users","user"]; $datas = ["ups","up","downs","down"];
//初始化数据 //初始化数据
foreach($datas as $k=>$v){ foreach($datas as $k=>$v){
if($v =="ups"){ if($v =="ups"){
@ -437,15 +437,6 @@ class CompanyStatementController extends ThinkController
$basedata['company_type']=1; $basedata['company_type']=1;
$basedata['is_payment']=2; $basedata['is_payment']=2;
} }
if($v =="users"){
$basedata['company_type']=2;
$basedata['is_payment']=1;
}
if($v =="user"){
$basedata['company_type']=2;
$basedata['is_payment']=2;
}
$datas[$v]=$basedata; $datas[$v]=$basedata;
unset($datas[$k]); unset($datas[$k]);
} }
@ -460,15 +451,7 @@ class CompanyStatementController extends ThinkController
$this->setDf($datas['up'],$v); $this->setDf($datas['up'],$v);
} }
}else{ }else{
//下游
if($v['company_type'] == 2){
//个人
if($v['is_payment'] == 1){
$this->setDf($datas['users'],$v);
}else{
$this->setDf($datas['user'],$v);
}
}else{
if($v['is_payment'] == 1){ if($v['is_payment'] == 1){
$this->setDf($datas['downs'],$v); $this->setDf($datas['downs'],$v);
}else{ }else{
@ -476,7 +459,6 @@ class CompanyStatementController extends ThinkController
} }
} }
} }
}
$Pool = M("company_statement_pool","tab_"); $Pool = M("company_statement_pool","tab_");
$Statemen = M("company_statement","tab_"); $Statemen = M("company_statement","tab_");
foreach ($datas as $k => $v) { foreach ($datas as $k => $v) {
@ -519,6 +501,7 @@ class CompanyStatementController extends ThinkController
protected function addStatementInfo($pool_id,$va,$k,$v){ protected function addStatementInfo($pool_id,$va,$k,$v){
$StatementInfo = M("company_statement_info","tab_"); $StatementInfo = M("company_statement_info","tab_");
$company_info = $va['company_info']; $company_info = $va['company_info'];
//统一比例字段
if($k == "up" || $k=="ups"){ if($k == "up" || $k=="ups"){
foreach ($va['statement_info'] as $key => &$value) { foreach ($va['statement_info'] as $key => &$value) {
if($company_info['pay_type'] == 2){ if($company_info['pay_type'] == 2){

@ -65,10 +65,13 @@ class CompanyStatementSetController extends Controller {
echo "--周结begin".PHP_EOL; echo "--周结begin".PHP_EOL;
$this->cpStatement(0,$stime); $this->cpStatement(0,$stime);
echo "----CP周结统计ok".PHP_EOL; echo "----CP周结统计ok".PHP_EOL;
$this->promoteCompanyStatement(0,$stime); $this->promoteCompanyStatement(0,$stime);
echo "----推广公司周结统计ok".PHP_EOL; echo "∟----推广公司周结统计ok".PHP_EOL;
$this->promoteUserPool(0,$stime);
echo "∟----推广个人月结&补点统计ok".PHP_EOL;
} }
if($d == 1){ if($d == 1){
echo $nowdate.":".PHP_EOL; echo $nowdate.":".PHP_EOL;
@ -76,11 +79,15 @@ class CompanyStatementSetController extends Controller {
$this->cpStatement(1,$stime); $this->cpStatement(1,$stime);
$this->cpStatement(2,$stime); $this->cpStatement(2,$stime);
echo "----CP月结&补点统计ok".PHP_EOL; echo "----CP月结&补点统计ok".PHP_EOL;
$this->promoteCompanyStatement(1,$stime); $this->promoteCompanyStatement(1,$stime);
$this->promoteCompanyStatement(2,$stime); $this->promoteCompanyStatement(2,$stime);
echo "----推广公司月结&补点统计ok".PHP_EOL; echo "∟----推广公司月结&补点统计ok".PHP_EOL;
$this->promoteUserPool(1,$stime);
$this->promoteUserPool(2,$stime);
echo "∟----推广个人月结&补点统计ok".PHP_EOL;
} }
}else{ }else{
echo $nowdate."非周一和月初,无需任何处理".PHP_EOL; echo $nowdate."非周一和月初,无需任何处理".PHP_EOL;
@ -438,7 +445,9 @@ class CompanyStatementSetController extends Controller {
return ; return ;
} }
//获取pc公司 //获取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")->where(["id"=>['in',$pc_id]])->select(); $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")
->where(["id"=>['in',$pc_id],"company_type"=>1])
->select();
$pc =[]; $pc =[];
foreach ($tmpp as $v) { foreach ($tmpp as $v) {
$pc[$v['id']]=$v; $pc[$v['id']]=$v;
@ -461,19 +470,15 @@ class CompanyStatementSetController extends Controller {
$statement_end_time = date("Y-m-d",$endtime); $statement_end_time = date("Y-m-d",$endtime);
$RewardRecord = M("RewardRecord","tab_"); $RewardRecord = M("RewardRecord","tab_");
foreach($pcList as $k=>$v){ foreach($pcList as $k=>$v){
if(!isset($pc[$k])){continue;}//不存在的公司不结算
$add_data=[]; $add_data=[];
$is_pu = ($add_data['company_type'] == 1 ? false :true);//是否是个人
//1.获取甲乙方信息 //1.获取甲乙方信息
if($v['first_company_type'] == 1){ if($v['first_company_type'] == 1){
//甲方合作 //甲方合作
$pc[$v['first_company_id']]['invoice_type'] = $v['invoice_type']; $pc[$v['first_company_id']]['invoice_type'] = $v['invoice_type'];
$pc[$v['first_company_id']]['invoice_content'] = $v['invoice_content']; $pc[$v['first_company_id']]['invoice_content'] = $v['invoice_content'];
if($is_pu){
//个人获取外信息
$pc[$v['first_company_id']] = $this->getCompanyOtherInfo($pc[$v['first_company_id']],$v['first_company_id']);
}
$add_data['first_party_info'] = json_encode($pc[$v['first_company_id']],JSON_UNESCAPED_UNICODE); $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['second_party_info'] = json_encode($our[$v['second_company_id']],JSON_UNESCAPED_UNICODE);
$add_data['company_id'] = $v['first_company_id']; $add_data['company_id'] = $v['first_company_id'];
@ -483,12 +488,6 @@ class CompanyStatementSetController extends Controller {
//乙方合作 //乙方合作
$pc[$v['second_company_id']]['invoice_type'] = $v['invoice_type']; $pc[$v['second_company_id']]['invoice_type'] = $v['invoice_type'];
$pc[$v['second_company_id']]['invoice_content'] = $v['invoice_content']; $pc[$v['second_company_id']]['invoice_content'] = $v['invoice_content'];
if($is_pu){
//个人获取外信息
$pc[$v['second_company_id']] = $this->getCompanyOtherInfo($pc[$v['second_company_id']],$v['second_company_id']);
}
$add_data['first_party_info'] = json_encode($our[$v['first_company_id']],JSON_UNESCAPED_UNICODE); $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['second_party_info'] = json_encode($pc[$v['second_company_id']],JSON_UNESCAPED_UNICODE);
$add_data['company_id'] = $v['second_company_id']; $add_data['company_id'] = $v['second_company_id'];
@ -519,12 +518,6 @@ class CompanyStatementSetController extends Controller {
$game['game_name'] =$va['game_name']; $game['game_name'] =$va['game_name'];
//获取比例 //获取比例
$game['relation_game_id']=$va['relation_game_id']; $game['relation_game_id']=$va['relation_game_id'];
if($is_pu){
//个人获取外信息
$game['game_type_name'] = $this->getGameTypeName($va['relation_game_id']);
}
if($type == 1){ 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);
}elseif($type == 0){ }elseif($type == 0){
@ -542,26 +535,8 @@ class CompanyStatementSetController extends Controller {
$game['ratio']=$tratio; $game['ratio']=$tratio;
} }
$add_data['pay_amount'] += $va['pay_amount']; $add_data['pay_amount'] += $va['pay_amount'];
//判断是否是个人
if($type < 2 && $is_pu){
//非补点及是个人
$rrmap = array(
"reward_time" => ['between', [$begintime,$endtime]],
"company_type"=>2,
"company_id"=>$add_data['company_id'],
"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();
$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-渠道费)*分成比例*(1-税费费率)
}
$add_data['statement_money'] += $game['sum_money']; $add_data['statement_money'] += $game['sum_money'];
$game['fax_ratio']=$fax_ratio; $game['fax_ratio']=$fax_ratio;
@ -573,8 +548,8 @@ class CompanyStatementSetController extends Controller {
} }
$add_data['platform_amount'] = $add_data['pay_amount']; $add_data['platform_amount'] = $add_data['pay_amount'];
if($type < 2 && !$is_pu){ if($type < 2){
//非补点及不是个人 //非补点计算奖罚
$rrmap = array( $rrmap = array(
"reward_time" => ['between', [$begintime,$endtime]], "reward_time" => ['between', [$begintime,$endtime]],
"company_type"=>2, "company_type"=>2,
@ -723,9 +698,8 @@ class CompanyStatementSetController extends Controller {
//获取pc公司 //获取pc公司
$pc_id = implode(",",array_flip(array_flip(array_keys($pcList)))); $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,company_belong,company_type,ali_user,ali_account")
->where(["id"=>['in',$pc_id]]) ->where(["id"=>['in',$pc_id],"company_type"=>2])
->select(); ->select();
//,"company_type"=>2
if(count($tmpp)<1){return;} if(count($tmpp)<1){return;}
$pc =[]; $pc =[];
@ -745,6 +719,7 @@ class CompanyStatementSetController extends Controller {
$basedata = [ $basedata = [
"pay_amount"=>0, "pay_amount"=>0,
"statement_money"=>0, "statement_money"=>0,
"lack_statement_money"=>0,
"platform_amount"=>0, "platform_amount"=>0,
"create_lack_ids"=>[], "create_lack_ids"=>[],
"del_lack_ids"=>[], "del_lack_ids"=>[],
@ -861,7 +836,7 @@ class CompanyStatementSetController extends Controller {
]; ];
} }
//聚合未结算数据 //聚合未结算数据
$lsres = $LackStatement->where("company_id='{$k}'")->select(); $lsres = $LackStatement->where("company_id='{$k}' and is_pool = 0")->select();
$del_lack_ids = []; $del_lack_ids = [];
if(count($lsres) > 0){ if(count($lsres) > 0){
@ -882,9 +857,14 @@ class CompanyStatementSetController extends Controller {
} }
if($v['statement_money'] < 300){ if($v['statement_money'] < 300){
//存未满 //存未满
if($lackcompany['pay_amount'] > 0){
$lask_id = $LackStatement->add($lackcompany); $lask_id = $LackStatement->add($lackcompany);
$countdata['create_lack_ids'][] =$lask_id; $countdata['create_lack_ids'][] =$lask_id;
$countdata['lack_statement_money'] +=$lackcompany['statement_money'];
$countdata['lack_platform_amount'] +=$lackcompany['platform_amount'];
}
}else{ }else{
if($v['pay_amount'] > 0){
//存成功 //存成功
$company =[ $company =[
"pool_id"=>0, "pool_id"=>0,
@ -909,7 +889,7 @@ class CompanyStatementSetController extends Controller {
$countdata['platform_amount'] +=$v['platform_amount']; $countdata['platform_amount'] +=$v['platform_amount'];
$countdata['fine'] +=$v['fine']; $countdata['fine'] +=$v['fine'];
$countdata['reward'] +=$v['reward']; $countdata['reward'] +=$v['reward'];
}
} }
} }
$this->savePromotateUserPool($users); $this->savePromotateUserPool($users);
@ -926,9 +906,14 @@ class CompanyStatementSetController extends Controller {
unset($data['info_ids']); unset($data['info_ids']);
$id = M("company_statement_pool","tab_")->add($data); $id = M("company_statement_pool","tab_")->add($data);
//回写 //回写
if(!empty($info)){
$save["pool_id"]=$id; $save["pool_id"]=$id;
M("company_statement_info","tab_")->where("id in ({$info})")->save($save); M("company_statement_info","tab_")->where("id in ({$info})")->save($save);
} }
if(!empty($data['del_lack_ids'])){
M("company_lack_statement_info","tab_")->where("id in ({$data['del_lack_ids']})")->save(["is_pool"=>1]);
}
}
/** /**
* 获取公司额为信息 * 获取公司额为信息

@ -149,6 +149,7 @@
<th>是否打款</th> <th>是否打款</th>
<th>结算金额</th> <th>结算金额</th>
<th>结算流水</th> <th>结算流水</th>
<th>不结算金额</th>
<th>创建记录</th> <th>创建记录</th>
<th>审批状态</th> <th>审批状态</th>
<th>打款状态</th> <th>打款状态</th>
@ -175,6 +176,7 @@
<td>{$data.statement_money}</td> <td>{$data.statement_money}</td>
<td>{$data.platform_amount}</td> <td>{$data.platform_amount}</td>
<td>{$data.lack_statement_money}</td>
<td>{$data.create}</td> <td>{$data.create}</td>
<td> <td>
<if condition="$data.verify_status eq -1 "> <if condition="$data.verify_status eq -1 ">

@ -1902,8 +1902,10 @@ CREATE TABLE `tab_company_statement_pool` (
`statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间', `statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间',
`statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间', `statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间',
`statement_money` decimal(10,2) DEFAULT '0.00' COMMENT '对账金额', `statement_money` decimal(10,2) DEFAULT '0.00' COMMENT '对账金额',
`lack_statement_money` decimal(10,2) DEFAULT '0.00' COMMENT '不结算金额',
`pay_amount` decimal(10,2) DEFAULT '0.00' COMMENT '总计', `pay_amount` decimal(10,2) DEFAULT '0.00' COMMENT '总计',
`platform_amount` decimal(10,2) DEFAULT '0.00' COMMENT '平台流水金额', `platform_amount` decimal(10,2) DEFAULT '0.00' COMMENT '平台流水金额',
`lack_platform_amount` decimal(10,2) DEFAULT '0.00' COMMENT '不结算平台流水金额',
`fine` decimal(10,2) DEFAULT '0.00' COMMENT '罚款', `fine` decimal(10,2) DEFAULT '0.00' COMMENT '罚款',
`reward` decimal(10,2) DEFAULT '0.00' COMMENT '奖励', `reward` decimal(10,2) DEFAULT '0.00' COMMENT '奖励',
@ -1973,6 +1975,7 @@ CREATE TABLE `tab_company_lack_statement_info` (
`statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间', `statement_begin_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账开始时间',
`statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间', `statement_end_time` int(11) NOT NULL DEFAULT '0' COMMENT '对账截止时间',
`statement_info` text NOT NULL DEFAULT '' COMMENT '订单相关信息json', `statement_info` text NOT NULL DEFAULT '' COMMENT '订单相关信息json',
`is_pool` tinyint(3) NOT NULL DEFAULT '0' COMMENT '是否被汇总:0否/1是',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `company_tid` (`company_id`,`company_type`) USING BTREE, KEY `company_tid` (`company_id`,`company_type`) USING BTREE,
KEY `statement_begin_time` (`statement_begin_time`) USING BTREE, KEY `statement_begin_time` (`statement_begin_time`) USING BTREE,

Loading…
Cancel
Save