Batchhandle.php.bak.2021-08-31 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use think\Session;
  5. use think\Db;
  6. use think\Request;
  7. use think\Log;
  8. class Batchhandle extends Controller
  9. {
  10. public function index(){
  11. // return $this->display('batchhandle/add');
  12. return $this->fetch();
  13. }
  14. public function Alarm_batch_handle(){
  15. $data=input('');
  16. $device_code=$data['device_code'];//设备编号
  17. $start_time=$data['start_time'];//开始时间
  18. $endtime=$data['end_time'];//结束时间
  19. $where='';
  20. $s_sql_company="select company from sp_owner where owner_code='".$device_code."'";
  21. $company_list = add($s_sql_company);
  22. if (empty($company_list)){
  23. return "该设备不存在,请联系管理员查明原因";
  24. }
  25. if (!empty($start_time)){
  26. $where=" and time>='".$start_time."'";
  27. }
  28. if (!empty($endtime)){
  29. $where=" and time<='".$endtime."'";
  30. }
  31. if (!empty($endtime)&&!empty($start_time)){
  32. $where=" and time>='".$start_time."' and time<='".$endtime."'";
  33. }
  34. $s_sql="select * from sp_hj2017 where id in(select MAX(id) from sp_hj2017 WHERE device_code='".$device_code."' ".$where." GROUP BY data2,data3,data5) ORDER BY id DESC;";
  35. $list = add($s_sql);
  36. if (empty($list)){
  37. return "该设备时间段内没有未处理报警";
  38. }
  39. $s_sql_clr="SELECT username,phone FROM sp_owner_phone WHERE owner_code='".$company_list[0]['company']."' AND phone NOT IN ('13301708833','18901601933','13817464316','15262166206','18621761642','18800178436','17317231730','13262875757','17630065224','17621295894','18773792538','15365185591','13501679954','13917531546') GROUP BY owner_code";
  40. $clr_list = add($s_sql_clr);
  41. if (empty($clr_list)){
  42. return "系统内部出现问题:处理人不存在,请联系管理员";
  43. }
  44. if (!empty($clr_list[0]['username'])){
  45. $clr=$clr_list[0]['username'];
  46. }else{
  47. $clr=$clr_list[0]['phone'];
  48. }
  49. $clnr="管理员批量处理";
  50. $clwb=1;
  51. $cldh=$clr_list[0]['phone'];
  52. $clsj= date('Y-m-d h:i:s', time());
  53. $clzt="1";
  54. $u_sql = "update sp_hj2017 set clnr='".$clnr."',clwb='".$clwb."',cldh='".$cldh."',clsj='".$clsj."',clr='".$clr."',clzt='".$clzt."' where device_code='".$device_code."' ".$where." and clzt='0'";
  55. // print_r($u_sql);exit();
  56. $res = addDataInfo($u_sql);
  57. foreach ($list as $key=>$value){
  58. $cs = [
  59. 'SubType'=>1,
  60. 'DeviceId'=>$list[$key]['device_code'],
  61. 'InsertId'=>$list[$key]['id'],
  62. 'Confirmed'=>true,
  63. ];
  64. $url='http://47.98.201.187:55335/report';
  65. // $url='http://47.98.201.73/ytapi/admin/Onenet/OneNetCeShi';
  66. $cs3=json_encode($cs);
  67. $result = http_post_advertise($url,$cs3);
  68. }
  69. if($res) {
  70. return $this->success('处理成功','index');
  71. }else{
  72. return $this->error("处理失败,请稍后再试");
  73. }
  74. // return "记录已处理";
  75. }
  76. }