|
|
|
@ -563,6 +563,8 @@ class CompanyStatementSetController extends Controller {
|
|
|
|
|
unset($tmpp);
|
|
|
|
|
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_");
|
|
|
|
@ -614,43 +616,85 @@ class CompanyStatementSetController extends Controller {
|
|
|
|
|
$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'];
|
|
|
|
|
if(!isset($v['list'])){continue;}
|
|
|
|
|
//游戏统计
|
|
|
|
|
foreach($v['list'] as $ke=>$va){
|
|
|
|
|
|
|
|
|
|
if(!isset($v['game_list'])){continue;}
|
|
|
|
|
//获取多段比例
|
|
|
|
|
$game_ratio_list = D("CompanyGameRatio")->getPromoteCompanyGameRatio($add_data['company_id'],$v['game_ids'],$begintime,$endtime,$company_belong);
|
|
|
|
|
foreach ($game_ratio_list as $t_game_id => $t_game_ratio) {
|
|
|
|
|
$game =[];
|
|
|
|
|
$game['pay_amount'] =$va['pay_amount'];
|
|
|
|
|
$game['game_name'] =$va['game_name'];
|
|
|
|
|
//获取比例
|
|
|
|
|
$game['relation_game_id']=$va['relation_game_id'];
|
|
|
|
|
$game['game_name'] =$v['game_list'][$t_game_id]['game_name'];
|
|
|
|
|
$game['relation_game_id'] =$v['game_list'][$t_game_id]['relation_game_id'];
|
|
|
|
|
$game_all_payment = $v['game_list'][$t_game_id]['pay_amount'];
|
|
|
|
|
|
|
|
|
|
// dump($tratio);
|
|
|
|
|
$game['fax_ratio']=$fax_ratio-0;
|
|
|
|
|
|
|
|
|
|
$game['statement_type']=0;
|
|
|
|
|
|
|
|
|
|
if(count($t_game_ratio) == 1){
|
|
|
|
|
$tmp_game_ratio = $t_game_ratio[0];
|
|
|
|
|
$game['pay_amount'] =$game_all_payment;
|
|
|
|
|
$game['pay_amount'] -=0;
|
|
|
|
|
|
|
|
|
|
$game['statement_begin_time']=$statement_begin_time;
|
|
|
|
|
$game['statement_end_time']=$statement_end_time;
|
|
|
|
|
$add_data['pay_amount'] += $game['pay_amount'];
|
|
|
|
|
|
|
|
|
|
if($type == 1){
|
|
|
|
|
$tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],true,$company_belong);
|
|
|
|
|
$tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio += $company_ratio;
|
|
|
|
|
}elseif($type == 0){
|
|
|
|
|
$tratio = getGamePromoteCompanyRadio($add_data['company_id'],$va['relation_game_id'],$endtime,$va['pay_amount'],false,$company_belong);
|
|
|
|
|
$tratio = $t_game_ratio['ratio'];
|
|
|
|
|
}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);
|
|
|
|
|
$tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio2 =$tmp_game_ratio['ratio'];
|
|
|
|
|
$tratio = $tratio1-$tratio2+$company_ratio;
|
|
|
|
|
if($tratio <= 0){ continue;}
|
|
|
|
|
}
|
|
|
|
|
$tratio = $tratio-0;
|
|
|
|
|
if($v['type'] == 2){
|
|
|
|
|
$game['increment_ratio']=$tratio;
|
|
|
|
|
}else{
|
|
|
|
|
$game['ratio']=$tratio;
|
|
|
|
|
}
|
|
|
|
|
$add_data['pay_amount'] += $va['pay_amount'];
|
|
|
|
|
|
|
|
|
|
$game['sum_money']=round($va['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率)
|
|
|
|
|
$game['sum_money']=round($game['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率)
|
|
|
|
|
$add_data['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;
|
|
|
|
|
$add_data['statement_info'][] = $game;
|
|
|
|
|
}else{
|
|
|
|
|
// dd($t_game_ratio);
|
|
|
|
|
for ($i=0; $i < count($t_game_ratio); $i++) {
|
|
|
|
|
$tmp_game_ratio = $t_game_ratio[$i];
|
|
|
|
|
$temp_game = $game;
|
|
|
|
|
$temp_game['statement_begin_time']=date("Y.m.d",$tmp_game_ratio['begintime']);
|
|
|
|
|
$temp_game['statement_end_time']=date("Y.m.d",$tmp_game_ratio['endtime']);
|
|
|
|
|
// dd($t_game_id);
|
|
|
|
|
$temp_game['pay_amount'] =$this->getRelationGameIdSpend($add_data['company_id'],$t_game_id,$tmp_game_ratio['begintime'],$tmp_game_ratio['endtime']);
|
|
|
|
|
$temp_game['pay_amount'] -=0;
|
|
|
|
|
$add_data['pay_amount'] += $temp_game['pay_amount'];
|
|
|
|
|
|
|
|
|
|
if($type == 1){
|
|
|
|
|
$tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio += $company_ratio;
|
|
|
|
|
}elseif($type == 0){
|
|
|
|
|
$tratio = $t_game_ratio['ratio'];
|
|
|
|
|
}else{
|
|
|
|
|
//补点
|
|
|
|
|
$tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
|
|
|
|
|
$tratio2 =$tmp_game_ratio['ratio'];
|
|
|
|
|
$tratio = $tratio1-$tratio2+$company_ratio;
|
|
|
|
|
if($tratio <= 0){ continue;}
|
|
|
|
|
}
|
|
|
|
|
if($v['type'] == 2){
|
|
|
|
|
$temp_game['increment_ratio']=$tratio;
|
|
|
|
|
}else{
|
|
|
|
|
$temp_game['ratio']=$tratio;
|
|
|
|
|
}
|
|
|
|
|
$temp_game['sum_money']=round($temp_game['pay_amount']*$tratio*(100-$fax_ratio)/(100*100),2);//结算金额=平台总额*(分成比例+补点比例)*(1-税费费率)
|
|
|
|
|
$add_data['statement_money'] += $temp_game['sum_money'];
|
|
|
|
|
$add_data['statement_info'][] = $temp_game;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$add_data['platform_amount'] = $add_data['pay_amount'];
|
|
|
|
|
if($type < 2){
|
|
|
|
@ -789,9 +833,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;
|
|
|
|
|
|
|
|
|
|
$pcList[$k]['game_list'] = $v;
|
|
|
|
|
$pcList[$k]['game_ids'] = implode(",",array_keys($pcList[$k]['game_list']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//获取推广公司推广金额
|
|
|
|
|
protected function getPuPromoteSpend(&$pcList,$idarr,$begintime,$endtime){
|
|
|
|
@ -980,7 +1025,6 @@ 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->getPuPromoteSpend($pc,array_unique(array_keys($pc)),$begintime,$endtime);
|
|
|
|
|
|
|
|
|
@ -1286,102 +1330,58 @@ class CompanyStatementSetController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 按公司获取游戏分成比例
|
|
|
|
|
* 获取比例
|
|
|
|
|
*
|
|
|
|
|
* @param [type] $company_id 公司id
|
|
|
|
|
* @param [type] $game_ids 游戏关联id
|
|
|
|
|
* @param [type] $begintime 开始时间
|
|
|
|
|
* @param [type] $endtime 结束时间
|
|
|
|
|
* @param boolean $company_belong 公司内外团
|
|
|
|
|
* @param [type] $amount 总额
|
|
|
|
|
* @param [type] $ratio 默认比例
|
|
|
|
|
* @param [type] $turnover_ratio 比例梯度
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function getPromoteCompanyGameRatio($company_id,$game_ids,$begintime,$endtime,$company_belong=false){
|
|
|
|
|
//获取默认比例
|
|
|
|
|
if($company_belong === false){
|
|
|
|
|
$company_belong = M("PromoteCompany","tab_")->field("company_belong")->where("id='{$company_id}'")->find()['company_belong'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mwhere = [
|
|
|
|
|
"company_belong"=>$company_belong,
|
|
|
|
|
"relation_game_id"=>["in",$game_ids]
|
|
|
|
|
];
|
|
|
|
|
$m_res = M("GameRatioMould","tab_")->where($mwhere)->select();
|
|
|
|
|
$modul_ratio = [];
|
|
|
|
|
for ($i=0; $i < count($m_res); $i++) {
|
|
|
|
|
$modul_ratio[$m_res[$i]['relation_game_id']] = $m_res[$i];
|
|
|
|
|
}
|
|
|
|
|
unset($m_res);
|
|
|
|
|
//设置默认
|
|
|
|
|
$game_ratio = [];
|
|
|
|
|
$tmp_g = explode(",",$game_ids);
|
|
|
|
|
for ($i=0; $i < count($tmp_g); $i++) {
|
|
|
|
|
$game_ratio[$tmp_g[$i]] = [
|
|
|
|
|
["begintime"=>$begintime,"endtime"=>$endtime]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$map = [
|
|
|
|
|
"company_id"=>$company_id,
|
|
|
|
|
"relation_game_id"=>['in',$game_ids],
|
|
|
|
|
"_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})"
|
|
|
|
|
];
|
|
|
|
|
$res = M("company_game_ratio","tab_")->where($map)->order("begin_time asc")->select();
|
|
|
|
|
foreach($res as $k=>$v){
|
|
|
|
|
//获取最后一个数据
|
|
|
|
|
$tgr = &$game_ratio[$v['relation_game_id']];
|
|
|
|
|
$last_time_ratio = end($game_ratio[$v['relation_game_id']]);
|
|
|
|
|
if($v['end_time'] == 0 || ($v['end_time'] >= $last_time_ratio['endtime'])){
|
|
|
|
|
//全段
|
|
|
|
|
if($v['begin_time'] <= $last_time_ratio['begintime']){
|
|
|
|
|
$tgr[count($tgr)-1]['ratio'] = $v['ratio'];
|
|
|
|
|
$tgr[count($tgr)-1]['turnover_ratio'] = $v['turnover_ratio'];
|
|
|
|
|
continue;
|
|
|
|
|
}else{
|
|
|
|
|
//上分段
|
|
|
|
|
$tgr[count($tgr)-1]['endtime'] = $v['begin_time']-1;
|
|
|
|
|
$tgr[] = ['begintime'=>$v['begin_time'],"endtime"=>$last_time_ratio['endtime'],"ratio"=>$v['ratio'],"turnover_ratio"=>$v['turnover_ratio']];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if($v['end_time'] < $last_time_ratio['endtime']){
|
|
|
|
|
if($last_time_ratio['begintime'] < $v['begin_time']){
|
|
|
|
|
//中段
|
|
|
|
|
$tgr[count($tgr)-1]['endtime'] = $v['begin_time']-1;
|
|
|
|
|
|
|
|
|
|
$tgr[] = ['begintime'=>$v['begin_time'],"endtime"=>$v['end_time'],"ratio"=>$v['ratio'],"turnover_ratio"=>$v['turnover_ratio']];
|
|
|
|
|
|
|
|
|
|
$tgr[] = ['begintime'=>$v['end_time']-0+1,"endtime"=>$last_time_ratio['endtime']];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if($last_time_ratio['begintime'] > $v['begin_time']){
|
|
|
|
|
//下分段
|
|
|
|
|
$tgr[count($tgr)-1]['endtime'] = $v['end_time'];
|
|
|
|
|
$tgr[] = ['begintime'=>$v['end_time']-0+1,"endtime"=>$last_time_ratio['endtime'],"ratio"=>$v['ratio'],"turnover_ratio"=>$v['turnover_ratio']];
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if($last_time_ratio['begintime'] = $v['begin_time']){
|
|
|
|
|
$tgr[count($tgr)-1]['endtime'] = $v['end_time'];
|
|
|
|
|
$tgr[count($tgr)-1]['ratio'] = $v['ratio'];
|
|
|
|
|
$tgr[count($tgr)-1]['turnover_ratio'] = $v['turnover_ratio'];
|
|
|
|
|
|
|
|
|
|
$tgr[] = ['begintime'=>$v['end_time']-0+1,"endtime"=>$last_time_ratio['endtime']];
|
|
|
|
|
protected function getTurnoverRatio($amount,$ratio,$turnover_ratio)
|
|
|
|
|
{
|
|
|
|
|
if(empty($turnover_ratio)){
|
|
|
|
|
return $ratio;
|
|
|
|
|
}
|
|
|
|
|
if(!is_array($turnover_ratio)){
|
|
|
|
|
$turnover_ratio = json_decode($turnover_ratio,true);
|
|
|
|
|
}
|
|
|
|
|
foreach($turnover_ratio as $k=>$v){
|
|
|
|
|
if($v['instanceof'] == 1){
|
|
|
|
|
if($amount >= $v['turnover']){
|
|
|
|
|
$ratio = $v['ratio'];
|
|
|
|
|
}
|
|
|
|
|
//模板填充
|
|
|
|
|
foreach($game_ratio as $k=>&$list){
|
|
|
|
|
foreach($list as $i => &$ratio){
|
|
|
|
|
if(!isset($ratio['ratio'])){
|
|
|
|
|
if(isset($modul_ratio[$k]['ratio'])){
|
|
|
|
|
$ratio['ratio'] = $modul_ratio[$k]['ratio'];
|
|
|
|
|
$ratio['turnover_ratio'] = $modul_ratio[$k]['turnover_ratio'];
|
|
|
|
|
}else{
|
|
|
|
|
$ratio['ratio'] = 0;
|
|
|
|
|
$ratio['turnover_ratio'] =null;
|
|
|
|
|
if($amount > $v['turnover']){
|
|
|
|
|
$ratio = $v['ratio'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $ratio;
|
|
|
|
|
}
|
|
|
|
|
return $game_ratio;
|
|
|
|
|
|
|
|
|
|
protected function getRelationGameIdSpend($company_id,$relation_game_id,$begintime,$endtime)
|
|
|
|
|
{
|
|
|
|
|
$res = [];
|
|
|
|
|
//获取推广员
|
|
|
|
|
$Promote = M("Promote","tab_");
|
|
|
|
|
$Spend = M("Spend","tab_");
|
|
|
|
|
$spenMap = [
|
|
|
|
|
"s.pay_status"=>1,
|
|
|
|
|
"s.payed_time"=>['between', [$begintime,$endtime]],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$company_id = $company_id;
|
|
|
|
|
$pres = $Promote->field("group_concat(id) ids,count(id) count")->where("company_id = '{$company_id}'")->group("company_id")->find();
|
|
|
|
|
if($pres['count'] ==0 ){return 0;}
|
|
|
|
|
$spenMap['s.promote_id']=["in",$pres['ids']];
|
|
|
|
|
//游戏
|
|
|
|
|
|
|
|
|
|
$game_id = D("Game")->changeRelationGameidToGameid($relation_game_id);
|
|
|
|
|
// dd($game_id);
|
|
|
|
|
$spenMap['s.game_id'] =['in',$game_id];
|
|
|
|
|
//获取支付记录
|
|
|
|
|
$pay_amount = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount')->where($spenMap)->find();
|
|
|
|
|
return $pay_amount['pay_amount'] ?? 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|