FireController.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. //include '../Common/function.php';
  5. class FireController extends ComController
  6. {
  7. public function index()
  8. {
  9. $Data = I();
  10. $Map['company'] = $Data['companyid'];
  11. $Map['clzt'] = 0;
  12. $device_code_list=$this->getDeviceCode($Data['companyid'],"1,3");
  13. if (!empty($device_code_list)){
  14. $ResData=M()->query("SELECT count(*) as hj FROM sp_hj2017 where device_code in(".$device_code_list.") and clzt='0'");
  15. }else{
  16. $ResData[0]['hj']= 0;
  17. }
  18. // $ResData=M()->query("SELECT count(a.id) as hj FROM sp_hj2017 as a join sp_owner as b ON a.device_code=b.owner_code WHERE b.dwtype in(1,3) and b.company='".$Map['company']."' and a.clzt='0'");
  19. $this->assign('wcl', $ResData[0]['hj']);
  20. $this->assign('companyid', $Data['companyid']);
  21. $this->display('Index/fire');
  22. }
  23. public function change()
  24. {
  25. $Data = I('');
  26. $page = $Data['page'];
  27. $size = 20;
  28. $startpage=($page - 1) * 20;
  29. $Map['company'] = $Data['companyid'];
  30. switch ($Data['type']) {
  31. case 'untreated':
  32. $Map['clzt'] = 0;
  33. $where=" and clzt='0' ";
  34. break;
  35. case 'treated':
  36. $Map['clzt'] = 1;
  37. $where=" and clzt='1' ";
  38. break;
  39. default:
  40. break;
  41. }
  42. $device = M()->query("SELECT owner_code,owner_name FROM sp_owner WHERE company in(".$Map['company'].") and dwtype in(1,3)");
  43. if (!empty($device)){
  44. $str = "";
  45. foreach ($device as $val) {
  46. $str .= "'" . $val['owner_code'] . "',";
  47. }
  48. $newstr = substr($str, 0, strlen($str) - 1);
  49. $ResData = M()->query("select data2 as ftype , time ,device_code ,clzt ,id ,data4 from sp_hj2017 WHERE device_code in(".$newstr.") ".$where." order by id desc limit ".$startpage.",".$size);
  50. if (!empty($ResData)){
  51. foreach ($ResData as $key => $value){
  52. foreach ($device as $key1=>$value1){
  53. if ($ResData[$key]['device_code']==$device[$key1]['owner_code']){
  54. $ResData[$key]['owner_name']=$device[$key1]['owner_name'];
  55. }
  56. }
  57. }
  58. }
  59. }
  60. // $ResData = M()->query("select a.data2 as ftype , a.time ,b.owner_name ,a.clzt ,a.id ,a.data4 from sp_hj2017 as a join sp_owner as b ON a.device_code=b.owner_code WHERE b.dwtype in(1,3) and b.company='".$Map['company']."' ".$where." order by a.id desc limit 500");
  61. // $ResData = M('v_hj2017_2')->where($Map)->order("time desc")->limit(500)->select();
  62. // $this->assign('ResData', $ResData);
  63. // $this->display('Index/fire-list');
  64. echo json_encode($ResData);
  65. }
  66. //获取设备编号
  67. public function getDeviceCode($company,$dwtype)
  68. {
  69. $device = M()->query("SELECT owner_code FROM sp_owner WHERE company in(".$company.") and dwtype in(".$dwtype.")");
  70. $str = "";
  71. foreach ($device as $val) {
  72. $str .= "'" . $val['owner_code'] . "',";
  73. }
  74. $newstr = substr($str, 0, strlen($str) - 1);
  75. return $newstr;
  76. }
  77. //无用
  78. public function change1()
  79. {
  80. $Data = I('');
  81. $Map['company'] = $Data['companyid'];
  82. $type = $Data['type'];
  83. switch ($type) {
  84. case 'untreated':
  85. $ResData = M()->query("select sp_hj2017.time, sp_hj2017.data2, sp_owner.owner_name, sp_hj2017.clzt, sp_hj2017.id, sp_hj2017.data4 from sp_owner join sp_hj2017 on sp_owner.owner_code=sp_hj2017.device_code where company=" . $Map['company'] . " and clzt=0 order by time desc limit 500");
  86. break;
  87. case 'treated':
  88. $ResData = M()->query("select sp_hj2017.time, sp_hj2017.data2, sp_owner.owner_name, sp_hj2017.clzt, sp_hj2017.id, sp_hj2017.data4 from sp_owner join sp_hj2017 on sp_owner.owner_code=sp_hj2017.device_code where company=" . $Map['company'] . " and clzt=1 order by time desc limit 500");
  89. break;
  90. default:
  91. $ResData = M()->query("select sp_hj2017.time, sp_hj2017.data2, sp_owner.owner_name, sp_hj2017.clzt, sp_hj2017.id, sp_hj2017.data4 from sp_owner join sp_hj2017 on sp_owner.owner_code=sp_hj2017.device_code where company=" . $Map['company'] . " order by time desc limit 500");
  92. break;
  93. }
  94. $this->assign('ResData', $ResData);
  95. $this->display('Index/fire-list');
  96. }
  97. }
  98. ?>