IndexController.class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. include '/var/www/html/jdxf/Public/vendor/WxJDK/JSSDK5.php';
  5. class IndexController extends ComController
  6. {
  7. public $owner_name;
  8. //微信 app 首页
  9. public function index()
  10. {
  11. $company = $_GET['companyid'];
  12. $phone = $_GET['phone'];
  13. if (!empty($_SESSION['idphone'])) {
  14. $phone = $_SESSION['idphone'];
  15. }
  16. if (!empty($_SESSION['phone'])) {
  17. $phone = $_SESSION['phone'];
  18. }
  19. $arr = M()->query("SELECT owner_id,owner_name FROM sp_v_jd_wxindex WHERE phone='" . $phone . "'GROUP BY owner_id");
  20. $this->assign('company', $arr);
  21. $comp = '';
  22. if (!empty($company)) {
  23. $comp = $this->getdevice($company);
  24. $device_code_list = $comp;
  25. if (empty($comp)) {
  26. $this->assign('title', '无数据');
  27. $this->assign('hj0', 0);
  28. $this->assign('hj1', 0);
  29. $this->assign('hjall', 0);
  30. $this->assign('gz0', 0);
  31. $this->assign('gz1', 0);
  32. $this->assign('gzall', 0);
  33. $this->assign('sj', 0);
  34. $this->assign('rtu', 0);
  35. $this->assign('cns', 0);
  36. // 第二饼图
  37. $this->assign('zx', 0);
  38. $this->assign('lx', 0);
  39. $this->assign('gj', 0);
  40. // $this->display();
  41. $this->display('Index2/index');
  42. exit;
  43. } else {
  44. $this->assign('title', $this->owner_name);
  45. }
  46. } else {
  47. if (count($arr) > 0) {
  48. $company = $arr[0]['owner_id'];
  49. $comp = $this->getdevice($arr[0]['owner_id']);
  50. $device_code_list = $comp;
  51. $this->assign('title', $this->owner_name);
  52. } else {
  53. $this->assign('title', '无数据');
  54. $this->assign('hj0', 0);
  55. $this->assign('hj1', 0);
  56. $this->assign('hjall', 0);
  57. $this->assign('gz0', 0);
  58. $this->assign('gz1', 0);
  59. $this->assign('gzall', 0);
  60. $this->assign('sj', 0);
  61. $this->assign('rtu', 0);
  62. $this->assign('cns', 0);
  63. // 第二饼图
  64. $this->assign('zx', 0);
  65. $this->assign('lx', 0);
  66. $this->assign('gj', 0);
  67. // $this->display();
  68. // $this->display('Index2/index');
  69. $this->display('Public/index-1');
  70. exit;
  71. }
  72. }
  73. $this->assign('companys', $company);
  74. $this->assign('phone', $_SESSION["idphone"]);
  75. $deviceid = "and deviceid in($comp)";
  76. $comp = "and device_code in($comp)";
  77. $res = M()->procedure("
  78. SELECT COUNT(id) as gz1 FROM sp_hj2017 WHERE clzt='1'$comp AND data2 = '故障';
  79. SELECT COUNT(id) as gzall FROM sp_hj2017 WHERE data2 = '故障' $comp;
  80. SELECT COUNT(id) as cn FROM sp_owner WHERE company=$company;
  81. SELECT COUNT(id) as zx FROM sp_devices_status WHERE true_status='0' $deviceid;
  82. SELECT COUNT(id) as lx FROM sp_devices_status WHERE true_status='75' $deviceid;
  83. SELECT COUNT(id) as gj FROM sp_devices_status WHERE devicestatus !='0' $deviceid;
  84. ");
  85. $where2['company_code'] = $company;
  86. $data_statistics = M('company_sync')->where($where2)->find();
  87. //火报警总数量
  88. $hj_total = $data_statistics['device_01_alarm']+$data_statistics['device_01_out'];
  89. //水报警总数
  90. $sj_total = $data_statistics['device_02_alarm'] + $data_statistics['device_00_alarm']+$data_statistics['device_00_out']+$data_statistics['device_02_out'];
  91. //RTU报警总数
  92. $rtu_total = $data_statistics['device_06_alarm']+$data_statistics['device_06_out'];
  93. // 电气火灾报警总数
  94. $efire_total = $data_statistics['device_07_alarm']+$data_statistics['device_07_out'];
  95. //视频监测总数
  96. $video_total=$data_statistics['device_16_alarm']+$data_statistics['device_16_out'];
  97. if (!empty($device_code_list)) {
  98. $array = explode(',', $device_code_list);
  99. $where['device_code'] = array('in', $array);
  100. $elevator_total = M('lifter2017')->where($where)->count();
  101. } else {
  102. $elevator_total = 0;
  103. }
  104. //该单位总共报警总数
  105. if ($company == 10215) {
  106. //RTU报警总数
  107. $ResData1 = M()->query("select count(*) as sl from sp_v_rtu2017_2 where company='10215' AND wtype not LIKE '%离线%'");
  108. $ResData2 = M()->query("select count(*) as sl from sp_v_rtu2017_2 where company='10215' AND wtype LIKE '%离线%' AND time < '2021-03-10'");
  109. if (empty($ResData1)) {
  110. $ResData1[0]['sl'] = 0;
  111. }
  112. if (empty($ResData2)) {
  113. $ResData2[0]['sl'] = 0;
  114. }
  115. $ResData = $ResData1[0]['sl'] + $ResData2[0]['sl'];
  116. $commm = $hj_total + $sj_total + $ResData + $efire_total + $elevator_total + $video_total;
  117. } else {
  118. $commm = $hj_total + $sj_total + $rtu_total + $efire_total + $elevator_total + $video_total;
  119. }
  120. //该单位总共报警总数
  121. $this->assign('commm', $commm);
  122. //消防支队人工督察单
  123. $rgdcd = ytapi_query("select count(*) from person_data where clzt='0' and company_code='" . $company . "'");
  124. $dzdcd = ytapi_query("select count(*) from jingan_analysis_data where status=0 and clzt='0' and content != '设备离线' and company_code='" . $company . "'");
  125. $xfzdrydcd = $rgdcd[0]['count(*)'] + $dzdcd[0]['count(*)'];
  126. $this->assign('xfzdrydcd', $xfzdrydcd);
  127. if ($company == 10209 || $company == 10198 || $company == 10195 || $company == 10078 || $company == 10069 || $company == 10083 || $company == 10064 || $company == 10067 || $company == 10215 ||
  128. $company == 10216 || $company == 10214 || $company == 10212 || $company == 10206 || $company == 10114 || $company == 10077 || $company == 10122 || $company == 10074 || $company == 10076 ||
  129. $company == 10079 || $company == 10066 || $company == 10065 || $company == 10070 || $company == 10063 || $company == 10113 || $company == 10012 || $company == 10229 || $company == 10219) {
  130. $pd = 1;
  131. } else {
  132. $pd = 0;
  133. }
  134. $this->assign('pd', $pd);
  135. // 火警未处理
  136. $hj88 = $data_statistics['device_01_alarm']-$data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out']-$data_statistics['device_01_out_confirm'];
  137. //水警未处理
  138. $sj88 = $data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
  139. +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
  140. if ($hj88 > 99) {
  141. $hj_x = '99+';
  142. } else {
  143. $hj_x = $hj88;
  144. }
  145. if ($sj88 > 99) {
  146. $sj_x = '99+';
  147. } else {
  148. $sj_x = $sj88;
  149. }
  150. // 水
  151. $this->assign('sj', $sj88);
  152. $this->assign('sj_x', $sj_x);
  153. //RTU
  154. if ($company == 10215) {
  155. $ResData1 = M()->query("select count(*) as sl from sp_v_rtu2017_2 where company='10215' AND wtype not LIKE '%离线%' and clzt=0");
  156. $ResData2 = M()->query("select count(*) as sl from sp_v_rtu2017_2 where company='10215' AND wtype LIKE '%离线%' AND time < '2021-03-10' and clzt=0");
  157. if (empty($ResData1)) {
  158. $ResData1[0]['sl'] = 0;
  159. }
  160. if (empty($ResData2)) {
  161. $ResData2[0]['sl'] = 0;
  162. }
  163. $rtu_wcl = $ResData1[0]['sl'] + $ResData2[0]['sl'];
  164. } else {
  165. $rtu_wcl =$data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
  166. }
  167. if ($rtu_wcl > 99) {
  168. $rtu_x = '99+';
  169. } else {
  170. $rtu_x = $rtu_wcl;
  171. }
  172. $this->assign('rtu', $rtu_wcl);
  173. $this->assign('rtu_x', $rtu_x);
  174. // 电气火灾未处理
  175. $efire = $data_statistics['device_07_alarm'] - $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out']-$data_statistics['device_07_out_confirm'];
  176. //视频监测未处理
  177. $video = $data_statistics['device_16_alarm'] - $data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out']-$data_statistics['device_16_out_confirm'];
  178. if (!empty($device_code_list)) {
  179. $array1 = explode(',', $device_code_list);
  180. $where1['device_code'] = array('in', $array1);
  181. $where1['clzt'] = '0';
  182. //电梯
  183. $elevator = M('lifter2017')->where($where1)->count();
  184. //门磁
  185. $mc = M('door2020')->where($where1)->count();
  186. //可燃气体
  187. $combustible_gas = M('gas2020')->where($where1)->count();
  188. }else{
  189. $elevator = 0;
  190. $mc = 0;
  191. $combustible_gas = 0;
  192. }
  193. if ($efire > 99) {
  194. $efire_x = '99+';
  195. } else {
  196. $efire_x = $efire;
  197. }
  198. if ($video > 99) {
  199. $video_x = '99+';
  200. } else {
  201. $video_x = $video;
  202. }
  203. if ($elevator > 99) {
  204. $elevator_x = '99+';
  205. } else {
  206. $elevator_x = $elevator;
  207. }
  208. if ($mc > 99) {
  209. $mc_x = '99+';
  210. } else {
  211. $mc_x = $mc;
  212. }
  213. if ($combustible_gas > 99) {
  214. $combustible_gas_x = '99+';
  215. } else {
  216. $combustible_gas_x = $combustible_gas;
  217. }
  218. $this->assign('efire_x', $efire_x);
  219. $this->assign('hj_x', $hj_x);
  220. $this->assign('video_x', $video_x);
  221. $this->assign('elevator_x', $elevator_x);
  222. $this->assign('mc_x', $mc_x);
  223. $this->assign('combustible_gas_x', $combustible_gas_x);
  224. $this->assign('hjall', $data_statistics['device_01_alarm']);
  225. $this->assign('gz0', $res[1][0]['gzall']-$res[0][0]['gz1']);
  226. $this->assign('gz1', $res[0][0]['gz1']);
  227. $this->assign('gzall', $res[1][0]['gzall']);
  228. $this->assign('cns', $res[2][0]['cn']);
  229. // 第二饼图
  230. $this->assign('zx', $res[3][0]['zx']);
  231. $this->assign('lx', $res[4][0]['lx']);
  232. $this->assign('gj', $res[5][0]['gj']);
  233. $rtu88 = $data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
  234. $qt = $rtu88+ $efire;
  235. $this->assign('qt', $qt);
  236. //综合消防总数
  237. $zhxfzs = $hj88 + $sj88 + $rtu88 + $efire + $video + $elevator + $mc;
  238. if ($zhxfzs > 99) {
  239. $zhxfzs = '99+';
  240. }
  241. $this->assign('zhxfzs', $zhxfzs);
  242. $Data = I();
  243. $return_key = $Data['return_key'];
  244. if (empty($return_key)) {
  245. $return_key = 0;
  246. }
  247. $this->assign('return_key', $return_key);
  248. $appid = 'wx41e478e592f9e04a';
  249. # 公众号获取
  250. $appSecret = 'fc165de4aa5cd24b628baa30b100e146';
  251. $accessToken = GetAccess_Token1();
  252. # 实例化
  253. $wx = new \JSSDK5($appid, $appSecret, $accessToken);
  254. # 获取参数
  255. $info = $wx->getWxConfig();
  256. # 传参页面
  257. $this->assign('wxConfig', $info);
  258. $this->display('Index2/index');
  259. }
  260. //获取 权限 设备编号 001,001
  261. public function getdevice($company)
  262. {
  263. $device = M()->query("SELECT o.owner_code,c.owner_name FROM sp_owner o join sp_owner_company c ON o.company =c.owner_id WHERE o.company in($company);");
  264. $this->owner_name = $device[0]['owner_name'];
  265. $str = "";
  266. foreach ($device as $val) {
  267. $str .= "'" . $val['owner_code'] . "',";
  268. }
  269. $newstr = substr($str, 0, strlen($str) - 1);
  270. return $newstr;
  271. }
  272. }