InspectionController.class.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: TianFeng
  5. * Date: 2019-03-20
  6. * Time: 12:37
  7. */
  8. namespace Home\Controller;
  9. use Think\Controller;
  10. include '../Common/function.php';
  11. include '/var/www/html/jdxf/Public/vendor/WxJDK/JSSDK.php';
  12. class InspectionController extends ComController
  13. {
  14. public function index()
  15. {
  16. // print_r($_SESSION['phone']);
  17. $data = I();
  18. // print_r($data);
  19. $sql = "select * from ytiot_xj_inspectors where phone='" . $data['phone'] . "' and zn in(2,3,6,7)";//.$_SESSION['phone'];//17621295894";
  20. $res = add66($sql);
  21. $dq_time = date("Y-m-d");
  22. $arr = array();
  23. if ($res != null) {
  24. $ry = count($res);
  25. $ry_id_list = '';
  26. for ($i = 0; $i < $ry; $i++) {
  27. if ($i == 0) {
  28. $ry_id_list = $res[$i]['id'];
  29. } else {
  30. $ry_id_list .= ',' . $res[$i]['id'];
  31. }
  32. }
  33. // $team_personnel_sql = "select a.team_id from ytiot_xj_team_personnel as a join ytiot_xj_plan_team as b on a.team_id=b.id where person_liable_id=".$res[0]['id']." or people_id=".$res[0]['id']." group by a.team_id";
  34. $team_personnel_sql = "select a.team_id from ytiot_xj_team_personnel as a join ytiot_xj_plan_team as b on a.team_id=b.id where person_liable_id in(" . $ry_id_list . ") or people_id in(" . $ry_id_list . ") group by a.team_id";
  35. $team_res = add66($team_personnel_sql);
  36. // print_r($team_res);
  37. if ($team_res != null) {
  38. $td_id_ct = count($team_res);
  39. $td_id_list = '';
  40. for ($i = 0; $i < $td_id_ct; $i++) {
  41. if ($i == 0) {
  42. $td_id_list = $team_res[$i]['team_id'];
  43. } else {
  44. $td_id_list .= ',' . $team_res[$i]['team_id'];
  45. }
  46. }
  47. $plan_child_sql = "select * from ytiot_xj_plan_child where inspect_date='" . $dq_time . "' and team_id in(" . $td_id_list . ") and data2='1'";
  48. // print_r($plan_child_sql);
  49. $plan_child_res = add66($plan_child_sql);
  50. // print_r($plan_child_res);
  51. if ($plan_child_res != null) {
  52. foreach ($plan_child_res as $key => $value) {
  53. $plan_master_sql = "select plan_name from ytiot_xj_plan_master where id=" . $value['zb_id'];
  54. // print_r($plan_master_sql);
  55. $plan_master_res = add66($plan_master_sql);
  56. // print_r($plan_master_res);
  57. $spot_operation_record_sql = "select * from ytiot_xj_spot_operation_record where zb_id=" . $value['id'];
  58. // print_r($spot_operation_record_sql);
  59. $spot_operation_record_res = add66($spot_operation_record_sql);
  60. // print_r($spot_operation_record_res);
  61. if ($spot_operation_record_res != null && $plan_master_res != null) {
  62. foreach ($spot_operation_record_res as $key1 => $value1) {
  63. $dw_sql = "select * from ytiot_xj_inspection_points where id=" . $value1['spot_id'];
  64. $dw_res = add66($dw_sql);
  65. // print_r($dw_res);
  66. if ($dw_res != null) {
  67. $arr[$key]['id'] = $plan_child_res[$key]['id'];
  68. $arr[$key]['completion'] = $plan_child_res[$key]['completion'];
  69. $arr[$key]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  70. $arr[$key]['bw'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  71. $arr[$key]['bw'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  72. $arr[$key]['bw'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. }
  80. $appid = C('APPID');
  81. # 公众号获取
  82. $appSecret = C('SECRET');
  83. # 实例化
  84. $wx = new \JSSDK($appid, $appSecret);
  85. # 获取参数
  86. $info = $wx->getWxConfig();
  87. # 传参页面
  88. $this->assign('wxConfig', $info);
  89. $this->assign('res5', $arr);
  90. // print_r($res[0]['id']);
  91. $this->assign('wbr_id', $res[0]['id']);
  92. $this->display('Index/inspection_system');
  93. }
  94. public function wb_index()
  95. {
  96. $Data = I();
  97. $this->assign('companyid', $Data['companyid']);
  98. $this->display('Index/wb_menu');
  99. }
  100. public function xj_index()
  101. {
  102. $Data = I();
  103. $this->assign('companyid', $Data['companyid']);
  104. $this->display('Index/xj_menu');
  105. }
  106. public function index2()
  107. {
  108. // print_r($_SESSION['phone']);
  109. $data = I();
  110. // print_r($data);
  111. $sql = "select * from ytiot_xj_inspectors where phone='" . $data['phone'] . "' and zn in(1,3,5,7)";//.$_SESSION['phone'];//17621295894";
  112. $res = add66($sql);
  113. // print_r($res);
  114. $dq_time = date("Y-m-d");
  115. $arr = array();
  116. if ($res != null) {
  117. $ry = count($res);
  118. $ry_id_list = '';
  119. for ($i = 0; $i < $ry; $i++) {
  120. if ($i == 0) {
  121. $ry_id_list = $res[$i]['id'];
  122. } else {
  123. $ry_id_list .= ',' . $res[$i]['id'];
  124. }
  125. }
  126. // $team_personnel_sql = "select a.team_id from ytiot_xj_team_personnel as a join ytiot_xj_plan_team as b on a.team_id=b.id where person_liable_id=".$res[0]['id']." or people_id=".$res[0]['id']." group by a.team_id";
  127. $team_personnel_sql = "select a.team_id from ytiot_xj_team_personnel as a join ytiot_xj_plan_team as b on a.team_id=b.id where person_liable_id in(" . $ry_id_list . ") or people_id in(" . $ry_id_list . ") group by a.team_id";
  128. $team_res = add66($team_personnel_sql);
  129. // print_r($team_res);
  130. if ($team_res != null) {
  131. $td_id_ct = count($team_res);
  132. $td_id_list = '';
  133. for ($i = 0; $i < $td_id_ct; $i++) {
  134. if ($i == 0) {
  135. $td_id_list = $team_res[$i]['team_id'];
  136. } else {
  137. $td_id_list .= ',' . $team_res[$i]['team_id'];
  138. }
  139. }
  140. $plan_child_sql = "select a.*,b.cycle from ytiot_xj_plan_child as a join ytiot_xj_plan_master as b on a.zb_id=b.id where a.team_id in(" . $td_id_list . ") and a.data2='2'";
  141. // $plan_child_sql="select * from ytiot_xj_plan_child where inspect_date='".$dq_time."' and team_id in(".$td_id_list.") and data2='2'";
  142. // print_r($plan_child_sql);
  143. $plan_child_res = add66($plan_child_sql);
  144. // print_r($plan_child_res);
  145. if ($plan_child_res != null) {
  146. foreach ($plan_child_res as $key => $value) {
  147. // print_r(strtotime("+7 day",strtotime($plan_child_res[$key]['inspect_date'])));
  148. if (($plan_child_res[$key]['cycle'] == 0 && $plan_child_res[$key]['inspect_date'] == $dq_time) ||
  149. ($plan_child_res[$key]['cycle'] == 1 && strtotime("+7 day", strtotime($plan_child_res[$key]['inspect_date'])) > strtotime($dq_time)) ||
  150. ($plan_child_res[$key]['cycle'] == 2 && strtotime("+1 month", strtotime($plan_child_res[$key]['inspect_date'])) > strtotime($dq_time))) {
  151. $plan_master_sql = "select plan_name from ytiot_xj_plan_master where id=" . $value['zb_id'];
  152. // print_r($plan_master_sql);
  153. $plan_master_res = add66($plan_master_sql);
  154. // print_r($plan_master_res);
  155. $spot_operation_record_sql = "select * from ytiot_xj_spot_operation_record where zb_id=" . $value['id'];
  156. // print_r($spot_operation_record_sql);
  157. $spot_operation_record_res = add66($spot_operation_record_sql);
  158. // print_r($spot_operation_record_res);
  159. if ($spot_operation_record_res != null && $plan_master_res != null) {
  160. foreach ($spot_operation_record_res as $key1 => $value1) {
  161. $dw_sql = "select * from ytiot_xj_inspection_points where id=" . $value1['spot_id'];
  162. $dw_res = add66($dw_sql);
  163. // print_r($dw_res);
  164. if ($dw_res != null) {
  165. $arr[$key]['id'] = $plan_child_res[$key]['id'];
  166. $arr[$key]['completion'] = $plan_child_res[$key]['completion'];
  167. $arr[$key]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  168. $arr[$key]['bw'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  169. $arr[$key]['bw'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  170. $arr[$key]['bw'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. $appid = C('APPID');
  180. # 公众号获取
  181. $appSecret = C('SECRET');
  182. # 实例化
  183. $wx = new \JSSDK($appid, $appSecret);
  184. # 获取参数
  185. $info = $wx->getWxConfig();
  186. # 传参页面
  187. $this->assign('wxConfig', $info);
  188. $this->assign('res5', $arr);
  189. // print_r($arr);
  190. $this->assign('wbr_id', $res[0]['id']);
  191. $this->display('Index/maintenance_system');
  192. }
  193. public function maintenance_record()
  194. {
  195. $data = I();
  196. $buding_id = M()->query("SELECT building_id FROM sp_owner_company WHERE owner_id='".$data['companyid']."'");
  197. $sql = "select a.*,b.spot_name,d.plan_name from ytiot_xj_spot_operation_record AS a
  198. LEFT JOIN ytiot_xj_inspection_points AS b ON a.spot_id=b.id
  199. LEFT JOIN ytiot_xj_plan_child AS c ON a.zb_id=c.id
  200. LEFT JOIN ytiot_xj_plan_master AS d ON c.zb_id=d.id
  201. where a.data3=2 and a.data2=2 and a.company_code='".$buding_id[0]['building_id']."' order by a.id desc";
  202. // $sql = "select * from ytiot_xj_spot_operation_record where data3=2 and data2=2 order by id desc";
  203. $res = add($sql);
  204. foreach ($res as $key => $value) {
  205. if ($res[$key]['spot_abnormal'] == 0) {
  206. $res[$key]['spot_status'] = "正常";
  207. } elseif ($res[$key]['spot_abnormal'] == 1) {
  208. $res[$key]['spot_status'] = "异常";
  209. } elseif ($res[$key]['spot_abnormal'] == 2) {
  210. $res[$key]['spot_status'] = "故障";
  211. } elseif ($res[$key]['spot_abnormal'] == 3) {
  212. $res[$key]['spot_status'] = "其他";
  213. }
  214. // if (!empty($res[$key]['spot_id'])) {
  215. // $points_sql = "select * from ytiot_xj_inspection_points where id=" . $res[$key]['spot_id'];
  216. // $points_res = add($points_sql);
  217. // $res[$key]['spot_name'] = $points_res[0]['spot_name'];
  218. //// $res[$key]['spot_address']=$points_res[0]['spot_address'];
  219. // }
  220. // if (!empty($res[$key]['spot_id'])) {
  221. // $jhz_sql = "select * from ytiot_xj_plan_child where id=" . $res[$key]['zb_id'];
  222. // $jhz_res = add($jhz_sql);
  223. // $jh_sql = "select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id'];
  224. // $jh_res = add($jh_sql);
  225. // $res[$key]['plan_name'] = $jh_res[0]['plan_name'];
  226. //// $res[$key]['spot_address']=$jh_res[0]['spot_address'];
  227. // }
  228. // if (!empty($res[$key]['spot_id'])){
  229. // $zrr_sql="select * from ytiot_xj_inspectors where id=".$res[$key]['wbr_id'];
  230. // $zrr_res=add($zrr_sql);
  231. // $res[$key]['name']=$zrr_res[0]['name'];
  232. // $res[$key]['spot_address']=$zrr_res[0]['phone'];
  233. // }
  234. }
  235. $this->assign('companyid', $data['companyid']);
  236. $this->assign('res', $res);
  237. $this->display('Index/maintenance_list');
  238. }
  239. public function inspection_record()
  240. {
  241. $data = I();
  242. $buding_id = M()->query("SELECT building_id FROM sp_owner_company WHERE owner_id='".$data['companyid']."'");
  243. $sql = "select a.*,b.spot_name,d.plan_name from ytiot_xj_spot_operation_record AS a
  244. LEFT JOIN ytiot_xj_inspection_points AS b ON a.spot_id=b.id
  245. LEFT JOIN ytiot_xj_plan_child AS c ON a.zb_id=c.id
  246. LEFT JOIN ytiot_xj_plan_master AS d ON c.zb_id=d.id
  247. where a.data3=2 and a.data2=1 and a.company_code='".$buding_id[0]['building_id']."' order by a.id desc";
  248. // $sql = "select * from ytiot_xj_spot_operation_record where data3=2 and data2=1 order by id desc";
  249. $res = add($sql);
  250. foreach ($res as $key => $value) {
  251. if ($res[$key]['spot_abnormal'] == 0) {
  252. $res[$key]['spot_status'] = "正常";
  253. } elseif ($res[$key]['spot_abnormal'] == 1) {
  254. $res[$key]['spot_status'] = "异常";
  255. } elseif ($res[$key]['spot_abnormal'] == 2) {
  256. $res[$key]['spot_status'] = "故障";
  257. } elseif ($res[$key]['spot_abnormal'] == 3) {
  258. $res[$key]['spot_status'] = "其他";
  259. }
  260. // if (!empty($res[$key]['spot_id'])) {
  261. // $points_sql = "select * from ytiot_xj_inspection_points where id=" . $res[$key]['spot_id'];
  262. // $points_res = add($points_sql);
  263. // $res[$key]['spot_name'] = $points_res[0]['spot_name'];
  264. // }
  265. //
  266. // if (!empty($res[$key]['spot_id'])) {
  267. // $jhz_sql = "select * from ytiot_xj_plan_child where id=" . $res[$key]['zb_id'];
  268. // $jhz_res = add($jhz_sql);
  269. // $jh_sql = "select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id'];
  270. // $jh_res = add($jh_sql);
  271. // $res[$key]['plan_name'] = $jh_res[0]['plan_name'];
  272. // }
  273. }
  274. $this->assign('companyid', $data['companyid']);
  275. $this->assign('res', $res);
  276. $this->display('Index/inspection_list');
  277. }
  278. public function details()
  279. {
  280. $data = I();
  281. $record_id = $data['id'];
  282. $sql = "select * from ytiot_xj_spot_operation_record where id=" . $record_id;
  283. $res = add($sql);
  284. if ($res[0]['spot_abnormal'] == 0) {
  285. $res[0]['spot_status'] = "正常";
  286. } elseif ($res[0]['spot_abnormal'] == 1) {
  287. $res[0]['spot_status'] = "异常";
  288. } elseif ($res[0]['spot_abnormal'] == 2) {
  289. $res[0]['spot_status'] = "故障";
  290. } elseif ($res[0]['spot_abnormal'] == 3) {
  291. $res[0]['spot_status'] = "其他";
  292. }
  293. if (!empty($res[0]['spot_id'])) {
  294. $jhz_sql = "select * from ytiot_xj_plan_child where id=" . $res[0]['zb_id'];
  295. $jhz_res = add($jhz_sql);
  296. $jh_sql = "select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id'];
  297. $jh_res = add($jh_sql);
  298. $res[0]['plan_name'] = $jh_res[0]['plan_name'];
  299. }
  300. if (!empty($res[0]['spot_id'])) {
  301. $points_sql = "select * from ytiot_xj_inspection_points where id=" . $res[0]['spot_id'];
  302. $points_res = add($points_sql);
  303. $res[0]['spot_name'] = $points_res[0]['spot_name'];
  304. $res[0]['spot_address'] = $points_res[0]['spot_address'];
  305. }
  306. if (!empty($res[0]['wbr_id'])) {
  307. $zrr_sql = "select * from ytiot_xj_inspectors where id=" . $res[0]['wbr_id'];
  308. $zrr_res = add($zrr_sql);
  309. $res[0]['name'] = $zrr_res[0]['name'];
  310. $res[0]['phone'] = $zrr_res[0]['phone'];
  311. }
  312. if (!empty($res[0]['company_code'])) {
  313. // $zrr_sql="select * from ytiot_xj_inspectors where id=".$res[0]['company_code'];
  314. // $zrr_res=add($zrr_sql);
  315. $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $res[0]['company_code'] . "'");
  316. $res[0]['owner_name'] = $company_data[0]['owner_name'];
  317. $res[0]['owner_address'] = $company_data[0]['owner_address'];
  318. }
  319. if (!empty($res[0]['id'])) {
  320. $photos_sql = "select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $res[0]['id'];
  321. $photos_res = add($photos_sql);
  322. $res[0]['report_photos'] = $photos_res[0]['report_photos'];
  323. }
  324. $this->assign('companyid', $data['companyid']);
  325. $this->assign('res', $res[0]);
  326. $this->display('Index/maintenance_details');
  327. }
  328. public function xj_details()
  329. {
  330. $data = I();
  331. $record_id = $data['id'];
  332. $sql = "select * from ytiot_xj_spot_operation_record where id=" . $record_id;
  333. $res = add($sql);
  334. if ($res[0]['spot_abnormal'] == 0) {
  335. $res[0]['spot_status'] = "正常";
  336. } elseif ($res[0]['spot_abnormal'] == 1) {
  337. $res[0]['spot_status'] = "异常";
  338. } elseif ($res[0]['spot_abnormal'] == 2) {
  339. $res[0]['spot_status'] = "故障";
  340. } elseif ($res[0]['spot_abnormal'] == 3) {
  341. $res[0]['spot_status'] = "其他";
  342. }
  343. if (!empty($res[0]['spot_id'])) {
  344. $jhz_sql = "select * from ytiot_xj_plan_child where id=" . $res[0]['zb_id'];
  345. $jhz_res = add($jhz_sql);
  346. $jh_sql = "select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id'];
  347. $jh_res = add($jh_sql);
  348. $res[0]['plan_name'] = $jh_res[0]['plan_name'];
  349. }
  350. if (!empty($res[0]['spot_id'])) {
  351. $points_sql = "select * from ytiot_xj_inspection_points where id=" . $res[0]['spot_id'];
  352. $points_res = add($points_sql);
  353. $res[0]['spot_name'] = $points_res[0]['spot_name'];
  354. $res[0]['spot_address'] = $points_res[0]['spot_address'];
  355. }
  356. if (!empty($res[0]['wbr_id'])) {
  357. $zrr_sql = "select * from ytiot_xj_inspectors where id=" . $res[0]['wbr_id'];
  358. $zrr_res = add($zrr_sql);
  359. $res[0]['name'] = $zrr_res[0]['name'];
  360. $res[0]['phone'] = $zrr_res[0]['phone'];
  361. }
  362. if (!empty($res[0]['company_code'])) {
  363. // $zrr_sql="select * from ytiot_xj_inspectors where id=".$res[0]['company_code'];
  364. // $zrr_res=add($zrr_sql);
  365. $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $res[0]['company_code'] . "'");
  366. $res[0]['owner_name'] = $company_data[0]['owner_name'];
  367. $res[0]['owner_address'] = $company_data[0]['owner_address'];
  368. }
  369. if (!empty($res[0]['id'])) {
  370. $photos_sql = "select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $res[0]['id'];
  371. $photos_res = add($photos_sql);
  372. $res[0]['report_photos'] = $photos_res[0]['report_photos'];
  373. }
  374. $this->assign('companyid', $data['companyid']);
  375. $this->assign('res', $res[0]);
  376. $this->display('Index/inspectione_details');
  377. }
  378. public function getDeviceList()
  379. {
  380. $Data = I();
  381. $record_id = $Data['record_id'];
  382. $spot_id = $Data['spot_id'];
  383. $sql = "select a.spot_id,b.* from ytIoT.ytiot_xj_spot_equipment as a JOIN jdxf.sp_owner as b ON a.equipment_code=b.owner_code where spot_id=" . $spot_id;
  384. $res = add($sql);
  385. $this->assign('record_id', $record_id);
  386. $this->assign('spot_id', $spot_id);
  387. $this->assign('res', $res);
  388. $this->display('point_details/point_details');
  389. }
  390. public function getDeviceDetails()
  391. {
  392. $Data = I();
  393. $record_id = $Data['record_id'];
  394. $spot_id = $Data['spot_id'];
  395. $this->assign('record_id', $record_id);
  396. $this->assign('spot_id', $spot_id);
  397. if ($Data['dwtype'] == 16) {
  398. $owner_xx = M()->query("select owner_code, owner_name, unitinfo, sim, install_time,rtmp,hls,dwtype from sp_owner where owner_code='" . $Data['deviceid'] . "'");
  399. $owner_address = M()->query("select owner_address from sp_owner_company where owner_id='" . $Data['companyid'] . "'");
  400. $gzsj = M()->query("select data4,time from sp_video2017 where device_code='" . $Data['deviceid'] . "' order by time desc");
  401. if (!empty($owner_xx[0]['rtmp'])) {
  402. $owner_xx[0]['rtmp'] = $owner_xx[0]['rtmp'];
  403. } else {
  404. $owner_xx[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  405. }
  406. $this->assign('type_name', "视频监控");
  407. $this->assign('type', "video");
  408. $this->assign('companyid', $Data['companyid']);
  409. $this->assign('owner_xx', $owner_xx);
  410. $this->assign('owner_address', $owner_address);
  411. $this->assign('gzsj', $gzsj);
  412. $this->display('point_details/000001');
  413. } else if ($Data['dwtype'] == 17) {
  414. $owner_xx = M()->query("select owner_code, owner_name, unitinfo, sim, install_time,rtmp,hls,dwtype from sp_owner where owner_code='" . $Data['deviceid'] . "'");
  415. $owner_address = M()->query("select owner_address from sp_owner_company where owner_id='" . $Data['companyid'] . "'");
  416. $gzsj = M()->query("select data4,time from sp_lifter2017 where device_code='" . $Data['deviceid'] . "' order by time desc");
  417. if (!empty($owner_xx[0]['rtmp'])) {
  418. $owner_xx[0]['rtmp'] = $owner_xx[0]['rtmp'];
  419. } else {
  420. $owner_xx[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  421. }
  422. $this->assign('type_name', "电梯监控");
  423. $this->assign('type', "elevator");
  424. $this->assign('companyid', $Data['companyid']);
  425. $this->assign('owner_xx', $owner_xx);
  426. $this->assign('owner_address', $owner_address);
  427. $this->assign('gzsj', $gzsj);
  428. $this->display('point_details/000001');
  429. } else if ($Data['dwtype'] == 4) {
  430. $owner_xx = M()->query("select owner_code, owner_name, unitinfo, sim, install_time,rtmp,hls,dwtype from sp_owner where owner_code='" . $Data['deviceid'] . "'");
  431. $owner_address = M()->query("select owner_address from sp_owner_company where owner_id='" . $Data['companyid'] . "'");
  432. $gzsj = M()->query("select data4,time from sp_d" . $Data['deviceid'] . " where device_code='" . $Data['deviceid'] . "' order by time desc");
  433. if (!empty($owner_xx[0]['rtmp'])) {
  434. $owner_xx[0]['rtmp'] = $owner_xx[0]['rtmp'];
  435. } else {
  436. $owner_xx[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  437. }
  438. $this->assign('type_name', "消防栓监控");
  439. $this->assign('type', "firehydrant");
  440. $this->assign('companyid', $Data['companyid']);
  441. $this->assign('owner_xx', $owner_xx);
  442. $this->assign('owner_address', $owner_address);
  443. $this->assign('gzsj', $gzsj);
  444. $this->display('point_details/000001');
  445. } else if ($Data['dwtype'] == 128) {
  446. $owner_xx = M()->query("select owner_code, owner_name, unitinfo, sim, install_time,rtmp,hls,dwtype from sp_owner where owner_code='" . $Data['deviceid'] . "'");
  447. $owner_address = M()->query("select owner_address from sp_owner_company where owner_id='" . $Data['companyid'] . "'");
  448. $gzsj = M()->query("select device_status,time from sp_iw2017 where device_code='" . $Data['deviceid'] . "' order by time desc");
  449. if (!empty($owner_xx[0]['rtmp'])) {
  450. $owner_xx[0]['rtmp'] = $owner_xx[0]['rtmp'];
  451. } else {
  452. $owner_xx[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  453. }
  454. if ($gzsj[0]['device_status']) {
  455. $gzsj[0]['data4'] = '正常';
  456. } else {
  457. $gzsj[0]['data4'] = '打开告警';
  458. }
  459. $this->assign('type_name', "井盖监控");
  460. $this->assign('type', "firehydrant");
  461. $this->assign('companyid', $Data['companyid']);
  462. $this->assign('owner_xx', $owner_xx);
  463. $this->assign('owner_address', $owner_address);
  464. $this->assign('gzsj', $gzsj);
  465. $this->display('point_details/000001');
  466. } else {
  467. $res = M()->query("SELECT * FROM sp_v_deviceall WHERE deviceid='" . $Data['deviceid'] . "'");
  468. $azwz = M()->query("select unitinfo from sp_owner where owner_code='" . $Data['deviceid'] . "'");
  469. $res[0]['azwz'] = $azwz[0]['unitinfo'];
  470. //在线离线权限问题
  471. $login_phone = M()->query("SELECT * FROM sp_login_phone");
  472. $phone_arr = array();
  473. foreach ($login_phone as $key => $value) {
  474. $phone_arr[$key] = $login_phone[$key]['phone'];
  475. }
  476. $phone = $_SESSION['phone'];
  477. $isin = in_array($phone, $phone_arr);
  478. if ($isin) {
  479. $phone_pd = 1;
  480. } else {
  481. $phone_pd = 0;
  482. }
  483. $time = M()->query("SELECT device_id,MAX(data_time) as data_time FROM sp_owner_status WHERE device_id='" . $Data['deviceid'] . "'");
  484. if (!empty($time)) {
  485. $stime = date('Y-m-d h:i:s', time());
  486. $etime = $time[0]['data_time'];
  487. $hour = intval((strtotime($stime) - strtotime($etime)) / 3600);
  488. if ($hour < 24) {
  489. $zs_status = '在线';
  490. } else {
  491. $zs_status = '离线';
  492. }
  493. } else {
  494. $zs_status = '状态不存在';
  495. }
  496. if ($res[0]['dwtype'] != 1) {
  497. if ($phone_pd == 1) {
  498. $res[0]['zs_status'] = $zs_status;
  499. }
  500. }
  501. if (!empty($res[0]['rtmp'])) {
  502. $res[0]['rtmp'] = $res[0]['rtmp'];
  503. } else {
  504. $res[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  505. }
  506. $this->assign('list', $res[0]);
  507. $this->assign('companyid', $Data['companyid']);
  508. $dwtype = $res[0]['dwtype'];
  509. $deviceid = $Data['deviceid'];
  510. if ($dwtype == 1) {
  511. $j2017 = M('hj2017');
  512. $counts = $j2017->order('time desc')->where(array('device_code' => $deviceid))->count('id');//总数
  513. $j_counts = $j2017->where(array('device_code' => $deviceid, 'clzt' => '1'))->count('id');//解决总数
  514. $d_counts = $j2017->where(array('device_code' => $deviceid, 'clwb' => '否'))->count('id');//真实总数
  515. $w_counts = $j2017->where(array('device_code' => $deviceid, 'clwb' => '是'))->count('id');//wb总数
  516. $this->assign('dwtype', 1);
  517. $this->assign('counts', $counts);
  518. $this->assign('j_counts', $j_counts);
  519. $this->assign('z_counts', $d_counts);
  520. $this->assign('w_counts', $w_counts);
  521. $this->display('point_details/000002');
  522. }
  523. if ($dwtype == 2) {
  524. $shui = M()->query("select * from sp_owner_sync_data where device_id='" . $Data['deviceid'] . "' and point_code=4 order by data_time desc");
  525. $electric_data = M()->query("select point_data from sp_owner_sync_data where device_id='" . $Data['deviceid'] . "' and point_code=2 order by data_time desc");
  526. $signal_data = M()->query("select point_data from sp_owner_sync_data where device_id='" . $Data['deviceid'] . "' and point_code=3 order by data_time desc");
  527. $a = array();
  528. $b = array();
  529. $electric = array();
  530. $signal = array();
  531. foreach ($shui as $value) {
  532. $a[] = $value['data_time'];
  533. $b[] = $value['point_data'];
  534. }
  535. foreach ($electric_data as $value) {
  536. $electric[] = $value['point_data'];
  537. }
  538. foreach ($signal_data as $value) {
  539. $signal[] = $value['point_data'] * 20;
  540. }
  541. $bb = $shui[0];
  542. $this->assign('bb', $bb['point_data']);
  543. $this->assign('dwtype', 2);
  544. $this->assign('time', json_encode($a));
  545. $this->assign('data4', json_encode($b));
  546. $this->assign('electric', json_encode($electric));
  547. $this->assign('signal', json_encode($signal));
  548. $this->display('point_details/000004');
  549. }
  550. if ($dwtype == 3) {
  551. $fume = M()->query("select RSRQ, DeviceStatus, BatteryLevel, storeTime, device_id from sp_y" . $deviceid . " ORDER BY storeTime DESC limit 1");
  552. $a = M()->query("select dwtype, sim,install_time,rtmp,hls from sp_owner where owner_code='" . $deviceid . "'");
  553. if ($a[0]['dwtype'] == 3) {
  554. $a[0]['dwtype'] = '烟感';
  555. }
  556. if (!empty($a[0]['rtmp'])) {
  557. $a[0]['rtmp'] = $a[0]['rtmp'];
  558. } else {
  559. $a[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  560. }
  561. foreach ($fume as $key => $arr) {
  562. if ($fume[$key]['devicestatus'] == 7) {
  563. $fume[$key]['type'] = '正常';
  564. } else if ($fume[$key]['devicestatus'] == 5) {
  565. $fume[$key]['type'] = '故障';
  566. } else if ($fume[$key]['devicestatus'] == 4) {
  567. $fume[$key]['type'] = '低压';
  568. } else if ($fume[$key]['devicestatus'] == 2) {
  569. $fume[$key]['type'] = '报警静音';
  570. } else if ($fume[$key]['devicestatus'] == 1) {
  571. $fume[$key]['type'] = '报警';
  572. }
  573. }
  574. $this->assign('dwtype', 3);
  575. $this->assign('a', $a);
  576. $this->assign('fume', $fume);
  577. $this->display('point_details/000003');
  578. }
  579. //液位
  580. if ($dwtype == 5) {
  581. $shui = M()->query("select * from sp_owner_sync_data where device_id='" . $Data['deviceid'] . "' and point_code=4 order by data_time desc");
  582. $a = array();
  583. $b = array();
  584. foreach ($shui as $value) {
  585. $a[] = $value['data_time'];
  586. $b[] = $value['point_data'];
  587. }
  588. $bb = $shui[0];
  589. $this->assign('bb', $bb['point_data']);
  590. $this->assign('dwtype', 5);
  591. $this->assign('time', json_encode($a));
  592. $this->assign('data4', json_encode($b));
  593. $this->display('point_details/000007');
  594. }
  595. if ($dwtype == 6) {
  596. $rtu = M()->query("SELECT id,data4,ncmd,`time`,data1,data2,CASE WHEN `port`='E6' THEN '模拟量' WHEN `port`='E3' THEN '开关量' END as types
  597. FROM sp_d" . $deviceid . " WHERE id in(SELECT MAX(id)
  598. FROM sp_d" . $deviceid . " GROUP BY `port`,ncmd) AND ncmd !='' "
  599. . (($deviceid == '4023363030303635') ? " AND (ncmd !='02' OR `port`!='E6') " :
  600. (($deviceid == '4023363030303639') ? " AND (ncmd !='03' OR `port`!='E6') " :
  601. (($deviceid == '4023363030303434') ? " AND (ncmd !='04' OR `port`!='E3') AND (ncmd !='05' OR `port`!='E3')" :
  602. (($deviceid == '4023363030303336') ? " AND (ncmd !='01' OR `port`!='E6') " :
  603. (($deviceid == '4023363030303733') ? " AND (ncmd !='05' AND ncmd !='06' )" : "")))))//山海大酒店B1楼水泵房02端口模拟量因设备故障,暂时屏蔽
  604. );
  605. $this->assign('dwtype', 6);
  606. $this->assign('rtu', $rtu);
  607. $res = M()->query("SELECT systype FROM sp_owner_port where owner_code='" . $deviceid . "'");
  608. $this->assign("trues", '0' . $res[0]['systype']);
  609. $this->display('point_details/000005');
  610. }
  611. // 电气火灾
  612. if ($dwtype == 7) {
  613. $install_time = M()->query("select install_time,rtmp,hls,owner_name,sim from sp_owner where owner_code='" . $Data['deviceid'] . "'");
  614. $owner_address = M()->query("select owner_address from sp_owner_company where owner_id=" . $Data['companyid']);
  615. $true_status = M()->query("select true_status from sp_devices_status where deviceid=" . $Data['deviceid']);
  616. $xssj = M()->query("select * from sp_owner_status where device_id='" . $Data['deviceid'] . "'");
  617. $zxsj = M()->query("select max(data_time) as zxsj from sp_owner_status where device_id='" . $Data['deviceid'] . "'");
  618. if ($true_status[0]['true_status'] == '75') {
  619. $dstatus = '离线';
  620. } else {
  621. $dstatus = '在线';
  622. }
  623. if (!empty($install_time[0]['rtmp'])) {
  624. $install_time[0]['rtmp'] = $install_time[0]['rtmp'];
  625. } else {
  626. $install_time[0]['rtmp'] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无';
  627. }
  628. $data = array(
  629. 'owner_name' => $install_time[0]['owner_name'],
  630. 'dstatus' => $dstatus,
  631. 'dthz' => '电气火灾',
  632. 'deviceid' => $Data['deviceid'],
  633. 'sim' => $install_time[0]['sim'],
  634. 'install_time' => $install_time[0]['install_time'],
  635. 'owner_address' => $owner_address[0]['owner_address'],
  636. 'rtmp' => $install_time[0]['rtmp'],
  637. 'hls' => $install_time[0]['hls'],
  638. );
  639. $this->assign('dwtype', 7);
  640. $this->assign('xssj', $xssj);
  641. $this->assign('zxsj', $zxsj);
  642. $this->assign('data', $data);
  643. $this->display('point_details/000006');
  644. }
  645. }
  646. }
  647. }