123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\admin\controller;
- use think\Controller;
- use think\Session;
- use think\Db;
- use think\Request;
- use think\Log;
- class Batchhandle extends Controller
- {
- public function index(){
- // return $this->display('batchhandle/add');
- return $this->fetch();
- }
- public function Alarm_batch_handle(){
- $data=input('');
- $device_code=$data['device_code'];//设备编号
- $start_time=$data['start_time'];//开始时间
- $endtime=$data['end_time'];//结束时间
- $where='';
- $s_sql_company="select company from sp_owner where owner_code='".$device_code."'";
- $company_list = add($s_sql_company);
- if (empty($company_list)){
- return "该设备不存在,请联系管理员查明原因";
- }
- if (!empty($start_time)){
- $where.=" and time>='".$start_time."'";
- }
- if (!empty($endtime)){
- $where.=" and time<'".$endtime."' ";
- }
- // if (!empty($endtime)&&!empty($start_time)){
- // $where=" and time>='".$start_time."' and time<='".$endtime."'";
- // }
- $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;";
- $list = add($s_sql);
- if (empty($list)){
- return "该设备时间段内没有未处理报警";
- }
- $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";
- $clr_list = add($s_sql_clr);
- if (empty($clr_list)){
- return "系统内部出现问题:处理人不存在,请联系管理员";
- }
- if (!empty($clr_list[0]['username'])){
- $clr=$clr_list[0]['username'];
- }else{
- $clr=$clr_list[0]['phone'];
- }
- $clnr="管理员批量处理";
- $clwb=1;
- $cldh=$clr_list[0]['phone'];
- $clsj= date('Y-m-d h:i:s', time());
- $clzt="1";
- $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'";
- // print_r($u_sql);exit();
- $res = addDataInfo($u_sql);
- foreach ($list as $key=>$value){
- $cs = [
- 'SubType'=>1,
- 'DeviceId'=>$list[$key]['device_code'],
- 'InsertId'=>$list[$key]['id'],
- 'Confirmed'=>true,
- ];
- $url='http://47.98.201.187:55335/report';
- // $url='http://47.98.201.73/ytapi/admin/Onenet/OneNetCeShi';
- $cs3=json_encode($cs);
- $result = http_post_advertise($url,$cs3);
- }
- if($res) {
- return $this->success('处理成功','index');
- }else{
- return $this->error("处理失败,请稍后再试");
- }
- // return "记录已处理";
- }
- }
|