dbname ='deviceinfo'; $this->regx_db='xj_'; } public function index(){ $Data=I(); if(isset($Data['list'])){ $UserVIew=M($this->dbname,$this->regx_db); $GetPage=$Data['pageCurrent'];//第几页 $GetSize=$Data['pageSize'];//每页条数 $Page=($GetPage-1)*$GetSize; $Map=array(); if(!empty($Data['Placename'])){ $Map['add_info']=array('like','%'.$Data['Placename'].'%'); } if(!empty($Data['style'])){ $Map['style']=$Data['style']; } if($Data['ndevice_status']!=''){ $Map['ndevice_status']=$Data['ndevice_status']; } $permdata=$this->permdata(); if (!empty($permdata)) { $Map['insert_name']=$permdata; } $Count= $UserVIew->where($Map)->count();// 查询满足要求的总记录数 $List = $UserVIew->field("case style WHEN '1' THEN '风' WHEN '2' THEN '电' WHEN '3' THEN '消火栓' WHEN '4' THEN '报警主机' END as style,add_info,insert_data,insert_name,case ndevice_status WHEN '0' THEN '正常' WHEN '1' THEN '损坏' WHEN '2' THEN '其他' END as ndevice_status,dt_update,update_user,id,url,lc")->where($Map)->order('insert_data desc,add_info ASC')->limit($Page,$GetSize)->select(); $Info = array( 'totalRow' => $Count, //'pageSize' => $count,//分页时不传 'list' => $List, ); echo json_encode($Info); } else { $this->display(); } } public function add(){ if (IS_POST) { $Tab=M($this->dbname,$this->regx_db); $rules = array( array('add_info','','详细位置重复!',0,'unique'), ); if (!$Tab->validate($rules)->create()) { $this->mtReturn(300,$Tab->getError()); } else { $Data=I(); $Data['insert_data']=date('Y-m-d H:i:s'); $Data['insert_name']=session('zt_username'); $res = $Tab->add($Data); if($res) $this->mtReturn(200,'设备新增成功'); else $this->mtReturn(300,'设备新增失败'); } } else { $this->assign('action','/home/Place/add'); $this->display(); } } public function edit(){ if(IS_POST) { $Data=I(); $Tab=M($this->dbname,$this->regx_db); $res=$Tab->save($Data); if($res) $this->mtReturn(200,'编辑成功'); else $this->mtReturn(300,'编辑失败'); } else { $Data=I(); $Tab=M($this->dbname,$this->regx_db); $ResData=$Tab->field("url,id,case style WHEN '1' THEN '风' WHEN '2' THEN '电' WHEN '3' THEN '消火栓' WHEN '4' THEN '报警主机' END as style,add_info,lc")->where(array('id'=>$Data['id']))->select(); $this->assign('ResData',$ResData[0]); $this->display(); } } public function del(){ $Model=M($this->dbname,$this->regx_db); $Data=I(); $res=$Model->where('id='.$Data['id'])->delete(); if($res) $this->mtReturn(200,'删除成功'.$Data['id']); else $this->mtReturn(300,'删除失败'); } public function qrcode(){ $Data=I(); include('../../../ThinkPHP/Library/phpqrcode/phpqrcode.php'); if (empty($Data['id'])) { $this->mtReturn(300,'ID空值!'); } vendor("phpqrcode.phpqrcode"); $value ='https://www.jd-ioe.com/jdxf/weixin.php/home/xunj/setform/id/'.$Data['id']; //二维码内容 // $value ='https://www.jd-ioe.com/jdxf/wxapp.php/home/Login/visitors/act/visitors'; $errorCorrectionLevel = 'L'; //容错级别 $matrixPointSize = 9; //生成图片大小 //$instance = new \QRcode(); //生成二维码图片 $Iamge=date('YmdHis').'-'.$Data['id'].'.png'; $filename = '/var/www/html/jdxf/Public/QRcode/'.$Iamge; $margin=10;//表示二维码周围边框空白区域间距值; \QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, $margin); $QR = imagecreatefromstring(file_get_contents($filename)); if ($QR !== false) { $List=M('deviceinfo','xj_')->field('add_info')->where(array('id'=>$Data['id']))->select(); $font = '/var/www/html/jdxf/Public/font/msyh.TTF';//字体 $black = imagecolorallocate($QR, 0, 0, 0);//字体颜色 RGB list($bgWidth, $bgHight, $bgType) = getimagesize($filename); $fontSize = 22; //字体大小 $circleSize = 90; //旋转角度 $text=$List[0]['add_info']; $strl=mb_strlen($text, 'UTF-8')*28/2; $left =$bgWidth-50; //左边距 $top = $bgHight-($bgHight/2-$strl); //顶边距 imagefttext($QR, $fontSize, $circleSize, $left, $top, $black, $font,$text); imagepng($QR,$filename); $Tab=M($this->dbname,$this->regx_db); $Tab->url=$Iamge; $Res=$Tab->where(array('id'=>$Data['id']))->save(); if($Res) $this->mtReturn(200,'生成二维码成功'); else $this->mtReturn(300,'保存二维码失败'); } else { $this->mtReturn(300,'生成二维码失败'); } } public function downdata(){//导出Excel $Data=I(); $UserVIew=M("v_user"); $Map['status']=1; if(!empty($Data['username'])){ $Map['username']=$Data['username']; } if(!empty($Data['truename'])){ $Map['truename']=$Data['truename']; } if(!empty($Data['depname'])){ $Map['depname']=$Data['depname']; } if(!empty($Data['posname'])){ $Map['posname']=$Data['posname']; } $expTableData =$UserVIew->field("username,truename,extension,agentid,depname,posname,phone,email,address")->where($Map)->select(); $expCellName=array('登录名','姓名','分机号','座席号','所在部门','担任角色','联系电话','电子邮箱','地址'); $expTitle='用户信息'; $this->exportExcel($expTitle,$expCellName,$expTableData); // echo json_encode($expTableData); } public function downe(){//下载文件 file $data=I(); $path_parts = pathinfo($data['file']); $DirName=$path_parts['dirname'];//有路径显示路径,无路径显示. $file_name = $path_parts['basename'];//文件名,有后缀 $Extension=$path_parts['extension'];//后缀名 $filename='/var/www/html/jdxf/Public/QRcode/'.$file_name; if (!file_exists($filename)) { $this->mtReturn(300,'无文件,下载失败'); } header('Content-type: application/x-'.$Extension); //下载显示的名字 header('Content-Disposition: attachment; filename='.$file_name); $tr=readfile($filename); if($tr===false) $this->mtReturn(300,'下载错误'); } public function prints(){ $Data=I(); $UserVIew=M($this->dbname,$this->regx_db); if(isset($Data['id'])) { $res=$UserVIew->query("SELECT * from xj_deviceinfo WHERE id='".$Data['id']."'"); $this->assign("list",$res); $this->display('prints2'); } else { $Map=array(); if(!empty($Data['Placename'])){ $Map['add_info']=array('like','%'.$Data['Placename'].'%'); } if(!empty($Data['style'])){ $Map['style']=$Data['style']; } if($Data['ndevice_status']!=''){ $Map['ndevice_status']=$Data['ndevice_status']; } // dump($_SESSION['zt_username']); if ($_SESSION['zt_username'] !='admin') { $Map['insert_name']=$_SESSION['zt_username']; } $res=$UserVIew->where($Map)->order('insert_data desc,add_info ASC')->select(); $this->assign("list",$res); $this->display('prints2'); } } }