ComprehensiveAlarmController.class.php.bak.2021-07-30 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class ComprehensiveAlarmController extends ComController
  5. {
  6. //综合告警各类型数据统计
  7. public function getAlarmStatistics()
  8. {
  9. $Date = I();
  10. $company_code = $Date['company_code'];
  11. if (empty($company_code)) {
  12. $res['msg'] = '操作失败,缺少关键参数company_code';
  13. $res['flag'] = false;
  14. echo json_encode($res);
  15. exit();
  16. }
  17. $device_list = $this->getDeviceCode($company_code);
  18. $device_list1 = $this->getDeviceCode1($company_code);
  19. //消火栓未处理统计
  20. $untreated_fire_hydrant_count = M()->query("select count(*) as untreated_fire_hydrant_count from sp_sj2017 where clzt=0 and device_code in(" . $device_list1 . ")");
  21. //报警主机未处理数量统计
  22. $untreated_alarm_host_count = M()->query("select count(*) as untreated_alarm_host_count from sp_hj2017 where clzt=0 and device_code in(" . $device_list . ")");
  23. //消防水未处理数量统计
  24. $untreated_fire_water_count1 = M()->query("select count(*) as untreated_fire_water_count from sp_sj2017 where clzt=0 and device_code in(" . $device_list . ")");
  25. $untreated_fire_water_count = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'] - (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  26. //电气火灾未处理数量统计
  27. $untreated_electrical_fire_count = M()->query("select count(*) as untreated_electrical_fire_count from sp_ef2017 where clzt=0 and device_code in(" . $device_list . ")");
  28. //视频监测未处理数量统计
  29. $untreated_video_monitoring_count = M()->query("select count(*) as untreated_video_monitoring_count from sp_video2017 where clzt=0 and device_code in(" . $device_list . ")");
  30. //井盖未处理数量统计
  31. $untreated_manhole_cover_count = M()->query("select count(*) as untreated_manhole_cover_count from sp_iw2017 where clzt=0 and device_code in(" . $device_list . ")");
  32. //门禁未处理数量统计
  33. $untreated_door_count = M()->query("select count(*) as untreated_door_count from sp_door2020 where clzt=0 and device_code in(" . $device_list . ")");
  34. //可燃气体未处理数量统计
  35. $untreated_gas_count = M()->query("select count(*) as untreated_gas_count from sp_gas2020 where clzt=0 and device_code in(" . $device_list . ")");
  36. //地磁未处理数量统计
  37. $untreated_geomagnetism_count = M()->query("select count(*) as untreated_geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(" . $device_list . ")");
  38. //RTU未处理数量统计
  39. $untreated_rtu_count = M()->query("select count(*) as untreated_rtu_count from sp_rtu2017 where clzt=0 and device_code in(" . $device_list . ")");
  40. //电梯未处理数量统计
  41. $untreated_elevator_count = M()->query("select count(*) as untreated_elevator_count from sp_lifter2017 where clzt=0 and device_code in(" . $device_list . ")");
  42. $data[0]['company_code'] = $company_code;
  43. $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count[0]['untreated_alarm_host_count'];
  44. $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count;
  45. $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count[0]['untreated_electrical_fire_count'];
  46. $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count[0]['untreated_video_monitoring_count'];
  47. $data[0]['untreated_manhole_cover_count'] = (int)$untreated_manhole_cover_count[0]['untreated_manhole_cover_count'];
  48. $data[0]['untreated_door_count'] = (int)$untreated_door_count[0]['untreated_door_count'];
  49. $data[0]['untreated_gas_count'] = (int)$untreated_gas_count[0]['untreated_gas_count'];
  50. $data[0]['untreated_geomagnetism_count'] = (int)$untreated_geomagnetism_count[0]['untreated_geomagnetism_count'];
  51. $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count[0]['untreated_rtu_count'];
  52. $data[0]['untreated_elevator_count'] = (int)$untreated_elevator_count[0]['untreated_elevator_count'];
  53. $data[0]['untreated_fire_hydrant_count'] = (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  54. $res['msg'] = '操作成功';
  55. $res['flag'] = true;
  56. $res['data'] = $data;
  57. echo json_encode($res);
  58. }
  59. public function getIntegratedAlarmList()
  60. {
  61. $Date = I();
  62. $company_code = $Date['company_code'];
  63. $type = $Date['type'];
  64. $processing_status = $Date['processing_status'];
  65. if (empty($company_code) && empty($type) && empty($processing_status)) {
  66. $res['msg'] = '操作失败,缺少关键参数';
  67. $res['flag'] = false;
  68. echo json_encode($res);
  69. exit();
  70. }
  71. switch ($type) {
  72. case '1'://烟感和报警主机
  73. $table = 'sp_hj2017';
  74. $types = '1,3';
  75. break;
  76. case '2'://水表和液位
  77. $table = 'sp_sj2017';
  78. $types = '2,5';
  79. break;
  80. case '4'://消防栓
  81. $table = 'sp_sj2017';
  82. $types = $type;
  83. break;
  84. case '6'://RTU
  85. $table = 'sp_rtu2017';
  86. $types = $type;
  87. break;
  88. case '7'://电气火灾
  89. $table = 'sp_ef2017';
  90. $types = $type;
  91. break;
  92. case '16'://视频监测
  93. $table = 'sp_video2017';
  94. $types = $type;
  95. break;
  96. case '17'://电梯监测
  97. $table = 'sp_lifter2017';
  98. $types = $type;
  99. break;
  100. case '128'://井盖
  101. $table = 'sp_iw2017';
  102. $types = $type;
  103. break;
  104. case '129'://地磁
  105. $table = 'sp_dc2020';
  106. $types = $type;
  107. break;
  108. case '130'://门禁
  109. $table = 'sp_door2020';
  110. $types = $type;
  111. break;
  112. case '131'://可燃气体
  113. $table = 'sp_gas2020';
  114. $types = $type;
  115. break;
  116. default:
  117. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  118. $res['flag'] = 3002;
  119. echo json_encode($res);
  120. exit();
  121. break;
  122. }
  123. $alarm_count = M()->query("SELECT count(*) as alarm_count FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE b.dwtype in(" . $types . ") AND b.company='" . $company_code . "' AND clzt=" . $processing_status);
  124. $alarm_list = M()->query("SELECT a.id,a.device_code,a.time,a.data1,a.data4,a.data2,a.clzt,b.company AS company_code,b.owner_name,b.unitinfo,b.dwtype as type FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE b.dwtype in(" . $types . ") AND b.company='" . $company_code . "' AND clzt=" . $processing_status . " ORDER BY time DESC LIMIT 1000");
  125. if ($type == 2 || $type == 4) {
  126. foreach ($alarm_list as $key => $value) {
  127. switch ($alarm_list[$key]['data1']) {
  128. case 'WP1':
  129. $alarm_list[$key]['data4'] = '低压';
  130. break;
  131. case 'WP2':
  132. $alarm_list[$key]['data4'] = '高压';
  133. break;
  134. case 'WP3':
  135. $alarm_list[$key]['data4'] = '故障';
  136. break;
  137. case 'WP4':
  138. $alarm_list[$key]['data4'] = '离线';
  139. break;
  140. case 'LL1':
  141. $alarm_list[$key]['data4'] = '低水位';
  142. break;
  143. case 'LL2':
  144. $alarm_list[$key]['data4'] = '高水位';
  145. break;
  146. default:
  147. $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
  148. break;
  149. }
  150. }
  151. } else if ($type == 7) {
  152. foreach ($alarm_list as $key => $value) {
  153. if ($alarm_list[$key]['data1'] == 'EF1') {
  154. $alarm_list[$key]['data4'] = '欠压报警';
  155. } elseif ($alarm_list[$key]['data1'] == 'EF2') {
  156. $alarm_list[$key]['data4'] = '过压报警';
  157. } elseif ($alarm_list[$key]['data1'] == 'EF3') {
  158. $alarm_list[$key]['data4'] = '过流报警';
  159. } elseif ($alarm_list[$key]['data1'] == 'EF4') {
  160. $alarm_list[$key]['data4'] = '漏电报警';
  161. } elseif ($alarm_list[$key]['data1'] == 'EF5') {
  162. $alarm_list[$key]['data4'] = '回路1温度超限报警';
  163. } elseif ($alarm_list[$key]['data1'] == 'EF6') {
  164. $alarm_list[$key]['data4'] = '回路2温度超限报警';
  165. } elseif ($alarm_list[$key]['data1'] == 'EF7') {
  166. $alarm_list[$key]['data4'] = '回路3温度超限报警';
  167. } elseif ($alarm_list[$key]['data1'] == 'EF8') {
  168. $alarm_list[$key]['data4'] = '回路4温度超限报警';
  169. } elseif ($alarm_list[$key]['data1'] == 'EF9') {
  170. $alarm_list[$key]['data4'] = '离线';
  171. } else {
  172. $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
  173. }
  174. }
  175. }
  176. $res['msg'] = '操作成功';
  177. $res['flag'] = true;
  178. $res['alarm_count'] = (int)$alarm_count[0]['alarm_count'];
  179. $res['data'] = $alarm_list;
  180. echo json_encode($res);
  181. }
  182. public function getAlarmDetails()
  183. {
  184. $Date = I();
  185. $id = $Date['id'];
  186. $type = $Date['type'];
  187. // $processing_status = $Date['processing_status'];
  188. if (empty($id) && empty($type)) {
  189. $res['msg'] = '操作失败,缺少关键参数';
  190. $res['flag'] = 3001;
  191. echo json_encode($res);
  192. exit();
  193. }
  194. switch ($type) {
  195. case '1'://烟感和报警主机
  196. $table = 'sp_hj2017';
  197. $types = '1,3';
  198. break;
  199. case '2'://水表和液位
  200. $table = 'sp_sj2017';
  201. $types = '2,5';
  202. break;
  203. case '4'://消防栓
  204. $table = 'sp_sj2017';
  205. $types = $type;
  206. break;
  207. case '6'://RTU
  208. $table = 'sp_rtu2017';
  209. $types = $type;
  210. break;
  211. case '7'://电气火灾
  212. $table = 'sp_ef2017';
  213. $types = $type;
  214. break;
  215. case '16'://视频监测
  216. $table = 'sp_video2017';
  217. $types = $type;
  218. break;
  219. case '17'://电梯监测
  220. $table = 'sp_lifter2017';
  221. $types = $type;
  222. break;
  223. case '128'://井盖
  224. $table = 'sp_iw2017';
  225. $types = $type;
  226. break;
  227. case '129'://地磁
  228. $table = 'sp_dc2020';
  229. $types = $type;
  230. break;
  231. case '130'://门禁
  232. $table = 'sp_door2020';
  233. $types = $type;
  234. break;
  235. case '131'://可燃气体
  236. $table = 'sp_gas2020';
  237. $types = $type;
  238. break;
  239. default:
  240. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  241. $res['flag'] = 3002;
  242. echo json_encode($res);
  243. exit();
  244. break;
  245. }
  246. $list = M()->query("SELECT a.id,a.port,a.device_code,b.owner_name as device_name,a.data1,a.data4,a.data2,a.data3,a.data5,a.clwb,a.clzt,a.clr,a.clnr,b.company AS company_code,a.time,b.unitinfo,b.dwtype,a.ncmd FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE a.id=" . $id);
  247. if ($type == 2 || $type == 4) {
  248. switch ($list[0]['data1']) {
  249. case 'WP1':
  250. $list[0]['alarm_information'] = '低压';
  251. break;
  252. case 'WP2':
  253. $list[0]['alarm_information'] = '高压';
  254. break;
  255. case 'WP3':
  256. $list[0]['alarm_information'] = '故障';
  257. break;
  258. case 'WP4':
  259. $list[0]['alarm_information'] = '离线';
  260. break;
  261. case 'LL1':
  262. $list[0]['alarm_information'] = '低水位';
  263. break;
  264. case 'LL2':
  265. $list[0]['alarm_information'] = '高水位';
  266. break;
  267. default:
  268. $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
  269. break;
  270. }
  271. if ($list[0]['dwtype'] == 5) {
  272. $list[0]['numerical_value'] = '水位值:' . $list[0]['data4'] . 'M';
  273. } else {
  274. $list[0]['numerical_value'] = '水压值:' . $list[0]['data4'] . 'Mpa';
  275. }
  276. }else if ($type == 6){
  277. $list[0]['alarm_information'] =$list[0]['data2'];
  278. if ($list[0]['port'] == 'E6') {
  279. if ($list[0]['data2'] == '低压' || $list[0]['data2'] == '高压') {
  280. $list[0]['numerical_value'] = '水压值:' . $list[0]['data1'] . 'Mpa';
  281. } elseif ($list[0]['data2'] == '低水位' || $list[0]['data2'] == '高水位') {
  282. $list[0]['numerical_value'] = '水位:' . $list[0]['data1'] . 'M';
  283. } elseif ($list[0]['data2'] == '低温' || $list[0]['data2'] == '高温') {
  284. $list[0]['numerical_value'] = '温度:' . $list[0]['data1'] . '℃';
  285. } elseif ($list[0]['data2'] == '低湿度' || $list[0]['data2'] == '高湿度') {
  286. $list[0]['numerical_value'] = '湿度:' . $list[0]['data1'] . '%';
  287. }else if ($list[0]['data2'] == '设备异常'){
  288. $list[0]['numerical_value'] = $list[0]['data4'].':'.$list[0]['data1'];
  289. } else {
  290. $list[0]['numerical_value'] = $list[0]['data4'];
  291. }
  292. } else {
  293. $list[0]['numerical_value'] = $list[0]['data4'];
  294. }
  295. }else if ($type == 7) {
  296. if ($list[0]['data1'] == 'EF1') {
  297. $list[0]['alarm_information'] = '欠压报警';
  298. $list[0]['numerical_value'] = 'A相欠压值:' . $list[0]['data2'] . 'V B相欠压值:' . $list[0]['data3'] . 'V C相欠压值:' . $list[0]['data4'] . 'V';
  299. } elseif ($list[0]['data1'] == 'EF2') {
  300. $list[0]['alarm_information'] = '过压报警';
  301. $list[0]['numerical_value'] = 'A相过压值:' . $list[0]['data2'] . 'V B相过压值:' . $list[0]['data3'] . 'V C相过压值:' . $list[0]['data4'] . 'V';
  302. } elseif ($list[0]['data1'] == 'EF3') {
  303. $list[0]['alarm_information'] = '过流报警';
  304. $list[0]['numerical_value'] = 'A相过流值:' . $list[0]['data2'] . 'mA B相过流值:' . $list[0]['data3'] . 'mA C相过流值:' . $list[0]['data4'] . 'mA';
  305. } elseif ($list[0]['data1'] == 'EF4') {
  306. $list[0]['alarm_information'] = '漏电报警';
  307. $list[0]['numerical_value'] = '漏电流值:' . $list[0]['data2'] . 'mA';
  308. } elseif ($list[0]['data1'] == 'EF5') {
  309. $list[0]['alarm_information'] = '回路1温度超限报警';
  310. $list[0]['numerical_value'] = '温度1值:' . $list[0]['data2'] . '℃';
  311. } elseif ($list[0]['data1'] == 'EF6') {
  312. $list[0]['alarm_information'] = '回路2温度超限报警';
  313. $list[0]['numerical_value'] = '温度2值:' . $list[0]['data2'] . '℃';
  314. } elseif ($list[0]['data1'] == 'EF7') {
  315. $list[0]['alarm_information'] = '回路3温度超限报警';
  316. $list[0]['numerical_value'] = '温度3值:' . $list[0]['data2'] . '℃';
  317. } elseif ($list[0]['data1'] == 'EF8') {
  318. $list[0]['alarm_information'] = '回路4温度超限报警';
  319. $list[0]['numerical_value'] = '温度4值:' . $list[0]['data2'] . '℃';
  320. } elseif ($list[0]['data1'] == 'EF9') {
  321. $list[0]['alarm_information'] = '离线';
  322. $list[0]['numerical_value'] = '设备离线';
  323. } else {
  324. $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
  325. }
  326. }else{
  327. $list[0]['alarm_information'] = $list[0]['data4'];
  328. }
  329. $res['msg'] = '操作成功';
  330. $res['flag'] = true;
  331. $res['data'] = $list;
  332. echo json_encode($res);
  333. }
  334. public function setAlarmHandling(){
  335. $Data = I();
  336. $id = $Data['id'];
  337. $type = $Data['type'];
  338. $device_code = $Data['device_code'];
  339. $if_batch = $Data['if_batch'];
  340. $clwb = $Data['clwb'];
  341. $clnr = $Data['clnr'];
  342. $clr = $_SESSION['phone'];
  343. $port = $Data['port'];
  344. $Source_code=$Data['ncmd'];
  345. if (empty($id) && empty($type)&& empty($device_code)&& empty($clwb)&& empty($Data['data2'])&& empty($Data['data5'])&& empty($Data['data1'])&& empty($Source_code)) {
  346. $res['msg'] = '操作失败,缺少关键参数';
  347. $res['flag'] = false;
  348. echo json_encode($res);
  349. exit();
  350. }
  351. switch ($type) {
  352. case '1'://烟感和报警主机
  353. $table = 'sp_hj2017';
  354. $Tabs = M('hj2017');
  355. $types = '1,3';
  356. $where['data2'] = $Data['data2'];
  357. $where['data3'] = $Data['data3'];
  358. $where['data5'] = $Data['data5'];
  359. break;
  360. case '2'://水表和液位
  361. $table = 'sp_sj2017';
  362. $Tabs = M('sj2017');
  363. $types = '2,5';
  364. $where['data1'] = $Data['data1'];
  365. break;
  366. case '4'://消防栓
  367. $table = 'sp_sj2017';
  368. $Tabs = M('sj2017');
  369. $types = $type;
  370. break;
  371. case '6'://RTU
  372. $table = 'sp_rtu2017';
  373. $Tabs = M('rtu2017');
  374. $types = $type;
  375. $where['ncmd'] = $Data['ncmd'];
  376. $where['data2'] = $Data['data2'];
  377. $where['data4'] = $Data['data4'];
  378. break;
  379. case '7'://电气火灾
  380. $table = 'sp_ef2017';
  381. $Tabs = M('ef2017');
  382. $types = $type;
  383. $where['data1'] = $Data['data1'];
  384. break;
  385. case '16'://视频监测
  386. $table = 'sp_video2017';
  387. $Tabs = M('video2017');
  388. $types = $type;
  389. break;
  390. case '17'://电梯监测
  391. $table = 'sp_lifter2017';
  392. $Tabs = M('lifter2017');
  393. $types = $type;
  394. break;
  395. case '128'://井盖
  396. $table = 'sp_iw2017';
  397. $Tabs = M('iw2017');
  398. $types = $type;
  399. break;
  400. case '129'://地磁
  401. $table = 'sp_dc2020';
  402. $Tabs = M('dc2020');
  403. $types = $type;
  404. break;
  405. case '130'://门禁
  406. $table = 'sp_door2020';
  407. $Tabs = M('door2020');
  408. $types = $type;
  409. break;
  410. case '131'://可燃气体
  411. $table = 'sp_gas2020';
  412. $Tabs = M('gas2020');
  413. $types = $type;
  414. break;
  415. default:
  416. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  417. $res['flag'] = false;
  418. echo json_encode($res);
  419. exit();
  420. break;
  421. }
  422. //修改条件
  423. $data['clzt']=1;
  424. $data['clwb']=$clwb;
  425. $data['clnr']=$clnr;
  426. $data['cldh']=$clr;
  427. $data['clr']=$clr;
  428. $data['clsj']=date("Y-m-d");
  429. $types_data=M()->query("select dwtype from sp_owner where owner_code='".$Data['device_code']."'");
  430. $typess=$types_data[0]['dwtype'];
  431. if ($if_batch==1){//批量处理
  432. $where['device_code']=$device_code;
  433. $where['clzt']=0;
  434. $R=$Tabs->where($where)->save($data);
  435. }else{
  436. $where['id']=$id;
  437. $R=$Tabs->where($where)->save($data);
  438. }
  439. $url1 = 'http://47.98.201.187:55335/report';
  440. if ($if_batch==1){
  441. if ($typess==1){
  442. $res_id = M()->query("select id,data3,data4 from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data3='" . $Data['data3'] . "' and data5='" . $Data['data5'] . "' and clzt=1 order by time desc LIMIT 1;");
  443. $cs66 = [
  444. 'SubType' => 1,
  445. 'DeviceId' => $Data['device_code'],
  446. 'InsertId' => $res_id[0]['id'],
  447. 'Confirmed' => true,
  448. ];
  449. $cs88 = json_encode($cs66);
  450. $result = http_post_advertise($url1, $cs88);
  451. if (!empty($res_id[0]['data4'])){
  452. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  453. // $port=substr($res_id[0]['data4'],3,1);
  454. }else{
  455. $port='';
  456. }
  457. if (!empty($res_id[0]['data3'])){
  458. $Source_code=str_replace(',','',$res_id[0]['data3']);
  459. }else{
  460. $Source_code='';
  461. }
  462. $unique_number=$Data['device_code'].$port.$Source_code;
  463. }elseif ($typess==2){
  464. $res_id = M()->query("select id from sp_sj2017 where device_code='" . $Data['device_code'] . "' and data1='" . $Data['data1'] . "' and clzt=1 order by time desc limit 1");
  465. $cs66 = [
  466. 'SubType' => 2,
  467. 'DeviceId' => $Data['device_code'],
  468. 'InsertId' => $res_id[0]['id'],
  469. 'Confirmed' => true,
  470. ];
  471. $cs88 = json_encode($cs66);
  472. $result = http_post_advertise($url1, $cs88);
  473. $unique_number=$Data['device_code'];
  474. }elseif ($typess==3){
  475. $res_id = M()->query("select id from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data2='" . $Data['ftypewtype'] . "' and clzt=1 order by time desc limit 1");
  476. $cs66 = [
  477. 'SubType' => 3,
  478. 'DeviceId' => $Data['device_code'],
  479. 'InsertId' => $res_id[0]['id'],
  480. 'Confirmed' => true,
  481. ];
  482. $url1 = 'http://47.98.201.187:55335/report';
  483. $cs88 = json_encode($cs66);
  484. $result = http_post_advertise($url1, $cs88);
  485. $unique_number=$Data['device_code'];
  486. }elseif ($typess==6){
  487. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  488. }elseif ($typess==7){
  489. $res_id = M()->query("select * from sp_ef2017 where device_code='" . $Data['device_code'] . "' and data1='" . $Data['data1'] . "' and clzt=1 order by time desc limit 1");
  490. $cs66 = [
  491. 'SubType' => 7,
  492. 'DeviceId' => $Data['device_code'],
  493. 'InsertId' => $res_id[0]['id'],
  494. 'Confirmed' => true,
  495. ];
  496. $url1 = 'http://47.98.201.187:55335/report';
  497. $cs88 = json_encode($cs66);
  498. $result = http_post_advertise($url1, $cs88);
  499. $port=$res_id[0]['port'];
  500. $unique_number=$Data['device_code'].$port;
  501. }else{
  502. $unique_number=$Data['device_code'];
  503. }
  504. //redis链接
  505. // $redis = new \Redis();
  506. // $result = $redis->connect('127.0.0.1', 6379);
  507. // if ($result==1){
  508. // $redis->set("$unique_number",1);
  509. // $redis->close();
  510. // }
  511. }else{
  512. $cs = [
  513. 'SubType' => $typess,
  514. 'DeviceId' => $Data['device_code'],
  515. 'InsertId' => $Data['id'],
  516. 'Confirmed' => true,
  517. ];
  518. if ($typess == 1 || $typess == 2 || $typess == 3 || $typess == 7) {
  519. $url = 'http://47.98.201.187:55335/report';
  520. $cs3 = json_encode($cs);
  521. $result = http_post_advertise($url, $cs3);
  522. }
  523. if ($typess==1){
  524. $res_id = M()->query("select data3,data4 from sp_hj2017 where id=" . $Data['id']);
  525. if (!empty($res_id[0]['data4'])){
  526. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  527. // $port=substr($res_id[0]['data4'],3,1);
  528. }else{
  529. $port='';
  530. }
  531. if (!empty($res_id[0]['data3'])){
  532. $Source_code=str_replace(',','',$res_id[0]['data3']);
  533. }else{
  534. $Source_code='';
  535. }
  536. $unique_number=$Data['device_code'].$port.$Source_code;
  537. }else if ($typess==6){
  538. $port=$Data['port'];
  539. $Source_code=$Data['ncmd'];
  540. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  541. }else if ($typess==7){
  542. $res_id = M()->query("select port from sp_ef2017 where id=" . $Data['id']);
  543. $port=$res_id[0]['port'];
  544. $unique_number=$Data['device_code'].$port;
  545. }else{
  546. $unique_number=$Data['device_code'];
  547. }
  548. //redis储存处理的设备
  549. // $redis = new \Redis();
  550. // $result = $redis->connect('127.0.0.1', 6379);
  551. // if ($result==1){
  552. // $redis->set("$unique_number",1);
  553. // $redis->close();
  554. // }
  555. }
  556. // $data = array("devicestatus" => 0);
  557. // $str_where = "deviceid='" . $Data['device_code'] . "'";
  558. // $str_sql_upd = M('devices_status')->where($str_where)->save($data);
  559. if ($R){
  560. $res['msg'] = '操作成功';
  561. $res['flag'] = true;
  562. echo json_encode($res);
  563. }else{
  564. $res['msg'] = '操作失败';
  565. $res['flag'] = 3002;
  566. echo json_encode($res);
  567. }
  568. }
  569. //获取消防栓设备编号
  570. public function getDeviceCode1($company)
  571. {
  572. $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.dwtype=4 and o.company in($company)");
  573. $str = "";
  574. foreach ($device as $val) {
  575. $str .= "'" . $val['owner_code'] . "',";
  576. }
  577. $newstr = substr($str, 0, strlen($str) - 1);
  578. return $newstr;
  579. }
  580. }