@ -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 =[];
@ -744,7 +718,8 @@ class CompanyStatementSetController extends Controller {
$StatementInfo = M("company_statement_info","tab_");
$StatementInfo = M("company_statement_info","tab_");
$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,34 +857,39 @@ class CompanyStatementSetController extends Controller {
}
}
if($v['statement_money'] < 300 ) {
if($v['statement_money'] < 300 ) {
//存未满
//存未满
$lask_id = $LackStatement->add($lackcompany);
if($lackcompany['pay_amount'] > 0){
$countdata['create_lack_ids'][] =$lask_id;
$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{
}else{
//存成功
if($v['pay_amount'] > 0){
$company =[
//存成功
"pool_id"=>0,
$company =[
"company_id"=>$k,
"pool_id"=>0,
"company_type"=>2,
"company_id"=>$k,
"company_name"=>$v['partner'],
"company_type"=>2,
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
"company_name"=>$v['partner'],
"statement_money"=>$v['statement_money'],
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
"pay_amount"=>$v['pay_amount'],
"statement_money"=>$v['statement_money'],
"platform_amount"=>$v['platform_amount'],
"pay_amount"=>$v['pay_amount'],
"fine"=>$v['fine'],
"platform_amount"=>$v['platform_amount'],
"reward"=>$v['reward'],
"fine"=>$v['fine'],
"statement_begin_time"=>$begintime,
"reward"=>$v['reward'],
"statement_end_time"=>$endtime,
"statement_begin_time"=>$begintime,
"statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE)
"statement_end_time"=>$endtime,
];
"statement_info"=>json_encode($v['statement_info'],JSON_UNESCAPED_UNICODE)
$companyid = $StatementInfo->add($company);
];
$countdata['info_ids'][] =$companyid;
$companyid = $StatementInfo->add($company);
$countdata['del_lack_ids'] =array_merge($countdata['del_lack_ids'],$del_lack_ids);
$countdata['info_ids'][] =$companyid;
$countdata['statement_money'] +=$v['statement_money'];
$countdata['del_lack_ids'] =array_merge($countdata['del_lack_ids'],$del_lack_ids);
$countdata['pay_amount'] +=$v['pay_amount'];
$countdata['statement_money'] +=$v['statement_money'];
$countdata['platform_amount'] +=$v['platform_amount'];
$countdata['pay_amount'] +=$v['pay_amount'];
$countdata['fine'] +=$v['fine'];
$countdata['platform_amount'] +=$v['platform_amount'];
$countdata['reward'] +=$v['reward'];
$countdata['fine'] +=$v['fine'];
$countdata['reward'] +=$v['reward'];
}
}
}
}
}
$this->savePromotateUserPool($users);
$this->savePromotateUserPool($users);
@ -926,8 +906,13 @@ 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);
//回写
//回写
$save["pool_id"]=$id;
if(!empty($info)){
M("company_statement_info","tab_")->where("id in ({$info})")->save($save);
$save["pool_id"]=$id;
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]);
}
}
}
/**
/**