SecurityRecord.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\util\ExcelUtil;
  4. use think\Db;
  5. class SecurityRecord extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','sort','trim'); //排序列
  15. $sort = input('sord','asc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort.' ,id desc';
  17. $title = input('title','','trim');
  18. if($title !=''){
  19. $securityId = Db::name('security')->where('del',0)->where('org_id',cur_org_id())->where('title','like','%'.$title.'%')->column('id');
  20. $map[] = ['security_id','in',$securityId];
  21. }
  22. $b = input('start', '', 'trim');
  23. $e = input('end', '', 'trim');
  24. if ($b) {
  25. $map[] = ['create_time', '>=', $b.' 00:00:00'];
  26. }
  27. if ($e) {
  28. $map[] = ['create_time', '<=', $e.' 23:59:59'];
  29. }
  30. $status = input('status','','trim');
  31. if($status != ''){
  32. $map[] = ['status','=',$status];
  33. }
  34. $map[] = ['org_id','=',cur_org_id()];
  35. $map= empty($map) ? true: $map;
  36. //数据查询
  37. $lists = Db::name('security_record')->where($map)->limit($start,$length)->order('id desc')->select();
  38. foreach ($lists as $k=>$v){
  39. $lists[$k]['security_name'] = Db::name('security')->where('id',$v['security_id'])->value('title');
  40. $lists[$k]['cf_user'] = '';
  41. if($v['cf_user_id'] > 0){
  42. $lists[$k]['cf_user'] = Db::name('user')->where('id',$v['cf_user_id'])->value('real_name');
  43. }
  44. }
  45. //数据返回
  46. $totalCount = Db::name('security_record')->where($map)->count();
  47. $totalPage = ceil($totalCount/$length);
  48. $result['page'] = $page;
  49. $result['total'] = $totalPage;
  50. $result['records'] = $totalCount;
  51. $result['rows'] = $lists;
  52. return json($result);
  53. }else{
  54. $this->assign('meta_title','报警记录列表');
  55. return $this->fetch();
  56. }
  57. }
  58. public function check($id=0){
  59. if(request()->isPost()){
  60. $remark = input('remark','','trim');
  61. if(!$remark){
  62. $this->error('备注不能为空');
  63. }
  64. $save = Db::name('security_record')->where('id',$id)->update(['status'=>1,'update_time'=>date('Y-m-d H:i:s'),'remark'=>$remark]);
  65. if(!$save){
  66. $this->error('操作失败');
  67. }
  68. // model('ActionLog')->addlog(is_login(),33,'报警记录:处理',['id' => $id],cur_org_id());
  69. $this->success('操作成功');
  70. }else{
  71. $this->assign('id',$id);
  72. return $this->fetch();
  73. }
  74. }
  75. public function export(){
  76. $title = input('title','','trim');
  77. if($title !=''){
  78. $securityId = Db::name('security')->where('del',0)->where('org_id',cur_org_id())->where('title','like','%'.$title.'%')->column('id');
  79. $map[] = ['security_id','in',$securityId];
  80. }
  81. $b = input('start', '', 'trim');
  82. $e = input('end', '', 'trim');
  83. if ($b) {
  84. $map[] = ['create_time', '>=', $b.' 00:00:00'];
  85. }
  86. if ($e) {
  87. $map[] = ['create_time', '<=', $e.' 23:59:59'];
  88. }
  89. $status = input('status','','trim');
  90. if($status != ''){
  91. $map[] = ['status','=',$status];
  92. }
  93. $map[] = ['org_id','=',cur_org_id()];
  94. $map= empty($map) ? true: $map;
  95. //数据查询
  96. $lists = Db::name('security_record')->where($map)->order('id desc')->select();
  97. foreach ($lists as $k=>$v){
  98. $lists[$k]['security_name'] = Db::name('security')->where('id',$v['security_id'])->value('title');
  99. $lists[$k]['cf_user'] = '';
  100. $lists[$k]['statusTxt'] = $v['status']==0?'未处理':'已处理';
  101. if($v['cf_user_id'] > 0){
  102. $lists[$k]['cf_user'] = Db::name('user')->where('id',$v['cf_user_id'])->value('real_name');
  103. }
  104. }
  105. $filename = '报警记录_' . date('YmdHis', time()) . '.xls';
  106. $header = [
  107. ['title' => '设备名称', 'name' => 'security_name','width'=>'30'],
  108. ['title' => '报警时间', 'name' => 'alarm_time','width'=>'20'],
  109. ['title' => '状态', 'name' => 'statusTxt','width'=>'20'],
  110. ['title' => '处理人', 'name' => 'cf_user','width'=>'20'],
  111. ['title' => '处理时间', 'name' => 'update_time','width'=>'20'],
  112. ['title' => '备注', 'name' => 'remark','width'=>'20'],
  113. ];
  114. ExcelUtil::export($filename,$header,$lists);
  115. }
  116. }