where(array('openid'=> $_SESSION['useropenid']))->select(); $this->assign('ListData',$ListData); $this->display(); } //获取 权限 设备编号 public function getdevice(){ $device=M()->query("SELECT owner_code FROM ztxf.sp_owner WHERE company in(SELECT owner_code FROM ztxf.sp_owner_phone WHERE phone =(SELECT idphone FROM ztcrm.sp_customuser WHERE openid='".$_SESSION['useropenid']."') or phone =(SELECT 0+idphone as idphone FROM ztcrm.sp_customuser WHERE openid='".$_SESSION['useropenid']."'));"); $str=""; foreach ($device as $val) { $str.="'".$val['owner_code']."',"; } $newstr = substr($str,0,strlen($str)-1); return $newstr; } public function index2(){ $Data=I(); //and device_code='".$Data['code_id']."' if(!isset($Data['types'])){ $Data=$_SESSION['pielist']; } $openid=$_SESSION['useropenid']; $phone=M('customuser')->field('idphone')->where(array('openid'=>$openid))->select(); //dump($phone); //dump($_SESSION); $perm=$this->getdevice(); if (!empty($perm)) { switch ($Data['types']) { case '1': $ListData=M('')->query("SELECT id, device_code,TIME(time) as time1 FROM ztxf.sp_hj2017 WHERE clzt=0 and device_code in(".$perm.") ORDER BY time DESC"); break; case '2': $ListData=M('')->query("SELECT id, device_code,TIME(time) as time1 FROM ztxf.sp_sj2017 WHERE clzt=0 and device_code in(".$perm.") ORDER BY time DESC"); break; default: break; } }else{ $ListData=null; } $this->assign('types',$Data['types']); $this->assign('ListData',$ListData); $this->display(); } public function indexinfo(){ $Data=I(''); if ($Data['types']=='1') { $list=M()->query("SELECT y.id,y.device_code,y.time,y.`status`,y.address,ncmd,data1,data2,data3,data4,data5,clnr,clwb,owner_name,o.address as oaddress,dwtype,sim,unitinfo ,p.phone ,p.username FROM ztxf.`sp_hj2017` `y` LEFT JOIN ztxf.`sp_owner` `o` ON `y`.`device_code` = `o`.`owner_code` LEFT JOIN (SELECT owner_code ,username,phone from ztxf.sp_owner_phone GROUP BY owner_code) p ON p.owner_code=y.device_code where y.id='".$Data['id']."' ORDER BY `y`.`time` DESC"); } elseif ($Data['types']=='2') { $list=M()->query("SELECT y.id,y.device_code,y.time,y.`status`,y.address,ncmd,data1,data2,data3,data4,data5,clnr,clwb,owner_name,o.address as oaddress,dwtype,sim,unitinfo,p.phone ,p.username FROM ztxf.`sp_sj2017` `y` LEFT JOIN ztxf.`sp_owner` `o` ON `y`.`device_code` = `o`.`owner_code` LEFT JOIN (SELECT owner_code ,username,phone from ztxf.sp_owner_phone GROUP BY owner_code) p ON p.owner_code=y.device_code where y.id='".$Data['id']."' ORDER BY `y`.`time` DESC"); } elseif ($Data['types']=='3') { $list=M()->query("SELECT y.id,y.device_code,y.time,y.`status`,y.address,ncmd,data1,data2,data3,data4,data5,clnr,clwb,owner_name,o.address as oaddress,dwtype,sim,unitinfo,p.phone ,p.username FROM ztxf.`sp_yj2017` `y` LEFT JOIN ztxf.`sp_owner` `o` ON `y`.`device_code` = `o`.`owner_code` LEFT JOIN (SELECT owner_code ,username,phone from ztxf.sp_owner_phone GROUP BY owner_code) p ON p.owner_code=y.device_code where y.id='".$Data['id']."' ORDER BY `y`.`time` DESC"); }else{ $list=array(array()); } $video=M()->query("SELECT h5 FROM ztxf.sp_owner_company WHERE owner_id =(SELECT company FROM ztxf.sp_owner o WHERE o.owner_code='".$list[0]['device_code']."')"); $this->assign('html5',$video[0]['h5']); $this->assign('types',$Data['types']); $this->assign('list',$list[0]); //dump($Data); //dump($list); $this->display('index2info'); } public function savefire(){ $Data=I(); if(empty($Data['code'])){ $this->assign('ResData', '设备编号为空,保存失败,请重试!'); $this->display('Public/error'); return; } if ($Data['types']=='1') { $res=M()->query("select id from ztxf.sp_hj2017 WHERE clzt=0 and id='".$Data['uid']."'"); } elseif ($Data['types']=='2') { $res=M()->query("select id from ztxf.sp_sj2017 WHERE clzt=0 and id='".$Data['uid']."'"); } elseif ($Data['types']=='3') { $res=M()->query("select id from ztxf.sp_yj2017 WHERE clzt=0 and id='".$Data['uid']."'"); }else{ $res=null; } if(count($res)<1){ $this->assign('ResData', '已被其他人保存!'); $this->display('Public/success'); return; } //获取临时文件路径rand(1000,9999) $BasefName=''; $tmpFilePath = $_FILES['video']['tmp_name']; //确保我们有一个文件路径 if ($tmpFilePath != ""){ //设置我们的新文件路径 $FileCode=date('YmdHis').rand(1000,9999); $FileName=$_FILES['video']['name']; $FileType=strtolower(substr(strrchr($FileName,'.'),1)); $BasefName=$FileCode.'.'.$FileType; $newFilePath = "/var/www/html/ztxf/videofile/".$BasefName; //将文件上传到临时目录中 if(move_uploaded_file($tmpFilePath, $newFilePath)) { } } if ($Data['types']=='1') { $res=M()->execute("UPDATE ztxf.sp_hj2017 y SET y.clwb='".$Data['wb']."',y.video='".$BasefName."' ,y.clnr='".$Data['nr']."',y.clsj=NOW(),y.clzt=1,clr='".$_SESSION['useropenid']."' WHERE device_code='".$Data['code']."'"); } elseif ($Data['types']=='2') { $res=M()->execute("UPDATE ztxf.sp_sj2017 y SET y.clwb='".$Data['wb']."',y.video='".$BasefName."' ,y.clnr='".$Data['nr']."',y.clsj=NOW(),y.clzt=1,clr='".$_SESSION['useropenid']."' WHERE device_code='".$Data['code']."'"); } elseif ($Data['types']=='3') { $res=M()->execute("UPDATE ztxf.sp_yj2017 y SET y.clwb='".$Data['wb']."',y.video='".$BasefName."' ,y.clnr='".$Data['nr']."',y.clsj=NOW(),y.clzt=1,clr='".$_SESSION['useropenid']."' WHERE device_code='".$Data['code']."'"); }else{ //$ListData=array(array()); } M()->execute("UPDATE ztxf.sp_devices_status SET devicestatus=0 WHERE deviceid='".$Data['code']."'"); // $errno = $errdesc = NULL; // $fp = fsockopen('119.23.108.157', '8089', $errno, $errdesc) or die("Connection false"); // //socket_set_blocking($fp,true);//非阻塞模式 // if ($fp) { // fputs($fp, '{"device_code":"'.$Data['code'].'"}'); // } //dump($Data); $this->assign('ResData', '保存成功!'); $this->display('Public/success'); //dump($_SESSION); } public function edit(){ $Data=I(''); if(IS_POST){ unset($Data['openid']); $Data['statu']=3; $Res=M('customuser')->save($Data); if($Res!==false) { //$Text='完善资料成功,请等待客服人员联系!'; $this->redirect('Pielist/index'); } } else{ $ResData=M('v_customuser')->where(array('id' => $Data['id']))->select(); $this->assign('ResData',$ResData[0]); $this->assign('action','/Home/Pielist/edit'); $this->assign('Pielist','Pielist'); $this->display('Index/edit'); } } }