比例逻辑修改

master
zhengyongxing 4 years ago
parent 0c69c8f662
commit 6ac5c1d524

@ -225,7 +225,7 @@ class GameRatioMouldController extends AdminController
$save["create_time"]=time();
$save["begin_time"] = strtotime($params["begin_time"]) ?? 0;
$save["end_time"] = $params["end_time"] ?strtotime($params["end_time"]): 0;
$save["end_time"] = $params["end_time"] ?strtotime($params["end_time"])-1: 0;
$save["turnover_type"] = $params["turnover_type"] ?? 0;
//判断是否存在
// $where = [

@ -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 = 3711;
// $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);
}
}

@ -51,6 +51,7 @@ class CompanyGameRatioModel extends Model
"_string"=>"begin_time <={$endtime} AND ( end_time = 0 OR end_time >= {$begintime})"
];
$res = $this->where($map)->order("begin_time asc")->select();
foreach($res as $k=>$v){
//获取最后一个数据
$tgr = &$game_ratio[$v['relation_game_id']];
@ -60,11 +61,13 @@ class CompanyGameRatioModel extends Model
if($v['begin_time'] <= $last_time_ratio['begintime']){
$tgr[count($tgr)-1]['ratio'] = !$is_inside?$v['ratio']:0;
$tgr[count($tgr)-1]['turnover_ratio'] = !$is_inside?$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"=>!$is_inside?$v['ratio']:0,"turnover_ratio"=>!$is_inside?$v['turnover_ratio']:[]];
continue;
}
}
@ -76,37 +79,80 @@ class CompanyGameRatioModel extends Model
$tgr[] = ['begintime'=>$v['begin_time'],"endtime"=>$v['end_time'],"ratio"=>!$is_inside?$v['ratio']:0,"turnover_ratio"=>!$is_inside?$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"=>!$is_inside?$v['ratio']:0,"turnover_ratio"=>!$is_inside?$v['turnover_ratio']:[]];
$tgr[count($tgr)-1]['begintime'] = $v['end_time']-0+1;
// $tgr[] = ['begintime'=>$v['end_time']-0+1,"endtime"=>$last_time_ratio['endtime'],"ratio"=>!$is_inside?$v['ratio']:0,"turnover_ratio"=>!$is_inside?$v['turnover_ratio']:[]];
$tgr[] = ['begintime'=>$last_time_ratio['begintime'],"endtime"=>$v['end_time']-0,"ratio"=>!$is_inside?$v['ratio']:0,"turnover_ratio"=>!$is_inside?$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'] = !$is_inside?$v['ratio']:0;
$tgr[count($tgr)-1]['turnover_ratio'] = !$is_inside?$v['turnover_ratio']:[];
$tgr[] = ['begintime'=>$v['end_time']-0+1,"endtime"=>$last_time_ratio['endtime']];
}
}
}
$return_data = [];
//模板填充
foreach($game_ratio as $k=>&$list){
foreach($list as $i => &$ratio){
if(!isset($ratio['ratio'])){
if(isset($modul_ratio[$k]['ratio'])){
$ratio['ratio'] = !$is_inside?$modul_ratio[$k]['ratio']:0;
$ratio['turnover_ratio'] = !$is_inside?$modul_ratio[$k]['turnover_ratio']:null;
$mouldwhere = [
"company_belong"=>$company_belong,
"relation_game_id"=>["in",(string)$k],
"_string"=>"begin_time <={$ratio['endtime']} AND ( end_time = 0 OR end_time >= {$ratio['begintime']})"
];
$moulddata = M("GameRatioMould","tab_")->field("begin_time begintime,end_time endtime,ratio,turnover_ratio")->where($mouldwhere)->order("begin_time asc")->select();
if ($moulddata) {
foreach ($moulddata as $key => $value) {
if ($key == 0) {
$value['begintime'] = $ratio['begintime'];
}
if (!$moulddata[$key+1]) {
$value['endtime'] = $ratio['endtime'];
}
$return_data[$k][] = $value;
}
} else {
$ratio['ratio'] = 0;
$ratio['turnover_ratio'] =null;
$return_data[$k][] = $ratio;
}
// if(isset($modul_ratio[$k]['ratio'])){
// $ratio['ratio'] = !$is_inside?$modul_ratio[$k]['ratio']:0;
// $ratio['turnover_ratio'] = !$is_inside?$modul_ratio[$k]['turnover_ratio']:null;
// }else{
// $ratio['ratio'] = 0;
// $ratio['turnover_ratio'] =null;
// }
} else {
$return_data[$k][] = $ratio;
}
}
}
return $game_ratio;
return $return_data;
}
}

@ -230,15 +230,10 @@ $(".select_gallery").select2();
$(function(){
$('.time').datetimepicker({
format: 'yyyy-mm',
format: 'yyyy-mm-dd',
language: "zh-CN",
autoclose: true,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
startView: 'year',
minView:'year',
maxView:'year',
minView: 2,
autoclose: true
});
showTab();

Loading…
Cancel
Save