<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;

class Msb extends Common
{
    public function lst()
    {
        $zsbid= input('zsbid');
        $list=Db::query("select * from vw_msb where zsbid= {$zsbid}");
        $this->assign('list',$list);
        return $this->fetch();
    }
    public function add()
    {
        $zsbid= input('zsbid');
//        $mainID = input('mainID');
        $ieds=Db::query("select id,name from vw_ied where bdzid =(select bdzid from vw_zsb where id ={$zsbid}) ");
        $lxs=Db::query("select id,mc from modevtype ");
//        $msbType=Db::query("select id,main_id,main_name from mainType"); //2021/10/13 主设备下拉
//        $ssbType=Db::query("select second_id,second_name from secondType A LEFT JOIN mainType B on A.main_id = B.id "); //2021/10/13 设备小类下拉
        if (request()->isPost()){
            $data = input('post.');
            $data['zsbid']=$zsbid;

            if(db('modev')->insert($data)){
                return $this->success('添加监测设备信息成功！',url('lst',array('zsbid'=>input('zsbid'))));
            }
            else {
                return $this->error('添加监测设备信息失败！');
            }
            return ;
        }


        $this->assign('ieds',$ieds);
        $this->assign('lxs',$lxs);
//        $this->assign('msbType',$msbType);//2021/10/13 主设备下拉
//        $this->assign('ssbType',$ssbType);//2021/10/13 设备小类下拉
        return $this->fetch();
    }
    public function edit(){
        $zsbid= input('zsbid');
        $id=input('id');
        $ieds=Db::query("select id,name from vw_ied where bdzid =(select bdzid from vw_zsb where id ={$zsbid}) ");
        $lxs=Db::query("select id,mc from modevtype ");
//        $msbType=Db::query("select id,main_id,main_name from mainType"); //2021/10/13 主设备下拉
//        $ssbType=Db::query("select second_id,second_name from secondType A LEFT JOIN mainType B on A.main_id = B.id "); //2021/10/13 设备小类下拉
        $sbs=db('modev')->where('id',$id)->find();
        if(request()->ispost()){

            $data = input('post.');
            $data['zsbid']=$zsbid;
		/*if($data["modevtid"]!=9){
			$data["ip"]       = '';
			$data["username"] = '';
			$data["pwd"] = '';
			$data["port"] = ''; 
			$data["nPresetId"] = 0;
			$data["nRuleId"] = 0;
			$data["nMeterType"] = 0;
		}
		if($data["modevtid"]!=12){
			$data["nPresetId"] = 0;
			$data["nRuleId"] = 0;
			$data["nMeterType"] = 0;
		}*/
            $save=db('modev')->where('id',$id)->update($data);
            if($save !== false){
                return $this->success('修改监测设备信息成功！',url('lst',array('zsbid'=>input('zsbid'))));
            }else{
                $this->error('修改监测设备信息失败！');
            }
            return;
        }
        $this->assign('sbs',$sbs);
        $this->assign('ieds',$ieds);
        $this->assign('lxs',$lxs);
//        $this->assign('msbType',$msbType);//2021/10/13 主设备下拉
//        $this->assign('ssbType',$ssbType);//2021/10/13 设备小类下拉
        return $this->fetch();
    }
	public function del(){
        $id=input('id');
        if(db('modev')->delete(input('id'))){
            $this->success('删除监测设备信息成功！',url('lst',array('zsbid'=>input('zsbid'))));
        }else{
            $this->error('删除监测设备信息失败！');
        }

    }
	public function eaiflist()
    {
        $id= input('id');
        $list=Db::query("select * from modev_eaif where eqmid= {$id}");
        $this->assign('list',$list);
        return $this->fetch();
    }
	
	public function eaifadd(){
        $id=input('id');
		$sbs=Db::query("select * from modev_eaif where id= '{$id}'");
        if(request()->ispost()){
			
            $data = input('post.');
			$data['eqmid'] = input('eqmid');
            $save=db('modev_eaif')->insert($data);
            if($save !== false){
                return $this->success('修改监测设备信息成功！',url('eaiflist',array('id'=>input('eqmid'))));
            }else{
                $this->error('修改监测设备信息失败！');
            }
            return;
        }
        $this->assign('sbs',$sbs);
		var_dump($sbs);
        return $this->fetch();
    }
	public function eaif(){
        $id=input('id');
		$sbs=db('modev_eaif')->where('id',$id)->find();
        if(request()->ispost()){
            $data = input('post.');
            $save=db('modev_eaif')->where('id',$id)->update($data);
            if($save !== false){
                return $this->success('修改监测设备信息成功！',url('eaiflist',array('id'=>input('eqmid'))));
            }else{
                $this->error('修改监测设备信息失败！');
            }
            return;
        }
        $this->assign('sbs',$sbs);
        return $this->fetch();
    }
    public function eaifdel(){
        $id=input('id');
        if(db('modev_eaif')->delete(input('id'))){
            $this->success('删除监测设备信息成功！',url('lst',array('zsbid'=>input('zsbid'))));
        }else{
            $this->error('删除监测设备信息失败！');
        }

    }


}

























































