PlaceController.class.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class PlaceController extends ComController {
  5. public function _initialize() {
  6. parent::_initialize();
  7. $this->dbname ='deviceinfo';
  8. $this->regx_db='xj_';
  9. }
  10. public function index(){
  11. $Data=I();
  12. if(isset($Data['list'])){
  13. $UserVIew=M($this->dbname,$this->regx_db);
  14. $GetPage=$Data['pageCurrent'];//第几页
  15. $GetSize=$Data['pageSize'];//每页条数
  16. $Page=($GetPage-1)*$GetSize;
  17. $Map=array();
  18. if(!empty($Data['Placename'])){
  19. $Map['add_info']=array('like','%'.$Data['Placename'].'%');
  20. }
  21. if(!empty($Data['style'])){
  22. $Map['style']=$Data['style'];
  23. }
  24. if($Data['ndevice_status']!=''){
  25. $Map['ndevice_status']=$Data['ndevice_status'];
  26. }
  27. $permdata=$this->permdata();
  28. if (!empty($permdata))
  29. {
  30. $Map['insert_name']=$permdata;
  31. }
  32. $Count= $UserVIew->where($Map)->count();// 查询满足要求的总记录数
  33. $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();
  34. $Info = array(
  35. 'totalRow' => $Count,
  36. //'pageSize' => $count,//分页时不传
  37. 'list' => $List,
  38. );
  39. echo json_encode($Info);
  40. }
  41. else
  42. {
  43. $this->display();
  44. }
  45. }
  46. public function add(){
  47. if (IS_POST) {
  48. $Tab=M($this->dbname,$this->regx_db);
  49. $rules = array(
  50. array('add_info','','详细位置重复!',0,'unique'),
  51. );
  52. if (!$Tab->validate($rules)->create())
  53. {
  54. $this->mtReturn(300,$Tab->getError());
  55. }
  56. else
  57. {
  58. $Data=I();
  59. $Data['insert_data']=date('Y-m-d H:i:s');
  60. $Data['insert_name']=session('zt_username');
  61. $res = $Tab->add($Data);
  62. if($res)
  63. $this->mtReturn(200,'设备新增成功');
  64. else
  65. $this->mtReturn(300,'设备新增失败');
  66. }
  67. }
  68. else
  69. {
  70. $this->assign('action','/home/Place/add');
  71. $this->display();
  72. }
  73. }
  74. public function edit(){
  75. if(IS_POST)
  76. {
  77. $Data=I();
  78. $Tab=M($this->dbname,$this->regx_db);
  79. $res=$Tab->save($Data);
  80. if($res)
  81. $this->mtReturn(200,'编辑成功');
  82. else
  83. $this->mtReturn(300,'编辑失败');
  84. }
  85. else
  86. {
  87. $Data=I();
  88. $Tab=M($this->dbname,$this->regx_db);
  89. $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();
  90. $this->assign('ResData',$ResData[0]);
  91. $this->display();
  92. }
  93. }
  94. public function del(){
  95. $Model=M($this->dbname,$this->regx_db);
  96. $Data=I();
  97. $res=$Model->where('id='.$Data['id'])->delete();
  98. if($res)
  99. $this->mtReturn(200,'删除成功'.$Data['id']);
  100. else
  101. $this->mtReturn(300,'删除失败');
  102. }
  103. public function qrcode(){
  104. $Data=I();
  105. include('../../../ThinkPHP/Library/phpqrcode/phpqrcode.php');
  106. if (empty($Data['id'])) {
  107. $this->mtReturn(300,'ID空值!');
  108. }
  109. vendor("phpqrcode.phpqrcode");
  110. $value ='https://www.jd-ioe.com/jdxf/weixin.php/home/xunj/setform/id/'.$Data['id']; //二维码内容
  111. // $value ='https://www.jd-ioe.com/jdxf/wxapp.php/home/Login/visitors/act/visitors';
  112. $errorCorrectionLevel = 'L'; //容错级别
  113. $matrixPointSize = 9; //生成图片大小
  114. //$instance = new \QRcode();
  115. //生成二维码图片
  116. $Iamge=date('YmdHis').'-'.$Data['id'].'.png';
  117. $filename = '/var/www/html/jdxf/Public/QRcode/'.$Iamge;
  118. $margin=10;//表示二维码周围边框空白区域间距值;
  119. \QRcode::png($value,$filename , $errorCorrectionLevel, $matrixPointSize, $margin);
  120. $QR = imagecreatefromstring(file_get_contents($filename));
  121. if ($QR !== false)
  122. {
  123. $List=M('deviceinfo','xj_')->field('add_info')->where(array('id'=>$Data['id']))->select();
  124. $font = '/var/www/html/jdxf/Public/font/msyh.TTF';//字体
  125. $black = imagecolorallocate($QR, 0, 0, 0);//字体颜色 RGB
  126. list($bgWidth, $bgHight, $bgType) = getimagesize($filename);
  127. $fontSize = 22; //字体大小
  128. $circleSize = 90; //旋转角度
  129. $text=$List[0]['add_info'];
  130. $strl=mb_strlen($text, 'UTF-8')*28/2;
  131. $left =$bgWidth-50; //左边距
  132. $top = $bgHight-($bgHight/2-$strl); //顶边距
  133. imagefttext($QR, $fontSize, $circleSize, $left, $top, $black, $font,$text);
  134. imagepng($QR,$filename);
  135. $Tab=M($this->dbname,$this->regx_db);
  136. $Tab->url=$Iamge;
  137. $Res=$Tab->where(array('id'=>$Data['id']))->save();
  138. if($Res)
  139. $this->mtReturn(200,'生成二维码成功');
  140. else
  141. $this->mtReturn(300,'保存二维码失败');
  142. }
  143. else
  144. {
  145. $this->mtReturn(300,'生成二维码失败');
  146. }
  147. }
  148. public function downdata(){//导出Excel
  149. $Data=I();
  150. $UserVIew=M("v_user");
  151. $Map['status']=1;
  152. if(!empty($Data['username'])){
  153. $Map['username']=$Data['username'];
  154. }
  155. if(!empty($Data['truename'])){
  156. $Map['truename']=$Data['truename'];
  157. }
  158. if(!empty($Data['depname'])){
  159. $Map['depname']=$Data['depname'];
  160. }
  161. if(!empty($Data['posname'])){
  162. $Map['posname']=$Data['posname'];
  163. }
  164. $expTableData =$UserVIew->field("username,truename,extension,agentid,depname,posname,phone,email,address")->where($Map)->select();
  165. $expCellName=array('登录名','姓名','分机号','座席号','所在部门','担任角色','联系电话','电子邮箱','地址');
  166. $expTitle='用户信息';
  167. $this->exportExcel($expTitle,$expCellName,$expTableData);
  168. // echo json_encode($expTableData);
  169. }
  170. public function downe(){//下载文件 file
  171. $data=I();
  172. $path_parts = pathinfo($data['file']);
  173. $DirName=$path_parts['dirname'];//有路径显示路径,无路径显示.
  174. $file_name = $path_parts['basename'];//文件名,有后缀
  175. $Extension=$path_parts['extension'];//后缀名
  176. $filename='/var/www/html/jdxf/Public/QRcode/'.$file_name;
  177. if (!file_exists($filename)) {
  178. $this->mtReturn(300,'无文件,下载失败');
  179. }
  180. header('Content-type: application/x-'.$Extension);
  181. //下载显示的名字
  182. header('Content-Disposition: attachment; filename='.$file_name);
  183. $tr=readfile($filename);
  184. if($tr===false)
  185. $this->mtReturn(300,'下载错误');
  186. }
  187. public function prints(){
  188. $Data=I();
  189. $UserVIew=M($this->dbname,$this->regx_db);
  190. if(isset($Data['id']))
  191. {
  192. $res=$UserVIew->query("SELECT * from xj_deviceinfo WHERE id='".$Data['id']."'");
  193. $this->assign("list",$res);
  194. $this->display('prints2');
  195. }
  196. else
  197. {
  198. $Map=array();
  199. if(!empty($Data['Placename'])){
  200. $Map['add_info']=array('like','%'.$Data['Placename'].'%');
  201. }
  202. if(!empty($Data['style'])){
  203. $Map['style']=$Data['style'];
  204. }
  205. if($Data['ndevice_status']!=''){
  206. $Map['ndevice_status']=$Data['ndevice_status'];
  207. }
  208. // dump($_SESSION['zt_username']);
  209. if ($_SESSION['zt_username'] !='admin') {
  210. $Map['insert_name']=$_SESSION['zt_username'];
  211. }
  212. $res=$UserVIew->where($Map)->order('insert_data desc,add_info ASC')->select();
  213. $this->assign("list",$res);
  214. $this->display('prints2');
  215. }
  216. }
  217. }