@ -737,11 +737,19 @@ class CompanyStatementSetController extends Controller {
if($type == 1){
$tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
$tratio += $company_ratio;
// if ($add_data['company_id'] == 12& & $game['relation_game_id'] == 191) {
// dump($tratio);
// dump($game_all_payment);
// dump($tmp_game_ratio);
// dump($company_ratio);
// }
}elseif($type == 0){
// $tratio = $tmp_game_ratio['ratio'];
$turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2 || $turnover_type == 4 ) {
$tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
} else {
$tratio = $tmp_game_ratio['ratio'];
@ -749,7 +757,7 @@ class CompanyStatementSetController extends Controller {
}else{
//补点
$turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2 || $turnover_type == 4 ) {
continue;
}
$tratio1 =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
@ -787,14 +795,14 @@ class CompanyStatementSetController extends Controller {
// $tratio = $t_game_ratio['ratio'];
$turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2 || $turnover_type == 4 ) {
$tratio =$this->getTurnoverRatio($game_all_payment,$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
} else {
$tratio = $tmp_game_ratio['ratio'];
}
}else{
$turnover_type = $this->getTurnoverType($t_game_id,$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2 || $turnover_type == 4 ) {
continue;
}
//补点
@ -929,6 +937,8 @@ class CompanyStatementSetController extends Controller {
public function getPromoteCompanySpend(& $pcList,$idarr,$begintime,$endtime){
$res = [];
$all_res = [];
$cp_res = [];
$cp_all_res = [];
//获取推广员
if(count($idarr) == 0){return $res;}
$Promote = M("Promote","tab_");
@ -937,6 +947,20 @@ class CompanyStatementSetController extends Controller {
"s.pay_status"=>1,
"s.payed_time"=>['between', [$begintime,$endtime]],
];
// dump($spenMap);
$cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
$cpAllMap = $spenMap;
$cpAllMap["s.payed_time"] = ['elt',$endtime];
// unset($cpAllMap["s.payed_time"]);
$cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
for ($i=0; $i < count ( $ idarr ) ; $ i + + ) {
$company_id = $idarr[$i];
@ -970,6 +994,36 @@ class CompanyStatementSetController extends Controller {
}
}
foreach($cpSpendList as $k=>$v){
try {
$cp_res[$company_id]["pay_amount"] += $v['pay_amount'];
} catch (\Throwable $th) {
$cp_res[$company_id]["pay_amount"] = $v['pay_amount'];
}
if(isset($cp_res[$company_id][$v['relation_game_id']])){
//
$cp_res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
unset($v['game_id']);
$cp_res[$company_id][$v['relation_game_id']]= $v;
}
}
foreach($cpAllSpendList as $k=>$v){
try {
$cp_all_res[$company_id]["pay_amount"] += $v['pay_amount'];
} catch (\Throwable $th) {
$cp_all_res[$company_id]["pay_amount"] = $v['pay_amount'];
}
if(isset($cp_all_res[$company_id][$v['relation_game_id']])){
//
$cp_all_res[$company_id][$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
unset($v['game_id']);
$cp_all_res[$company_id][$v['relation_game_id']]= $v;
}
}
if(empty($list)){continue;}
foreach($list as $k=>$v){
@ -1013,6 +1067,16 @@ class CompanyStatementSetController extends Controller {
if ($turnover_type == 2) {
$res[$company_id][$v[$j]]['ratio_pay_amount'] = $all_res[$company_id][$v[$j]]['pay_amount'];
$temp += $all_res[$company_id][$v[$j]]['pay_amount'];
} elseif($turnover_type == 3){
$res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_res[$company_id][$v[$j]]['pay_amount'];
$temp += $cp_res[$company_id][$v[$j]]['pay_amount'];
} elseif($turnover_type == 4){
$res[$company_id][$v[$j]]['ratio_pay_amount'] = $cp_all_res[$company_id][$v[$j]]['pay_amount'];
$temp += $cp_all_res[$company_id][$v[$j]]['pay_amount'];
} else {
// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount'];
$temp += $res[$company_id][$v[$j]]['pay_amount'];
@ -1039,6 +1103,10 @@ class CompanyStatementSetController extends Controller {
$turnover_type = $this->getTurnoverType($k,$key,$begintime,$endtime);
if ($turnover_type == 2) {
$res[$key][$k]['ratio_pay_amount'] = $all_res[$key][$k]['pay_amount'];
} elseif($turnover_type == 3){
$res[$key][$k]['ratio_pay_amount'] = $cp_res[$key][$k]['pay_amount'];
} elseif($turnover_type == 4){
$res[$key][$k]['ratio_pay_amount'] = $cp_all_res[$key][$k]['pay_amount'];
}
}
@ -1059,6 +1127,11 @@ class CompanyStatementSetController extends Controller {
*/
public function getTurnoverType($relation_game_id = 0, $company_id = 0, $begin_time = 0, $end_time = 0){
$company_belong = M("promote_company","tab_")->field("company_belong")->where(['id'=>$company_id])->find();
if (!$company_belong) {
return 0;
}
$turnover_where = [
"company_belong"=>$company_belong['company_belong'],
"relation_game_id"=>$relation_game_id,
@ -1105,6 +1178,19 @@ class CompanyStatementSetController extends Controller {
"s.pay_status"=>1,
"s.payed_time"=>['between', [$begintime,$endtime]],
];
$cpSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($spenMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
$cpAllMap = $spenMap;
$cpAllMap["s.payed_time"] = ['elt',$endtime];
// unset($cpAllMap["s.payed_time"]);
$cpAllSpendList = $Spend->alias('s')->field('sum(s.pay_amount) pay_amount,s.game_id,g.relation_game_id,g.relation_game_name game_name')->where($cpAllMap)->group('game_id')
->join("left join tab_game g on s.game_id = g.id")
->select();
for ($i=0; $i < count ( $ idarr ) ; $ i + + ) {
$company_id = $idarr[$i];
@ -1161,6 +1247,24 @@ class CompanyStatementSetController extends Controller {
}
}
$cpgame = [];
foreach($cpSpendList as $k=>$v){
if(isset($cpgame[$v['relation_game_id']])){
$cpgame[$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
$cpgame[$v['relation_game_id']]['pay_amount'] = $v['pay_amount'];
}
}
$cpallgame = [];
foreach($cpAllSpendList as $k=>$v){
if(isset($cpallgame[$v['relation_game_id']])){
$cpallgame[$v['relation_game_id']]['pay_amount'] += $v['pay_amount'];
}else{
$cpallgame[$v['relation_game_id']]['pay_amount'] = $v['pay_amount'];
}
}
//同cp, 同一个原包名的共享总流水分成
$game_ids = implode(",",array_keys($game));
$game_ids = $this->getModuleRatioGame($company_id,$game_ids,$begintime,$endtime);
@ -1173,6 +1277,10 @@ class CompanyStatementSetController extends Controller {
$turnover_type = $this->getTurnoverType($v[$j],$company_id,$begintime,$endtime);
if ($turnover_type == 2) {
$temp += $allgame[$v[$j]]['pay_amount'];
} elseif($turnover_type == 3) {
$temp += $cpgame[$v[$j]]['pay_amount'];
} elseif($turnover_type == 4) {
$temp += $cpallgame[$v[$j]]['pay_amount'];
} else {
// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount'];
$temp += $game[$v[$j]]['pay_amount'];
@ -1207,6 +1315,10 @@ class CompanyStatementSetController extends Controller {
if ($turnover_type == 2) {
// $temp += $allgame[$v[$j]]['pay_amount'];
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $allgame[$v['relation_game_id']]['pay_amount'];
} elseif($turnover_type == 3) {
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpgame[$v['relation_game_id']]['pay_amount'];
} elseif($turnover_type == 4) {
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $cpallgame[$v['relation_game_id']]['pay_amount'];
} else {
// $res[$company_id][$v[$j]]['ratio_pay_amount'] = $res[$company_id][$v[$j]]['pay_amount'];
$res[$company_id][$p_account][$v['relation_game_id']]['all_pay_amount']= $game[$v['relation_game_id']]['pay_amount'];
@ -1418,14 +1530,14 @@ class CompanyStatementSetController extends Controller {
// $tratio = $tmp_game_ratio['ratio'];
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2||$turnover_type == 4 ) {
$tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
} else {
$tratio = $tmp_game_ratio['ratio'];
}
}else{
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2||$turnover_type == 4 ) {
continue;
}
//补点
@ -1489,7 +1601,7 @@ class CompanyStatementSetController extends Controller {
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2 || $turnover_type == 4 ) {
$tratio =$this->getTurnoverRatio($p_info['all_pay_amount'],$tmp_game_ratio['ratio'],$tmp_game_ratio['turnover_ratio']);
} else {
$tratio = $tmp_game_ratio['ratio'];
@ -1498,7 +1610,7 @@ class CompanyStatementSetController extends Controller {
}else{
$turnover_type = $this->getTurnoverType($p_info['relation_game_id'],$k,$begintime,$endtime);
if ($turnover_type == 2) {
if ($turnover_type == 2 || $turnover_type == 4 ) {
continue;
}
//补点
@ -1931,7 +2043,15 @@ class CompanyStatementSetController extends Controller {
* return string "148,157"
*/
protected function getModuleRatioGame($company_id,$relation_game_ids,$begintime,$endtime){
$company_belong = M("promote_company","tab_")->field("company_belong")->where(['id'=>$company_id])->find();
if(empty($company_belong)){
return $relation_game_ids;
}
$where = [
"company_belong"=>$company_belong['company_belong'],
"relation_game_id"=>["in",$relation_game_ids],
"company_id"=>$company_id,
"_string"=>"begin_time < ={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})"