AccessControlwarnController.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. use Think\Cache\Driver;
  5. include '../Common/function.php';
  6. class AccessControlwarnController extends PushWarnController
  7. {
  8. public function message_access_control()
  9. {
  10. $Data = I('post.');
  11. //日志打印
  12. $filename_log = "/var/www/html/jdxf/log/access_control_b_log" . date("Y-m-d") . ".log";
  13. $this->printing_log($Data, $filename_log);
  14. if (!empty($Data['IMEI'])) {
  15. $device_code = $Data['IMEI'];
  16. } else if (!empty($Data['IEMI'])) {
  17. $device_code = $Data['IEMI'];
  18. }
  19. $unique_number = $device_code;
  20. $insert_id = $Data['insert_id'];
  21. $remarks = $Data['bz'];
  22. $time = $Data['time'];
  23. $evt = $Data['evt'];
  24. if (empty($insert_id) || empty($device_code) || empty($evt) || empty($unique_number)) {
  25. echo '缺少重要参数,请检查推送代码!';
  26. exit();
  27. }
  28. //3小时以内相同设备报警未处理则不推送
  29. $redis = new \Redis();
  30. $result = $redis->connect('127.0.0.1', 6379);
  31. $if_push = 1;
  32. if ($result == 1) {
  33. $res = $redis->get("$unique_number");
  34. if ($res == 1) {
  35. $if_push = 1;
  36. } else if (!empty($res)) {
  37. if (floor((strtotime($Data['time']) - strtotime($res)) / 3600) > 3) {
  38. $if_push = 1;
  39. } else {
  40. $if_push = 0;
  41. }
  42. } else {
  43. $if_push = 1;
  44. }
  45. $redis->get("$unique_number");
  46. $redis->set("$unique_number", "$time");
  47. $redis->close();
  48. }
  49. switch ($evt) {
  50. case 'gs01':
  51. $status = '可燃气体告警';
  52. // $where=" AND data2 like '%6%'";
  53. break;
  54. case 'gs02':
  55. $status = '电池电量低';
  56. // $where=" AND data2 like '%6%'";
  57. break;
  58. case 'gs03':
  59. $status = '设备防拆';
  60. // $where=" AND data2 like '%6%'";
  61. break;
  62. default:
  63. $status = '其他' . $Data['evt'];
  64. $where = " AND data2 like '%6%'";
  65. break;
  66. }
  67. $data = M()->query("select s.owner_name,s.unitinfo,s.company,c.owner_address,s.dwtype from sp_owner s ,sp_owner_company c where s.company=c.owner_id and s.owner_code ='" . $device_code . "'");
  68. $union_sql = M()->query("select phone from sp_owner_phone WHERE owner_code='" . $data[0]['company'] . "' " . $where . " union select phone from sp_owner_phone WHERE owner_code in (select other_code from sp_owner_fujin where owner_code='" . $data[0]['company'] . "') " . $where . " ");
  69. if (count($union_sql) == 0) {
  70. echo "phonr is null";
  71. exit;
  72. }
  73. $openids = $this->array_column1($union_sql, "phone");
  74. if (empty($openids)) {
  75. echo 'open is null';
  76. exit;
  77. }
  78. $status11 = M()->query("SELECT statustime FROM sp_devices_status where deviceid='" . $device_code . "'");
  79. $op = M()->query("SELECT openid FROM sp_wx_customuser WHERE type='wx' and idphone in($openids)");
  80. $access_token = GetAccess_Token1();
  81. $address = '警报地址:' . $data[0]['owner_address'] . $data[0]['unitinfo'];
  82. $type = $status;
  83. //keyword3.DATA
  84. if (empty($time)) {
  85. $time = $status11[0]['statustime'];
  86. }
  87. //remark.DATA
  88. if (empty($remarks)) {
  89. $remarks = '设备名称:' . $data[0]['owner_name'];
  90. }
  91. $url = "https://iot.usky.cn/jdxf/wxapp2.php/Home/Fireinfo/index/type/130/id/" . $insert_id;
  92. if ($if_push == 1) {
  93. foreach ($op as $o) {
  94. if (!empty($o['openid'])) {
  95. $R = $this->SendDeviceAlarm($access_token, $o['openid'], $address, $device_code, $type, $time, $remarks, $url);
  96. $filename_log = "/var/www/html/jdxf/log/access_control_t_log" . date("Y-m-d") . ".log";
  97. $this->printing_log($R, $filename_log);
  98. print_r($R);
  99. }
  100. }
  101. }
  102. }
  103. }