<?php

namespace app\admin\controller;
use think\Controller;
use think\Db;
class  Ied extends Common
{
public function lst()
{
$list=Db::query("select * from vw_ied ");
$this->assign('list',$list);
return $this->fetch();
}
public function add()
{
$cags=Db::query("select id,name from cag ");
if (request()->isPost()){
$data = input('post.');
unset($data["cagid"]);
if(db('ied')->insert($data)){
return $this->success('ok','lst');
}
else {
return $this->error('false');
}
return ;
}
$this->assign('cags',$cags);
return $this->fetch();
}
public function edit(){
$id=input('id');
$ieds=db('vw_ied')->where('id',$id)->find();
$cags=Db::query("select id,name from cag ");
if(request()->ispost()){
$data=[
'id'=>input('id'),
'name'=>input('name'),
'cacid'=>input('cacid'),
'manufacture'=>input('manufacture'),
'factoryint'=>input('factoryint'),
'manufacturedate'=>input('manufacturedate'),
'rundate'=>input('rundate'),
'location'=>input('location'),
'note'=>input('note'),
'diskfree'=>input('diskfree'),
'downip'=>input('downip'),
'upip'=>input('upip'),
];
$save=db('ied')->update($data);
if($save !== false){
$this->success('修改IED成功！','lst');
}else{
$this->error('修改IED失败！');
}
return;
}
$this->assign('cags',$cags);
$this->assign('ieds',$ieds);
return $this->fetch();
}
public function getcac(){
if (empty($_GET['cagid'])) return;
$cagid = $_GET['cagid'];
$data=Db::query("select id,name from cac where cagid='{$cagid}'");
echo json_encode($data);
}
public function del(){
$id=input('id');
if(db('ied')->delete(input('id'))){
$this->success('删除IED成功！','lst');
}else{
$this->error('删除IED失败！');
}
}
public function logout(){
session(null);
$this->success('退出成功！','Login/index');
}
}
?>