AdminlogController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-04-30
  10. // +—————————————————————————————————————————————————————————————————————
  11. /**
  12. * 管理员日志
  13. */
  14. namespace app\admin\controller;
  15. use cmf\controller\AdminBaseController;
  16. use think\Db;
  17. class AdminlogController extends AdminbaseController {
  18. function index(){
  19. $data = $this->request->param();
  20. $map=[];
  21. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  22. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  23. if($start_time!=""){
  24. $map[]=['addtime','>=',strtotime($start_time)];
  25. }
  26. if($end_time!=""){
  27. $map[]=['addtime','<=',strtotime($end_time) + 60*60*24];
  28. }
  29. $adminid=isset($data['adminid']) ? $data['adminid']: '';
  30. if($adminid!=''){
  31. $map[]=['adminid','=',$adminid];
  32. }
  33. $lists = Db::name("admin_log")
  34. ->where($map)
  35. ->order("id DESC")
  36. ->paginate(20);
  37. $lists->appends($data);
  38. $page = $lists->render();
  39. $this->assign('lists', $lists);
  40. $this->assign("page", $page);
  41. return $this->fetch();
  42. }
  43. function del(){
  44. $id = $this->request->param('id', 0, 'intval');
  45. $rs = DB::name('admin_log')->where("id={$id}")->delete();
  46. if(!$rs){
  47. $this->error("删除失败!");
  48. }
  49. $this->success("删除成功!");
  50. }
  51. function export(){
  52. $data = $this->request->param();
  53. $map=[];
  54. $start_time=isset($data['start_time']) ? $data['start_time']: '';
  55. $end_time=isset($data['end_time']) ? $data['end_time']: '';
  56. if($start_time!=""){
  57. $map[]=['addtime','>=',strtotime($start_time)];
  58. }
  59. if($end_time!=""){
  60. $map[]=['addtime','<=',strtotime($end_time) + 60*60*24];
  61. }
  62. $adminid=isset($data['adminid']) ? $data['adminid']: '';
  63. if($adminid!=''){
  64. $map[]=['adminid','=',$adminid];
  65. }
  66. $xlsName = "管理员日志";
  67. $xlsData=Db::name("admin_log")->where($map)->order("addtime DESC")->select()->toArray();
  68. foreach ($xlsData as $k => $v)
  69. {
  70. $xlsData[$k]['ip']=long2ip($v['ip']);
  71. $xlsData[$k]['addtime']=date("Y-m-d H:i:s",$v['addtime']);
  72. }
  73. $cellName = array('A','B','C','D','E');
  74. $xlsCell = array(
  75. array('id','序号'),
  76. array('admin','管理员'),
  77. array('action','行为'),
  78. array('ip','IP'),
  79. array('addtime','提交时间'),
  80. );
  81. exportExcel($xlsName,$xlsCell,$xlsData,$cellName);
  82. }
  83. }