isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','sort','trim'); //排序列 $sort = input('sord','asc','trim'); //排序方式 $order = $sortRow.' '.$sort.' ,id desc'; $title = input('title','','trim'); if($title !=''){ $securityId = Db::name('security')->where('del',0)->where('org_id',cur_org_id())->where('title','like','%'.$title.'%')->column('id'); $map[] = ['security_id','in',$securityId]; } $b = input('start', '', 'trim'); $e = input('end', '', 'trim'); if ($b) { $map[] = ['create_time', '>=', $b.' 00:00:00']; } if ($e) { $map[] = ['create_time', '<=', $e.' 23:59:59']; } $status = input('status','','trim'); if($status != ''){ $map[] = ['status','=',$status]; } $map[] = ['org_id','=',cur_org_id()]; $map= empty($map) ? true: $map; //数据查询 $lists = Db::name('security_record')->where($map)->limit($start,$length)->order('id desc')->select(); foreach ($lists as $k=>$v){ $lists[$k]['security_name'] = Db::name('security')->where('id',$v['security_id'])->value('title'); $lists[$k]['cf_user'] = ''; if($v['cf_user_id'] > 0){ $lists[$k]['cf_user'] = Db::name('user')->where('id',$v['cf_user_id'])->value('real_name'); } } //数据返回 $totalCount = Db::name('security_record')->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $this->assign('meta_title','报警记录列表'); return $this->fetch(); } } public function check($id=0){ if(request()->isPost()){ $remark = input('remark','','trim'); if(!$remark){ $this->error('备注不能为空'); } $save = Db::name('security_record')->where('id',$id)->update(['status'=>1,'update_time'=>date('Y-m-d H:i:s'),'remark'=>$remark]); if(!$save){ $this->error('操作失败'); } // model('ActionLog')->addlog(is_login(),33,'报警记录:处理',['id' => $id],cur_org_id()); $this->success('操作成功'); }else{ $this->assign('id',$id); return $this->fetch(); } } public function export(){ $title = input('title','','trim'); if($title !=''){ $securityId = Db::name('security')->where('del',0)->where('org_id',cur_org_id())->where('title','like','%'.$title.'%')->column('id'); $map[] = ['security_id','in',$securityId]; } $b = input('start', '', 'trim'); $e = input('end', '', 'trim'); if ($b) { $map[] = ['create_time', '>=', $b.' 00:00:00']; } if ($e) { $map[] = ['create_time', '<=', $e.' 23:59:59']; } $status = input('status','','trim'); if($status != ''){ $map[] = ['status','=',$status]; } $map[] = ['org_id','=',cur_org_id()]; $map= empty($map) ? true: $map; //数据查询 $lists = Db::name('security_record')->where($map)->order('id desc')->select(); foreach ($lists as $k=>$v){ $lists[$k]['security_name'] = Db::name('security')->where('id',$v['security_id'])->value('title'); $lists[$k]['cf_user'] = ''; $lists[$k]['statusTxt'] = $v['status']==0?'未处理':'已处理'; if($v['cf_user_id'] > 0){ $lists[$k]['cf_user'] = Db::name('user')->where('id',$v['cf_user_id'])->value('real_name'); } } $filename = '报警记录_' . date('YmdHis', time()) . '.xls'; $header = [ ['title' => '设备名称', 'name' => 'security_name','width'=>'30'], ['title' => '报警时间', 'name' => 'alarm_time','width'=>'20'], ['title' => '状态', 'name' => 'statusTxt','width'=>'20'], ['title' => '处理人', 'name' => 'cf_user','width'=>'20'], ['title' => '处理时间', 'name' => 'update_time','width'=>'20'], ['title' => '备注', 'name' => 'remark','width'=>'20'], ]; ExcelUtil::export($filename,$header,$lists); } }