@ -785,13 +785,85 @@ class CompanyStatementSetController extends Controller {
$res[$company_id][$v['relation_game_id']]= $v;
}
}
}
}
foreach($res as $k=>$v){
$pcList[$k]["pay_amount"] = $v['pay_amount'];
unset($v['pay_amount']);
$pcList[$k]['list'] = $v;
}
}
//获取推广公司推广金额
protected function getPuPromoteSpend(& $pcList,$idarr,$begintime,$endtime){
$res = [];
//获取推广员
if(count($idarr) == 0){return $res;}
$Promote = M("Promote","tab_");
$Spend = M("Spend","tab_");
$spenMap = [
"s.pay_status"=>1,
"s.payed_time"=>['between', [$begintime,$endtime]],
];
for ($i=0; $i < count ( $ idarr ) ; $ i + + ) {
$company_id = $idarr[$i];
$pres = $Promote->field("id,account")->where("company_id = '{$company_id}'")->select();
if(empty($pres)){continue;}
$spenMap['s.promote_id']=["in",array_column($pres,"id")];
$promote_a = [];
foreach($pres as $key=>$value){
$promote_a[$value['id']] = $value['account'];
}
unset($pres);
//获取支付记录
$list = $Spend
->alias('s')
->field("sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',s.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) p_id")
->where($spenMap)
->group('p_id,game_id')
->join("tab_promote promote ON s.promote_id = promote.id","left")
->join("left join tab_game g on s.game_id = g.id")
->select();
if(empty($list)){continue;}
$game = [];
foreach($list as $k=>$v){
if(isset($game[$v['relation_game_id']])){
$game[$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
$game[$v['relation_game_id']]['pay_amount'] = $v['pay_amount'];
}
}
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'];
}
$p_account = $promote_a[$v['p_id']];
if(isset($res[$company_id][$p_account][$v['relation_game_id']])){
//
$res[$company_id][$p_account][$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
unset($v['game_id']);
$res[$company_id][$p_account][$v['relation_game_id']]= $v;
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount'];
$res[$company_id][$p_account][$v['relation_game_id']]['game_type_name'] = $this->getGameTypeName($v['relation_game_id']);
}
}
}
foreach($res as $k=>$v){
$pcList[$k]["pay_amount"] = $v['pay_amount'];
unset($v['pay_amount']);
foreach($v as $ke=>$va){
$tmp = [
"account"=>$ke,
'game_list'=>$va
];
$pcList[$k]['list'][] = $tmp;
}
}
}
public function promoteUserPool($type,$stime,$recount = false){
$t = $this->setBeginAndEndTime($type,$stime);
@ -908,7 +980,9 @@ class CompanyStatementSetController extends Controller {
$pc[$v['id']]['is_payment']=$pcList[$v['id']]['is_payment'];
}
unset($tmpp);
$this->getPromoteCompanySpend($pc,array_unique(array_keys($pc)),$begintime,$endtime);
// $this->getPromoteCompanySpend($pc,array_unique(array_keys($pc)),$begintime,$endtime);
$this->getPuPromoteSpend($pc,array_unique(array_keys($pc)),$begintime,$endtime);
$StatementDb = M("CompanyStatement","tab_");
$statement_begin_time = date("Y.m.d",$begintime);
@ -930,8 +1004,15 @@ class CompanyStatementSetController extends Controller {
$countdata = &$user;
$v['statement_money'] = 0;
$v['pay_amount'] = 0;
$v['fine'] = 0;
$v['reward'] = 0;
if($type < 2 & & $ RewardRecordRes ) {
$v['fine'] = $RewardRecordRes['fine'];
$v['reward'] = $RewardRecordRes['reward'];
$v['statement_money'] -= $v['fine'];
$v['statement_money'] += $v['reward'];
}else{
$v['fine'] = 0;
$v['reward'] = 0;
}
$v['platform_amount'] = 0;
if(!isset($v['list'])){continue;}
$company_belong = $pc[$v['id']]['company_belong'];
@ -949,59 +1030,43 @@ class CompanyStatementSetController extends Controller {
$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'];
$game['game_name'] =$va['game_name'];
//获取比例
$game['relation_game_id']=$va['relation_game_id'];
$game['game_type_name'] = $this->getGameTypeName($va['relation_game_id']);
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+$company_ratio;
if($tratio < = 0){
continue;
$templist = $va['game_list'];
$va['game_list'] = [];
foreach($templist as $p_id => $p_info){
// dd($p_info);
if($type == 1){
$tratio = getGamePromoteCompanyRadio($v['id'],$p_info['relation_game_id'],$endtime,$p_info['all_pay_amount'],true,$company_belong);
$tratio += $company_ratio;
}elseif($type == 0){
$tratio = getGamePromoteCompanyRadio($v['id'],$p_info['relation_game_id'],$endtime,$p_info['all_pay_amount'],false,$company_belong);
}else{
//补点
$tratio1 = getGamePromoteCompanyRadio($v['id'],$p_info['relation_game_id'],$endtime,$p_info['all_pay_amount'],true,$company_belong);;
$tratio2 = getGamePromoteCompanyRadio($v['id'],$p_info['relation_game_id'],$endtime,$p_info['all_pay_amount'],false,$company_belong);
$tratio = $tratio1-$tratio2+$company_ratio;
if($tratio < = 0){
continue;
}
}
}
if($type == 2){
$game['increment_ratio']=$tratio;
}else{
$game['ratio']=$tratio;
}
$v['pay_amount'] += $va['pay_amount'];
$v['platform_amount'] += $va['pay_amount'];
//判断是否是个人
if($type < 2 ) {
//非补点
if($RewardRecordRes){
$rrfres = $RewardRecordRes[$va['relation_game_id']];
if($type == 2){
$p_info['increment_ratio']=$tratio;
}else{
$rrfres = [
'reward_count'=>0,
'fine_count'=>0,
];
$p_info['ratio']=$tratio;
}
$game['reward'] = $rrfres['reward_count'];
$game['fine'] = $rrfres['fine_count'];
$v['platform_amount'] += $p_info['pay_amount'];
$p_info['sum_money']=round($p_info['pay_amount']*$tratio/100,2); //个人等于 结算金额*比例
$v['pay_amount'] += $p_info['sum_money'];
$v['statement_money'] += $p_info['sum_money'];
$p_info['fax_ratio']=$fax_ratio;
$p_info['statement_begin_time']=$statement_begin_time;
$p_info['statement_end_time']=$statement_end_time;
$p_info['statement_type']=0;
$va['game_list'][] = $p_info;
}
$game['sum_money']=round($va['pay_amount']*$tratio/100,2)+$game['reward']-$game['fine']; //个人等于 结算金额*比例-罚款+奖励
$v['statement_money'] += $game['sum_money'];
$game['fax_ratio']=$fax_ratio;
$game['statement_begin_time']=$statement_begin_time;
$game['statement_end_time']=$statement_end_time;
$game['statement_type']=0;
$v['statement_info'][] = $game;
$v['statement_info'][] = $va;
}
$company_info = [
'account'=>$v['account'],
@ -1014,7 +1079,7 @@ class CompanyStatementSetController extends Controller {
"ali_user"=>$v['ali_user'],
"ali_account"=>$v['ali_account']
];
if($v['pay _amount'] < 300 ) {
if($v['platform _amount'] < 300 ) {
$lackcompany =[
"company_id"=>$k,
"company_type"=>2,
@ -1048,10 +1113,22 @@ class CompanyStatementSetController extends Controller {
$v['fine'] += $val['fine'];
$v['reward'] += $val['reward'];
$v['platform_amount'] += $val['platform_amount'];
$v['statement_info'] = array_merge($v['statement_info'],json_decode($val['statement_info'],true));
$last_names = array_column($v['statement_info'],'game_name');
array_multisort($last_names,SORT_DESC,SORT_STRING,$v['statement_info']);
$t_statement_info = json_decode($val['statement_info'],true);
$statement_info = [];
foreach($t_statement_info as $p=>$info){
$statement_info[$info['account']] = $info['game_list'];
}
foreach($v['statement_info'] as $p=>& $info){
if(isset($statement_info[$info['account']])){
$info['game_list'] = array_merge($statement_info[$info['account']],$info['game_list']);
unset($statement_info[$info['account']]);
}
}
if(!empty($statement_info)){
foreach($statement_info as $p=>$info){
$v['statement_info'][] = ["account"=>$p,"game_list"=>$info];
}
}
}
}
@ -1144,7 +1221,7 @@ class CompanyStatementSetController extends Controller {
{
$pl = M("promote_company","tab_")
->alias('pc')
->field("p.account,p.company_relation,IFNULL(s.nickname,'admin ') nickname")
->field("p.account,p.company_relation,IFNULL(s.real_name,'- ') nickname")
->join("left join (select company_id,account,company_relation,admin_id from tab_promote where level = 1 group by company_id ) p on p.company_id = pc.id")//获取会长
->join("left join sys_member s on s.uid = p.admin_id")
->where("pc.id = {$company_id}")
@ -1183,7 +1260,7 @@ class CompanyStatementSetController extends Controller {
return $ratio;
}
/**
* 获取公司比例加成
* 获取公司奖罚
* @param [type] $paymount 支付金额
* @param [type] $turnover_ratio 梯度
*/
@ -1199,22 +1276,15 @@ class CompanyStatementSetController extends Controller {
$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
")
IFNULL(SUM(CASE WHEN type = 1 THEN amount ELSE 0 END),0) as reward,
IFNULL(SUM(CASE WHEN type = 2 THEN amount ELSE 0 END),0) as fine")
->where($rrmap)
->join("tab_reward_record as r on d.record_id = r.id")
->group("record_id,company_id")
->select();
->group("company_id")
->find();
if(empty($rfres)){
return false;
}else{
$s = [];
foreach($rfres as $k=>$v){
$s[$v['relation_game_id']] = $v;
}
return $s;
$rfres;
}
}