diff --git a/Application/Admin/Controller/GameRatioMouldController.class.php b/Application/Admin/Controller/GameRatioMouldController.class.php index ca5b37d2d..6afd5aac6 100644 --- a/Application/Admin/Controller/GameRatioMouldController.class.php +++ b/Application/Admin/Controller/GameRatioMouldController.class.php @@ -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 = [ diff --git a/Application/Admin/Controller/TimingController.class.php b/Application/Admin/Controller/TimingController.class.php index 3548d0a95..f6b172497 100644 --- a/Application/Admin/Controller/TimingController.class.php +++ b/Application/Admin/Controller/TimingController.class.php @@ -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); - - if($value['begin_time'] > $begintime) { - - 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; - } - +// $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); - } elseif ($value['begin_time']<=$begintime) { + return 0; - $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; - } + } - } + foreach ($company_game_ratio as $key => $value) { + $turnover_ratio = json_decode($value['turnover_ratio'],true); - //缺片段的情况下用模板比例补充 - 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); - } + $spend = $this->getSpendData($value['begintime'],$value['endtime'],$company_id,$relation_game_id,$admin_id,$promote_id); - //如果最后还有缺失的片段再用模板补齐 - 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); - } + $amount += $this->setSpendData($spend,$turnover_ratio,$value['ratio'],$pay_amount); } diff --git a/Application/Admin/Model/CompanyGameRatioModel.class.php b/Application/Admin/Model/CompanyGameRatioModel.class.php index 95dbb6f94..f633caee3 100644 --- a/Application/Admin/Model/CompanyGameRatioModel.class.php +++ b/Application/Admin/Model/CompanyGameRatioModel.class.php @@ -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; - }else{ - $ratio['ratio'] = 0; - $ratio['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; } } \ No newline at end of file diff --git a/Application/Admin/View/GameRatioMould/add.html b/Application/Admin/View/GameRatioMould/add.html index e4ba49509..37f9a2a7d 100644 --- a/Application/Admin/View/GameRatioMould/add.html +++ b/Application/Admin/View/GameRatioMould/add.html @@ -230,15 +230,10 @@ $(".select_gallery").select2(); $(function(){ $('.time').datetimepicker({ - format: 'yyyy-mm', - language: "zh-CN", - autoclose: true, - scrollMonth: false, - scrollTime: false, - scrollInput: false, - startView: 'year', - minView:'year', - maxView:'year', + format: 'yyyy-mm-dd', + language: "zh-CN", + minView: 2, + autoclose: true }); showTab();