@ -405,12 +405,14 @@ class GameController extends ThinkController
$data['introduction'] = str_replace("~~", "\r\n", $data['introduction']);
$this->assign('data', $data);
$this->assign('game_id', $id);
$game_ratio = M('cp_game_ratio', 'tab_')->where(array('is_del'=>"0","game_id"=>$id))->order('begin_total_amount asc')->select();
$this->meta_title = '编辑游戏';
$this->m_title = '游戏列表';
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Game/lists', 'status' => 1])->find());
$this->assign('game_ratio',$game_ratio);
$this->display();
}
}
@ -761,4 +763,80 @@ class GameController extends ThinkController
}
/**
* 编辑CP分成比例
*/
public function edit_ratio(){
$data = $_POST;
if($data['data_id']==0 || $data['data_id']==""){ //查询初始分成比例信息
$initial_info = M('cp_game_ratio', 'tab_')->where("game_id=%d and begin_total_amount=0 and is_del=0",$data['game_id'])->find();
}
if($data['data_type']=='initial'){ //CP初始分成比例
if($data['data_id']>0){ //修改初始CP分成比例
$where = array();
$where['is_del'] = "0";
$where['game_id'] = $data['game_id'];
$where['id'] = array("neq",$data['data_id']);
$where['ratio'] = array("elt",$data['game_ratio']);
$info = M('cp_game_ratio', 'tab_')
->where($where)
->order("ratio asc")
->find();
if($info){
die(json_encode(array("result"=>"0","desc"=>"CP分成比例应小于".$info['ratio']."%")));
}
M('cp_game_ratio', 'tab_')->where("id=%d",$data['data_id'])->data(array("ratio"=>$data['game_ratio'],"update_time"=>time()))->save();
}else{
if($initial_info){
M('cp_game_ratio', 'tab_')->where("id=%d",$initial_info['id'])->data(array("ratio"=>$data['game_ratio'],"update_time"=>time()))->save();
}else{
M('cp_game_ratio', 'tab_')->data(array("game_id"=>$data['game_id'],"ratio"=>$data['game_ratio'],"begin_total_amount"=>0,"add_time"=>time(),"update_time"=>time()))->add();
}
}
}else{ //CP阶梯分成档位
if($data['data_id']>0) { //修改阶梯分成
$where = array();
$where['game_id']= $data['game_id'];
$where['is_del'] = "0";
$where['id']=array("neq",$data['data_id']);
$exis_info = M('cp_game_ratio', 'tab_')
->where($where)
->where("begin_total_amount='%s' or ratio = '%f'",array($data['total_amount'],$data['game_ratio']))
->find();
if($exis_info){
die(json_encode(array("result"=>"0","desc"=>"分成档位已存在")));
}
if($initial_info['game_ratio']>=$data['game_ratio']){
die(json_encode(array("result"=>"0","desc"=>"分成比例不得小于初始比例")));
}
M('cp_game_ratio', 'tab_')->where("id=%d",$data['data_id'])->data(array("ratio"=>$data['game_ratio'],"begin_total_amount"=>$data['total_amount'],"update_time"=>time()))->save();
}else{
if(!$initial_info){
die(json_encode(array("result"=>"0","desc"=>"请先设置初始CP分成比例")));
}
$exis_info = M('cp_game_ratio', 'tab_')->where("game_id=%d and (begin_total_amount='%s' or ratio = '%f') and is_del=0",array($data['game_id'],$data['total_amount'],$data['game_ratio']))->find();
if($exis_info){
die(json_encode(array("result"=>"0","desc"=>"分成档位已存在")));
}else{
$max_info = M('cp_game_ratio', 'tab_')->field("max(ratio) as max_ratio,max(begin_total_amount) as max_amount")->where("game_id=%d and is_del=0",$data['game_id'])->find();
if($max_info['max_ratio'] >= $data['game_ratio'] || $max_info['max_amount']>=$data['total_amount']){
die(json_encode(array("result"=>"0","desc"=>"新增分成档位金额或分成比例需大于现有分成档位")));
}
M('cp_game_ratio', 'tab_')->data(array("game_id"=>$data['game_id'],"ratio"=>$data['game_ratio'],"begin_total_amount"=>$data['total_amount'],"add_time"=>time(),"update_time"=>time()))->add();
}
}
}
echo(json_encode(array("result"=>"1","desc"=>"数据保存成功")));
}
/**
* 删除CP分成比例
*/
public function delete_ratio(){
M('cp_game_ratio', 'tab_')->where("id=".$_POST['data_id'])->data(array("is_del"=>"1","update_time"=>time()))->save();
echo(json_encode(array("result"=>"1","desc"=>"删除成功")));
}
}