<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Paramindexinfo extends Common
{
    public function index(){

        $d = isset($_GET['id']) ? $_GET['id'] : 1;
	    $this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid,phase from rptparamindex ");
//dump($menu);die;
        $this->assign('menu',$menu);

        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");

//dump($date);
        $this->assign('date',$date);

        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h

//dump($t);
        if(request()->isPost()){
		 //$data=input('post.');
            //dump($data);die;
		Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

		$para1 = $data['para1'];
		$para2 = $data['para2'];
		$para3 = $data['para3'];
		if($para1){
			Db::table('rptparamindex')->where('paramindex','like',$para1.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'A']);
		}
		if($para2){
			Db::table('rptparamindex')->where('paramindex','like',$para2.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'B']);
			    }
		if($para3){
		 	Db::table('rptparamindex')->where('paramindex','like',$para3.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'C']);

		}
            foreach ($data as $k=>$v){

                 if ($k!='para1' && $k!='para2' && $k!='para3'){
                       if(substr($k,-1)==1){
					$where=$para1.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
                       if(substr($k,-1)==2){
					$where=$para2.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
                       if(substr($k,-1)==3){
					$where=$para3.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
					//$where=$para.'$'.$v;
					// Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					//$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

			}
                }

 //echo substr($k,-1);die;
// dump(count($res));count($arr);
				if(count($res)){
					$this->success('操作成功！');

				}else{
					 $this->error('操作失败！');
				}

			}

        return $this->fetch();
    }


    public function epa_h() // 普通油色谱
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 5;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
			Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){

                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
 
       public function epa_h_1() // 光声光谱
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 38;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
			Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){

                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
          public function epa_h_2() // 油中气设备
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 39;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
			Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){

                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
    public function eia_h()
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 6;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

           // $da=$data['da'];
            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
    public function etp_h()
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 7;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

           // $da=$data['da'];
            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
    public function sf6_h()
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 8;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid,phase from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para1 = $data['para1'];
		$para2 = $data['para2'];
		$para3 = $data['para3'];

		if($para1){
			Db::table('rptparamindex')->where('paramindex','like',$para1.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'A']);
		}
		if($para2){
			Db::table('rptparamindex')->where('paramindex','like',$para2.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'B']);
			    }
		if($para3){
		 	Db::table('rptparamindex')->where('paramindex','like',$para3.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'C']);

		}


            //dump($data);
             foreach ($data as $k=>$v){

                 if ($k!='para1' && $k!='para2' && $k!='para3'){
                       if(substr($k,-1)==1){
					$where=$para1.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
                       if(substr($k,-1)==2){
					$where=$para2.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
                       if(substr($k,-1)==3){
					$where=$para3.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
					//$where=$para.'$'.$v;
					// Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					//$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

			}
                }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
   // SF6环境监测
   public function sf6env_h()
   {
        $d = isset($_GET['id']) ? $_GET['id'] : 61;
        $this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid,phase from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_sf6env_h
        if(request()->isPost()){
             Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para1 = $data['para1'];
		$para2 = $data['para2'];
		$para3 = $data['para3'];
		if($para1){
                                    Db::table('rptparamindex')->where('paramindex','like',$para1.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'A']);
		}
		if($para2){
                                    Db::table('rptparamindex')->where('paramindex','like',$para2.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'B']);
		}
		if($para3){
                                    Db::table('rptparamindex')->where('paramindex','like',$para3.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'C']);
		}

            //dump($data);
             foreach ($data as $k=>$v){

                 if ($k!='para1' && $k!='para2' && $k!='para3'){
                       if(substr($k,-1)==1){
                                    $where=$para1.'$'.$v;
                                    $res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
                                //   $res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => substr($k,0, strlen($k) - 1)]);
                       }
                       if(substr($k,-1)==2){
                                    $where=$para2.'$'.$v;
                                    $res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
                       }
                       if(substr($k,-1)==3){
                                    $where=$para3.'$'.$v;
                                    $res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
                        }
                        //$where=$para.'$'.$v;
                        // Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
                        //$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
                }
            }
            if(count($res)){
                    $this->success('操作成功！');

            }else{
                     $this->error('操作失败！');
            }
        }
        return $this->fetch();
   }
   
public function eia()
   {


	  $d = isset($_GET['id']) ? $_GET['id'] : 13;
	  $this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid,phase from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para1 = $data['para1'];
		$para2 = $data['para2'];
		$para3 = $data['para3'];
		if($para1){
			Db::table('rptparamindex')->where('paramindex','like',$para1.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'A']);
		}
		if($para2){
			Db::table('rptparamindex')->where('paramindex','like',$para2.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'B']);
			    }
		if($para3){
		 	Db::table('rptparamindex')->where('paramindex','like',$para3.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d,'phase'=>'C']);

		}
            //dump($data);
             foreach ($data as $k=>$v){

                 if ($k!='para1' && $k!='para2' && $k!='para3'){
                       if(substr($k,-1)==1){
					$where=$para1.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
                       if(substr($k,-1)==2){
					$where=$para2.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
                       if(substr($k,-1)==3){
					$where=$para3.'$'.$v;
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);
				}
					//$where=$para.'$'.$v;
					// Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					//$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

			}
                }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
    public function pd_h()
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 10;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
    public function scur_h()
    {
       
        
		$d = isset($_GET['id']) ? $_GET['id'] : 20;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();
    }
    public function jdw_h()
    {
       
        
		$d = isset($_GET['id']) ? $_GET['id'] : 40;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();
    }
    public function microclimate_h()
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 16;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_moa_h
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
   public function dlg_h()
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 21;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d"); //查询出来已绑定的参数
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//data_dlg_h
        if(request()->isPost()){
            Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>'','eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){
                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k,'tablename'=>$t[0]['tablename']]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
    public function etp_h_gxcw() // 光纖測溫
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 59;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//
        if(request()->isPost()){
			Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){

                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
   public function etp_h_rzcw() // raozu測溫
   {


		$d = isset($_GET['id']) ? $_GET['id'] : 60;
		$this->assign('d',$d);
        $menu=Db::query("select distinct substring_index(paramindex,'$',1) paramindex,eqmid from rptparamindex ");
        $this->assign('menu',$menu);
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where eqmid=$d");
        $this->assign('date',$date);
        $t=Db::query("SELECT tablename FROM modevtype WHERE id=(SELECT modevtid FROM modev WHERE id =$d)");//
        if(request()->isPost()){
			Db::table('rptparamindex')->where('eqmid',$d)->update(['colname' => '','tablename'=>'','eqmid'=>'','phase'=>'']);
            $data=input('post.');

            $para=$data['para'];
			Db::table('rptparamindex')->where('paramindex','like',$para.'$%')->update(['colname' => '','tablename'=>$t[0]['tablename'],'eqmid'=>$d]);

            //dump($data);
            foreach ($data as $k=>$v){

                if ($k!='para'){
					$where=$para.'$'.$v;
                    //dump($para.'$'.$v);die;
                    //Db::table('rptparamindex')->where('colname',$k)->where('eqmid',$d)->update(['colname' => '']);
					$res[] =  Db::table('rptparamindex')->where('paramindex', $where)->update(['colname' => $k]);

				}
            }
			if(count($res)){
				$this->success('操作成功！');

			}else{
				 $this->error('操作失败！');
			}
        }

        return $this->fetch();

   }
   
    public function ajax1()
    {
		// session('para', $_POST['para']);
        $para=$_POST['para'];
        //$date = Db::query("select * from rptparamindex WHERE paramindex LIKE '$para%'");
        $date = Db::query("select objid,SUBSTRING(paramindex,locate('$',paramindex)+1) paramindex,eqmid,tablename,colname from rptparamindex where paramindex like '$para$%'");
          //dump( $date);die;
	  echo json_encode($date);

      // die($date) ;
    }







}
