@ -35,19 +35,47 @@ class GameRatioMouldController extends AdminController
}
$this->checkListOrCountAuthRestMap($where);
$gameres = M("game","tab_")->field("tab_game.relation_game_id,tab_game.relation_game_name,IF(tab_game.original_package_name='','未配置',tab_game.original_package_name) original_package_name,tab_game_type.type_name game_type_name")->where($gamewhere)->join("tab_game_type on tab_game.game_type_id = tab_game_type.id")->group("tab_game.relation_game_id")->select(false);
$dbres = $this->DBModel->alias('m')->join("INNER JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")->where($where)->order('create_time desc, id desc');
$dbres = $this->DBModel->alias('m')
->field("*,group_concat(id SEPARATOR '|') id,group_concat(turnover_type SEPARATOR '|') turnover_type,group_concat(ratio SEPARATOR '|') ratio,group_concat(begin_time SEPARATOR '|') begin_time,group_concat(end_time SEPARATOR '|') end_time,group_concat(m.turnover_ratio SEPARATOR '|') turnover_ratio")
->join("INNER JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")->where($where)->order('create_time desc, id desc');
if(isset($params['export'])){
$dbres = $dbres->select();
$dbres = $dbres->group("m.relation_game_id,company_belong")-> select();
}else{
$dbres = $dbres->page($page, $row)->select();
$dbres = $dbres->page($page, $row)->group("m.relation_game_id,company_belong")-> select();
}
foreach($dbres as $k=>& $v){
$begin_time = explode('|',$v['begin_time']);
$end_time = explode('|',$v['end_time']);
$id_data = explode('|',$v['id']);
$turnover_type = explode('|',$v['turnover_type']);
foreach ($begin_time as $tk => $tv) {
$begintime = date("Y-m-d",$tv);
$endtime = $end_time[$tk] ? date('Y-m-d', $end_time[$tk]) : '永久';
$v["valid"][$tk] = "{$begintime} ~ {$endtime}";
$v["ids"][$tk] = $id_data[$tk];
if($turnover_type[$tk] == 0) {
$v["turnover_types"][$tk] = "无";
} elseif($turnover_type[$tk] == 1) {
$v["turnover_types"][$tk] = "月流水";
} elseif($turnover_type[$tk] == 2) {
$v["turnover_types"][$tk] = "历史流水";
}
}
$v['create_time'] = date("Y-m-d H:i:s",$v['create_time']);
$v['company_belong'] ="下游".getCompanyBlong($v['company_belong']);
$this->readTurnoverRatio($v);
}
$this->assign('data', $dbres);
//判断导出
if(isset($_REQUEST['export'])){
@ -57,7 +85,15 @@ class GameRatioMouldController extends AdminController
$this->display("export");
exit();
}
$count = $this->DBModel->alias('m')->field("count(id) count")->join("INNER JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")->where($where)->find()['count'];
// $count = $this->DBModel->alias('m')->field("count(id) count")->join("INNER JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")->where($where)->find()['count'];
$count = $this->DBModel->alias('m')
->field("id")
->join("INNER JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")->where($where)->group("m.relation_game_id,company_belong")->select(false);
$count = M()->table("({$count})a")->count();
$page = set_pagination($count, $row,$params);
if($page) {
$this->assign('_page', $page);
@ -68,6 +104,109 @@ class GameRatioMouldController extends AdminController
$this->display();
}
public function companyRatioTimeChange($company_belong = 0,$relation_game_id = 0, $begin_time = 0, $end_time = 0,$ratiov=[]) {
// dump($ratiov);die();
if (!$company_belong& & $company_belong!="0" || !$relation_game_id) {
$this->error("参数错误.");
}
// dump($end_time);dump($begin_time);die();
$check_data = M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
->find();
if ($check_data) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$begin_time,'end_time'=>$end_time])
->save($ratiov);
return;
}
M("game_ratio_mould","tab_")
->where("company_belong={$company_belong} and relation_game_id={$relation_game_id} and begin_time>={$begin_time} and end_time < = {$end_time} and end_time!=0")
->delete();
$data = M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id])
->order("begin_time DESC")
->select();
foreach($data as $key => $value) {
if ($value['begin_time'] > $begin_time) {
if (!$end_time) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->delete();
continue;
}
if ($value['begin_time'] >= $end_time & & $value['end_time']!=0) {
continue;
}
if ($end_time > $value['begin_time'] & & ($end_time < $value['end_time']||$value['end_time']==0)) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$end_time+1]);
} else if ($end_time > $value['begin_time'] & & ($end_time >= $value['end_time']& & $value['end_time']!=0)) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$begin_time,'end_time'=>$end_time]);
}
} else if ($value['begin_time'] < = $begin_time) {
if (!$end_time& & ($value['end_time']>$begin_time||$value['end_time']==0)) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
continue;
}else if (!$end_time) {
continue;
}
if ($begin_time >= $value['end_time']& & $value['end_time']!=0) {
continue;
}
if ($begin_time > $value['begin_time'] & & ($end_time >= $value['end_time'] & & $value['end_time']!=0)) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
} else if ($begin_time > $value['begin_time'] & & ($end_time < $value['end_time']||$value['end_time']==0)) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
$dataValue = $value;
$dataValue['begin_time'] = $end_time+1;
unset($dataValue['id']);
M("game_ratio_mould","tab_")->add($dataValue);
} else if ($begin_time == $value['begin_time'] & & ($end_time < $value['end_time']||$value['end_time']==0)) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$end_time+1]);
} else if ($end_time == $value['end_time']& & $begin_time>$value['begin_time']) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['end_time'=>$begin_time-1]);
} else if ($end_time == $value['end_time']& & $begin_time == $value['begin_time']) {
M("game_ratio_mould","tab_")
->where(['company_belong'=>$company_belong,'relation_game_id'=>$relation_game_id,'begin_time'=>$value['begin_time'],'end_time'=>$value['end_time']])
->save(['begin_time'=>$begin_time,'end_time'=>$end_time]);
}
}
}
M("game_ratio_mould","tab_")->add($ratiov);
}
public function add()
{
@ -84,18 +223,25 @@ class GameRatioMouldController extends AdminController
$save["admin_name"]=$this->admininfo["username"];
$save["admin_id"]=$this->admininfo["uid"];
$save["create_time"]=time();
$save["begin_time"] = strtotime($params["begin_time"]) ?? 0;
$save["end_time"] = $params["end_time"] ?strtotime($params["end_time"]): 0;
$save["turnover_type"] = $params["turnover_type"] ?? 0;
//判断是否存在
$where = [
"relation_game_id"=>$save['relation_game_id'],
"company_belong"=>$save['company_belong']
];
$hasdb = $this->DBModel->field("count(id) count")->where($where)->find()['count'];
if($hasdb > 0){
$this->error('该游戏与该公司类型的模板已经存在,请搜索后编辑');
}
// $where = [
// "relation_game_id"=>$save['relation_game_id'],
// "company_belong"=>$save['company_belong']
// ];
// $hasdb = $this->DBModel->field("count(id) count")->where($where)->find()['count'];
// if($hasdb > 0){
// $this->error('该游戏与该公司类型的模板已经存在,请搜索后编辑');
// }
$this->companyRatioTimeChange($save['company_belong'],$save['relation_game_id'],$save["begin_time"],$save["end_time"],$save);
//保存
$id = $this->DBModel->add($save);
addOperationLog(['op_type'=>0,'key'=>$id,'op_name'=>'新增游戏分成比例模板','url'=>U('GameRatioMould/index')]);
// $id = $this->DBModel->add($save);
addOperationLog(['op_type'=>0,'key'=>$save['relation_game_ id'] ,'op_name'=>'新增游戏分成比例模板','url'=>U('GameRatioMould/index')]);
$this->ajaxReturn(["msg"=>"添加成功","code"=>1,"url"=>U("index")]);
} else {
$game_type = M("game_type","tab_")->field("id,type_name")->where("status=1")->select();
@ -116,6 +262,7 @@ class GameRatioMouldController extends AdminController
$save['id'] = $params['id'];
$save["create_time"]=time();
$save['turnover_ratio'] = $this->setTurnoverRatio($params);
$save["turnover_type"] = $params["turnover_type"] ?? 0;
$this->DBModel->save($save);
addOperationLog(['op_type'=>1,'key'=>$save['id'],'op_name'=>'修改游戏分成比例模板','url'=>U('PromoteGameRatio/index')]);
@ -129,6 +276,10 @@ class GameRatioMouldController extends AdminController
$dbres = $this->DBModel->alias('m')->join("INNER JOIN ({$gameres}) g ON m.relation_game_id = g.relation_game_id")->where($map)->find();
$dbres['turnover_ratio'] = $dbres['turnover_ratio'] ? json_decode($dbres['turnover_ratio'], true) : $dbres['turnover_ratio'];
$dbres['company_belong'] = getCompanyBlong($dbres['company_belong']);
$dbres['begin_time'] = date("Y-m-d",$dbres['begin_time']);
$dbres['end_time'] = $dbres['end_time']==0 ? '永久' :date("Y-m-d",$dbres['end_time']);
$this->assign('data', $dbres);
$this->display();
}
@ -210,14 +361,47 @@ class GameRatioMouldController extends AdminController
}
return $save['turnover_ratio'];
}
//设置比例阶梯
// protected function readTurnoverRatio(& $v){
// $turnover_ratio = json_decode($v['turnover_ratio'],true);
// $v['turnover_ratio'] = array(
// array("ratio"=>floatval($v['ratio'])."%","name"=>"默认比例")
// );
//
// foreach($turnover_ratio as $ke=>$va){
// $t=array("ratio"=>floatval($va["ratio"])."%");
// if(array_key_exists("instanceof",$va)){
// //存在
// if($va['instanceof']=='1'){
// $t['name']="月流水≥".$va['turnover'];
// }else{
// $t['name']="月流水>".$va['turnover'];
// }
// }else{
// $t['name']="月流水≥".$va['turnover'];
// }
// $v['turnover_ratio'][]=$t;
// }
// $v['row'] = count($v['turnover_ratio']);
// }
//设置比例阶梯
protected function readTurnoverRatio(& $v){
$turnover_ratio = json_decode($v['turnover_ratio'],true);
$v['turnover_ratio'] = array(
array("ratio"=>floatval($v['ratio'])."%","name"=>"默认比例")
$radio = explode('|',$v['ratio']);
$turnover_ratio = explode('|',$v['turnover_ratio']);
$sec_row = 1;
foreach ($radio as $key => $value) {
$turnoverratio = json_decode($turnover_ratio[$key],true);
$v['turnover_ratios'][$key] = array(
array("ratio"=>floatval($value)."%","name"=>"默认比例")
);
foreach($turnover_ratio as $ke=>$va){
foreach($turnoverratio as $ke=>$va){
$t=array("ratio"=>floatval($va["ratio"])."%");
if(array_key_exists("instanceof",$va)){
//存在
@ -229,9 +413,14 @@ class GameRatioMouldController extends AdminController
}else{
$t['name']="月流水≥".$va['turnover'];
}
$v['turnover_ratio'][]=$t;
$sec_row++;
$v['turnover_ratios'][$key][]=$t;
}
$v['row'] = count($v['turnover_ratio']);
$v['sec_row'][$key] = $sec_row;
$sec_row = 1;
}
$v['row'] = array_sum($v['sec_row']);
}