@ -831,12 +831,12 @@ class TimingController extends AdminController {
// $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) {
// $company_id=273 ;
// $relation_game_id=213 ;
// $company_id=64 ;
// $relation_game_id=211 ;
// $pay_amount = 440;
// $date = "2020-07 ";
// $admin_id = 50 ;
// $promote_id = 371 1;
// $date = "2020-08 ";
// $admin_id = 34 ;
// $promote_id = 1726 ;
$begintime = strtotime(date("Y-m-1",strtotime($date)));
$endtime = strtotime(date("Y-m-t",strtotime($date)))+86399;
@ -847,75 +847,44 @@ class TimingController extends AdminController {
return 0;
}
$company_game_ratio = M("company_game_ratio","tab_")
->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id])
->where("(end_time>={$begintime} and (end_time< ={$endtime} and end_time!=0)) or (begin_time>={$begintime} and begin_time< ={$endtime}) or (begin_time< ={$begintime} and (end_time>={$endtime} or end_time=0))")
->order("begin_time ASC")
->select();
// $company_game_ratio = M("company_game_ratio","tab_")
// ->where(['company_id'=>$company_id,'relation_game_id'=>$relation_game_id])
// ->where("(end_time>={$begintime} and (end_time< ={$endtime} and end_time!=0)) or (begin_time>={$begintime} and begin_time< ={$endtime}) or (begin_time< ={$begintime} and (end_time>={$endtime} or end_time=0))")
// ->order("begin_time ASC")
// ->select();
//
$company_data = M('promote_company','tab_')
->field("company_belong")
->where("id=$company_id")
->find();
//
// $game_ratio_mould = M("game_ratio_mould","tab_")
// ->where(['relation_game_id'=>$relation_game_id,'company_belong'=>$company_data['company_belong'],
// "_string"=>"begin_time < ={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})"])
// ->select();
$game_ratio_mould = M("game_ratio_mould","tab_")
->where(['relation_game_id'=>$relation_game_id,'company_belong'=>$company_data['company_belong']])
->find();
$company_game_ratio = D("CompanyGameRatio")->getPromoteCompanyGameRatio($company_id,(string)$relation_game_id,$begintime,$endtime,$company_data['company_belong']);
$company_game_ratio = $company_game_ratio[$relation_game_id] ;
$mould = json_decode($game_ratio_mould ['turnover_ratio'],true);
// $mould = json_decode($company_ game_ratio['turnover_ratio'],true);
$amount = 0;
if (!$company_game_ratio) {
$spend = $this->getSpendData($begintime,$endtime,$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$mould,$game_ratio_mould['ratio'],$pay_amount);
}
foreach ($company_game_ratio as $key => $value) {
$turnover_ratio = json_decode($value['turnover_ratio'],true );
// $spend = $this->getSpendData($begintime,$endtime,$company_id,$relation_game_id,$admin_id,$promote_id);
// $amount += $this->setSpendData($spend,$mould,$game_ratio_mould['ratio'],$pay_amount);
if($value['begin_time'] > $begintime) {
return 0;
if ($key == 0) {
$spend = $this->getSpendData($begintime,$value['begin_time']-1,$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$mould,$game_ratio_mould['ratio'],$pay_amount);
}
if ($value['end_time']< $endtime& & ($value['end_time']!=0)) {
$spend = $this->getSpendData($value['begin_time'],$value['end_time'],$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount);
} else {
$spend = $this->getSpendData($value['begin_time'],$endtime,$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount);
break;
}
foreach ($company_game_ratio as $key => $value) {
$turnover_ratio = json_decode($value['turnover_ratio'],true);
} elseif ($value['begin_time']< =$begintime) {
$spend = $this->getSpendData($value['begintime'],$value['endtime'],$company_id,$relation_game_id,$admin_id,$promote_id);
$value['begin_time']=$begintime;
if ($value['end_time']< $endtime& & ($value['end_time']!=0)) {
$spend = $this->getSpendData($value['begin_time'],$value['end_time'],$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount);
} else {
$spend = $this->getSpendData($value['begin_time'],$endtime,$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount);
break;
}
}
//缺片段的情况下用模板比例补充
if ($company_game_ratio[$key+1]['begin_time'] != $value['end_time']+1 & & $company_game_ratio[$key+1]) {
$spend = $this->getSpendData($value['end_time']+1,$company_game_ratio[$key+1]['begin_time']-1,$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$mould,$game_ratio_mould['ratio'],$pay_amount);
}
//如果最后还有缺失的片段再用模板补齐
if(!$company_game_ratio[$key+1]& & $endtime>$value['end_time']) {
$spend = $this->getSpendData($value['end_time']+1,$endtime,$company_id,$relation_game_id,$admin_id,$promote_id);
$amount += $this->setSpendData($spend,$mould,$game_ratio_mould['ratio'],$pay_amount);
}
}