tp5项目添加或编辑
控制器
public function addbasguess(){
$id = input('id');
$list = db('basgame')->where('id',$id)->select();
$this->assign('list',$list);
$team1 = $list[0]['team1'];
$team2 = $list[0]['team2'];
$time = $list[0]['time'];
$gid = $list[0]['id'];
$state = $list[0]['state'];
$guess = db('basguess')->where('gid',$id)->select();
if($guess){
$this->redirect('edit/editbasguess',['id'=>$guess[0]['id']]);
//通过检测表单提交为post提交,将各种数据添加到数据库中,如果数据表中有此记录,则跳转到编辑界面
}else{
if(request()->isPost()){
$odd1a = input('post.odd1a');
$odd2a = input('post.odd2a');
$odd1b = 0.9/($odd1a-1)+1;
$odd2b = 0.9/($odd2a-1)+1;
$bet1a = 100000;
$bet2a = 100000;
$bet1b = 100000;
$bet2b = 100000;
$title1 = input('post.title1');
$title2 = input('post.title2');
$add = db('basguess')->insert(['title1' => $title1,'title2' => $title2,'odd1a' => $odd1a,'odd1b' => $odd1b,
'odd2a' => $odd2a,'odd2b' => $odd2b,'bet1a' => $bet1a,'bet2a' => $bet2a,'bet1b' => $bet1b,'bet2b' => $bet2b,
'team1'=>$team1,'team2'=>$team2,'time'=>$time,'gid'=>$gid,'state'=>$state]);
if($add){
$this->redirect('Index/bglist');
//如果添加成功则返回到列表页
}
//这里创建竞猜与创建比赛类似,不过一个竞猜项目下的两种赔率是有固定关系的,并且四项投注都会有一个起始值来为以后赔率的变动做基础
}
}
return $this->fetch();
}