<?php

namespace app\admin\controller;
use think\Controller;
use think\Db;
class Zsb extends Common
{
public function lst()
{
$list=Db::query("select id,bmc,jmc,lmc,mc from vw_zsb ");
$this->assign('list',$list);
return $this->fetch();
}
public function add()
{
$bdzs=Db::query("select id,mc from bdz ");
$lxs=Db::query("select id,mc from lx ");
if (request()->isPost()){
$data = input('post.');
if(db('zsb')->insert($data)){
return $this->success('ok','lst');
}
else {
return $this->error('false');
}
return ;
}
$this->assign('bdzs',$bdzs);
$this->assign('lxs',$lxs);
return $this->fetch();
}
public function edit(){
$id=input('id');
$sbs=db('zsb')->find($id);
$bdzs=Db::query("select id,mc from bdz ");
$lxs=Db::query("select id,mc from lx ");
if(request()->ispost()){
$data=[
'id'=>input('id'),
'mc'=>input('mc'),
'bdzid'=>input('bdzid'),
'jgid'=>input('jgid'),
'lxid'=>input('lxid'),
];
$save=db('zsb')->update($data);
if($save !== false){
$this->success('修改主设备成功！','lst');
}else{
$this->error('修改主设备失败！');
}
return;
}
$this->assign('sbs',$sbs);
$this->assign('bdzs',$bdzs);
$this->assign('lxs',$lxs);
return $this->fetch();
}
public function del(){
$id=input('id');
if(db('zsb')->delete(input('id'))){
$this->success('删除主设备成功！','lst');
}else{
$this->error('删除主设备失败！');
}
}
public function getjg(){
if (empty($_GET['bid'])) return;
$bid = $_GET['bid'];
$data=Db::query("select id,mc from jg where bdzid='{$bid}'");
echo json_encode($data);
}
public function logout(){
session(null);
$this->success('退出成功！','Login/index');
}
}
?>