@ -764,7 +764,10 @@ class TimingController extends AdminController {
*/
*/
public function getSpecialComplement($start_time=0,$end_time =0,$promote_id = 0) {
public function getSpecialComplement($start_time=0,$end_time =0,$promote_id = 0) {
$data = M("company_statement","tab_")->where("statement_begin_time< ={$start_time} and statement_end_time< ={$end_time} and withdraw_type=3")->select();
$data = M("company_statement","tab_")
// ->where("statement_begin_time< ={$start_time} and statement_end_time< ={$end_time} and withdraw_type=3")
->where("(statement_begin_time < ={$end_time} AND ( statement_end_time = 0 OR statement_end_time >= {$start_time})) and withdraw_type=3")
->select();
$return = [];
$return = [];
foreach ($data as $key => $value) {
foreach ($data as $key => $value) {
@ -776,6 +779,13 @@ class TimingController extends AdminController {
foreach ($statement_info as $skey => $sval) {
foreach ($statement_info as $skey => $sval) {
$info = $sval['game_list'];
$info = $sval['game_list'];
foreach ($info as $k => $v) {
foreach ($info as $k => $v) {
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
if (date("m",$statement_begin_time)!=date("m",$start_time) || date("m",$statement_end_time)!=date("m",$end_time)) {
continue;
}
//
//
if (isset($return[$statement_info['promote_id'].$v['relation_game_id']])) {
if (isset($return[$statement_info['promote_id'].$v['relation_game_id']])) {
$return[$value['company_id']."-".$sval['promote_id']."-".$v['relation_game_id']] = !$is_inside?$v['sum_money']:0;
$return[$value['company_id']."-".$sval['promote_id']."-".$v['relation_game_id']] = !$is_inside?$v['sum_money']:0;
@ -793,6 +803,11 @@ class TimingController extends AdminController {
foreach ($statement_info as $k => $v) {
foreach ($statement_info as $k => $v) {
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
if (date("m",$statement_begin_time)!=date("m",$start_time) || date("m",$statement_end_time)!=date("m",$end_time)) {
continue;
}
$amount_time['tab_spend.pay_status'] = 1;
$amount_time['tab_spend.pay_status'] = 1;
$amount_time['pay_way'] = ['egt',0];
$amount_time['pay_way'] = ['egt',0];
$amount_time['_string'] = "payed_time between {$statement_begin_time} and {$statement_end_time} and relation_game_id={$v['relation_game_id']}";
$amount_time['_string'] = "payed_time between {$statement_begin_time} and {$statement_end_time} and relation_game_id={$v['relation_game_id']}";
@ -830,15 +845,16 @@ class TimingController extends AdminController {
// $admin_id = 0,$promote_id = 0,$company_id=0,$relation_game_id=0,$date ='',$pay_amount = 0
// $admin_id = 0,$promote_id = 0,$company_id=0,$relation_game_id=0,$date ='',$pay_amount = 0
public function getCompanyGameRadio($admin_id = 0,$promote_id = 0,$company_id=0,$relation_game_id=0,$date ='' ,$pay_amount = 0) {
public function getCompanyGameRadio($admin_id = 0,$promote_id = 0,$company_id=0,$relation_game_id=0,$begintime=0,$endtime =0 ,$pay_amount = 0) {
// $company_id=64 ;
// $company_id=239 ;
// $relation_game_id=211 ;
// $relation_game_id=213 ;
// $pay_amount = 440;
// $pay_amount = 440;
// $date = "2020-08";
// $date = "2020-08";
// $admin_id = 34;
// $admin_id = 27;
// $promote_id = 1726;
// $promote_id = 3235;
$begintime = strtotime(date("Y-m-1",strtotime($date)));
$endtime = strtotime(date("Y-m-t",strtotime($date)))+86399;
// $begintime = strtotime(date("Y-m-1",strtotime($date)));
// $endtime = strtotime(date("Y-m-t",strtotime($date)))+86399;
$is_inside = M("PromoteCompany","tab_")->field("is_inside")->where("id='{$company_id}'")->find()['is_inside'];
$is_inside = M("PromoteCompany","tab_")->field("is_inside")->where("id='{$company_id}'")->find()['is_inside'];
@ -881,13 +897,15 @@ class TimingController extends AdminController {
foreach ($company_game_ratio as $key => $value) {
foreach ($company_game_ratio as $key => $value) {
$turnover_ratio = json_decode($value['turnover_ratio'],true);
$turnover_ratio = json_decode($value['turnover_ratio'],true);
// dump($value);
$spend = $this->getSpendData($value['begintime'],$value['endtime'],$company_id,$relation_game_id,$admin_id,$promote_id);
$spend = $this->getSpendData($value['begintime'],$value['endtime'],$company_id,$relation_game_id,$admin_id,$promote_id);
// dump($spend);
$amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount);
$amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount);
}
}
// dump($amount);die();
return $amount?$amount:0;
return $amount?$amount:0;
@ -972,8 +990,8 @@ class TimingController extends AdminController {
} else {
} else {
$time_start = strtotime(date('Y-m-1',strtotime($_REQUEST[' time'])));
$time_start = strtotime(date('Y-m-1',strtotime($map['pay_ time'])));
$time_end = strtotime(date('Y-m-t',strtotime($_REQUEST[' time'])));
$time_end = strtotime(date('Y-m-t',strtotime($map['pay_ time'])));
$belong_map = "((begin_time< ={$time_start} and (end_time >={$time_start} or end_time=0)) or (begin_time< ={$time_end} and end_time >={$time_end}) or (end_time>={$time_start} and end_time < ={$time_end}))";
$belong_map = "((begin_time< ={$time_start} and (end_time >={$time_start} or end_time=0)) or (begin_time< ={$time_end} and end_time >={$time_end}) or (end_time>={$time_start} and end_time < ={$time_end}))";
@ -1012,11 +1030,11 @@ class TimingController extends AdminController {
if (!$spend_map['_string']) {
if (!$spend_map['_string']) {
$spend_map['_string'] = "(pay_time between {$value['begin_time']} and {$value['end_time']}+86399 and relation_game_id not in({$value['game_ids']}))";
$spend_map['_string'] = "(pay_time between {$value['begin_time']} and {$value['end_time']}+86399 and relation_game_id in({$value['game_ids']}))";
} else {
} else {
$spend_map['_string'] .= " or (pay_time between {$value['begin_time']} and {$value['end_time']}+86399 and relation_game_id not in({$value['game_ids']}))";
$spend_map['_string'] .= " or (pay_time between {$value['begin_time']} and {$value['end_time']}+86399 and relation_game_id in({$value['game_ids']}))";
}
}
@ -1025,7 +1043,7 @@ class TimingController extends AdminController {
$spend = M("spend","tab_")
$spend = M("spend","tab_")
->field("sum(pay_amount) as pay_amount,FROM_UNIXTIME(pay_time,'%Y-%m') pay_time,
->field("sum(pay_amount) as pay_amount,FROM_UNIXTIME(pay_time,'%Y-%m') pay_time,
substring_index(substring_index(tab_spend.game_name,'(',1),'(',-1) game_name,game_id,relation_game_id,tab_spend.sdk_version,
substring_index(substring_index(tab_spend.game_name,'(',1),'(',-1) game_name,game_id,relation_game_id,tab_spend.sdk_version,
CASE WHEN substring_index(substring_index(`chain`,'/',2),'/',-1) !='' THEN substring_index(substring_index(`chain`,'/',2),'/',-1) ELSE promote_id END promote_id,pay_way,market_admin_id,1 is_settlement")
CASE WHEN substring_index(substring_index(`chain`,'/',2),'/',-1) !='' THEN substring_index(substring_index(`chain`,'/',2),'/',-1) ELSE promote_id END promote_id,pay_way,market_admin_id,0 is_settlement")
->join("left join tab_promote on tab_spend.promote_id = tab_promote.id")
->join("left join tab_promote on tab_spend.promote_id = tab_promote.id")
->join("left join tab_game game on game.id=tab_spend.game_id")
->join("left join tab_game game on game.id=tab_spend.game_id")
->where(['tab_spend.pay_status'=>1,'pay_way'=>['egt',0]])
->where(['tab_spend.pay_status'=>1,'pay_way'=>['egt',0]])
@ -1047,7 +1065,7 @@ class TimingController extends AdminController {
$unsettlement_spend = M("spend","tab_")
$unsettlement_spend = M("spend","tab_")
->field("sum(pay_amount) as pay_amount,FROM_UNIXTIME(pay_time,'%Y-%m') pay_time,
->field("sum(pay_amount) as pay_amount,FROM_UNIXTIME(pay_time,'%Y-%m') pay_time,
substring_index(substring_index(tab_spend.game_name,'(',1),'(',-1) game_name,game_id,relation_game_id,tab_spend.sdk_version,
substring_index(substring_index(tab_spend.game_name,'(',1),'(',-1) game_name,game_id,relation_game_id,tab_spend.sdk_version,
CASE WHEN substring_index(substring_index(`chain`,'/',2),'/',-1) !='' THEN substring_index(substring_index(`chain`,'/',2),'/',-1) ELSE promote_id END promote_id,pay_way,market_admin_id,0 is_settlement")
CASE WHEN substring_index(substring_index(`chain`,'/',2),'/',-1) !='' THEN substring_index(substring_index(`chain`,'/',2),'/',-1) ELSE promote_id END promote_id,pay_way,market_admin_id,1 is_settlement")
->join("left join tab_promote on tab_spend.promote_id = tab_promote.id")
->join("left join tab_promote on tab_spend.promote_id = tab_promote.id")
->join("left join tab_game game on game.id=tab_spend.game_id")
->join("left join tab_game game on game.id=tab_spend.game_id")
->where(['tab_spend.pay_status'=>1,'pay_way'=>['egt',0]])
->where(['tab_spend.pay_status'=>1,'pay_way'=>['egt',0]])
@ -1135,10 +1153,14 @@ class TimingController extends AdminController {
->join("left join tab_promote_company company on promote.company_id = company.id")
->join("left join tab_promote_company company on promote.company_id = company.id")
->join("left join ({$data}) auth on auth.uid=market_admin_id")
->join("left join ({$data}) auth on auth.uid=market_admin_id")
->where(['develop_type'=>['egt',1],'group_id'=>['in',['11','12','21']]])
->where(['develop_type'=>['egt',1],'group_id'=>['in',['11','12','21']]])
// ->where(['company_id'=>64,'spend.promote_id'=>1726,'relation_game_id'=>219])
// ->order("is_settlement ASC")
->select();
->select();
$specialPayAmount = [];
$specialPayAmount = [];
$unsettlement_amount = [];
foreach ($promote_data as $key => $value) {
foreach ($promote_data as $key => $value) {
$cp_radio = getGameCpRadio($value['game_id'],$value['pay_amount'],true);
$cp_radio = getGameCpRadio($value['game_id'],$value['pay_amount'],true);
@ -1153,8 +1175,123 @@ class TimingController extends AdminController {
// $promote_radio = getGamePromoteCompanyRadio($value['company_id'],$value['relation_game_id'],time(),$value['pay_amount'],false,$value['company_belong']);
// $promote_radio = getGamePromoteCompanyRadio($value['company_id'],$value['relation_game_id'],time(),$value['pay_amount'],false,$value['company_belong']);
// }
// }
$begin_pay_time = strtotime(date("Y-m-1",strtotime($value['pay_time'])));
$end_pay_time = strtotime(date("Y-m-t",strtotime($value['pay_time'])))+86399;
$company_belong_game = M("company_belong_game","tab_")
->field("game_ids,begin_time,end_time")
->where("begin_time < ={$end_pay_time} AND ( end_time = 0 OR end_time >= {$begin_pay_time})")
// ->where("((begin_time< ={$begin_pay_time} and (end_time >={$begin_pay_time} or end_time=0)) or (begin_time< ={$end_pay_time} and end_time >={$end_pay_time}) or (end_time>={$begin_pay_time} and end_time < ={$end_pay_time}))")
->order("begin_time ASC")
->select();
$promote_data[$key]['promote_amount'] = 0;
foreach ($company_belong_game as $ck => $cv) {
$ungame_ids = explode(',',$cv['game_ids']);
$use_begin = 0;
$use_end = 0;
if ($value['is_settlement'] == '0') {
if ($begin_pay_time > $cv['begin_time']) {
$use_begin = $begin_pay_time;
if ($end_pay_time > $cv['end_time']+86399) {
$use_end = $cv['end_time']+86399;
} else {
$use_end = $end_pay_time;
}
} else {
$use_begin = $cv['begin_time'];
if ($end_pay_time > $cv['end_time']) {
$use_end = $cv['end_time']+86399;
} else {
$use_end = $end_pay_time;
}
}
//下游流水
$promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$use_begin,$use_end,$value['pay_amount']);
} elseif($value['is_settlement'] == '1') {
if ($ck == 0) {
if ($cv['begin_time'] >= $begin_pay_time) {
$promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$begin_pay_time,$cv['begin_time']-1,$value['pay_amount']);
}
}
if (!$company_belong_game[$ck+1]) {
if ($end_pay_time > $cv['end_time']) {
$promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$cv['end_time']+86400,$end_pay_time,$value['pay_amount']);
}
}
if ($ck > 1) {
if (($cv['begin_time'] - $company_belong_game[$ck-1]['end_time'] + 86399) > 1) {
$promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$company_belong_game[$ck-1]['end_time'] + 86400,$cv['begin_time']-1,$value['pay_amount']);
}
}
if (!in_array($value['relation_game_id'],$ungame_ids)) {
if (($cv['end_time']+86399) > $end_pay_time) {
$cv['end_time'] = $end_pay_time;
} else {
$cv['end_time'] = $cv['end_time']+86399;
}
$promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$cv['begin_time'],$cv['end_time'],$value['pay_amount']);
}
}
// if (!in_array($value['relation_game_id'],$ungame_ids)) {
//
// if ($begin_pay_time > $cv['begin_time']) {
// $use_begin = $begin_pay_time;
// if ($end_pay_time > $cv['end_time']+86399) {
// $use_end = $cv['end_time']+86399;
// } else {
// $use_end = $end_pay_time;
// }
// } else {
//
// $use_begin = $cv['begin_time'];
// if ($end_pay_time > $cv['end_time']) {
// $use_end = $cv['end_time']+86399;
// } else {
// $use_end = $end_pay_time;
// }
//
// }
//
// //下游流水
// $promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$use_begin,$use_end,$value['pay_amount']);
// }
}
if (!$company_belong_game) {
$promote_data[$key]['promote_amount'] += $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$begin_pay_time,$end_pay_time,$value['pay_amount']);
}
//下游流水
//下游流水
$promote_data[$key]['promote_amount'] = $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$value['pay_time'],$value['pay_amount']);
// $promote_data[$key]['promote_amount'] = $this->getCompanyGameRadio($value['admin_id'],$value['promote_id'],$value['company_id'],$value['relation_game_id'],$value['pay_time'],$value['pay_amount'],$value['is_settleme nt']);
//下游流水
//下游流水
// $promote_data[$key]['promote_amount'] = $value['pay_amount'] * ($promote_radio * 0.01);
// $promote_data[$key]['promote_amount'] = $value['pay_amount'] * ($promote_radio * 0.01);