logs.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class logs extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '管理员登录日志');
  12. $uname = $this->req->get('uname');
  13. $ip = $this->req->get('ip');
  14. $fdate = $this->req->get('fdate');
  15. $tdate = $this->req->get('tdate');
  16. $cons = '';
  17. $consArr = array();
  18. if ($uname) {
  19. $cons .= $cons ? ' AND ' : '';
  20. $admin = $this->model()->select('id')->from('admin')->where(array('fields' => 'adminname=?', 'values' => array($uname)))->fetchRow();
  21. $cons .= 'a.adminid = ?';
  22. $consArr[] = $admin['id'];
  23. }
  24. if ($ip) {
  25. $cons .= $cons ? ' AND ' : '';
  26. $cons .= 'a.ip like ?';
  27. $consArr[] = '%' . $ip . '%';
  28. }
  29. if ($fdate) {
  30. $cons .= $cons ? ' AND ' : '';
  31. $cons .= 'a.addtime >= ?';
  32. $consArr[] = strtotime($fdate);
  33. }
  34. if ($tdate) {
  35. $cons .= $cons ? ' AND ' : '';
  36. $cons .= 'a.addtime <= ?';
  37. $consArr[] = strtotime($tdate . ' 23:59:59');
  38. }
  39. $page = $this->req->get('p');
  40. $page = $page ? $page : 1;
  41. $pagesize = 20;
  42. $lists = array();
  43. $totalsize = $this->model()->from('adminlogs a')->where(array('fields' => $cons, 'values' => $consArr))->count();
  44. if ($totalsize) {
  45. $totalpage = ceil($totalsize / $pagesize);
  46. $page = $page > $totalpage ? $totalpage : $page;
  47. $offset = ($page - 1) * $pagesize;
  48. $lists = $this->model()->select('a.*,c.adminname')->from('adminlogs a')->limit($pagesize)->left('admin c')->on('c.id=a.adminid')->join()->offset($offset)->orderby('a.id desc')->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  49. }
  50. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?uname=' . $uname . '&ip=' . $ip . '&fdate=' . $fdate . '&tdate=' . $tdate . '&p='));
  51. $data += array('lists' => $lists, 'pagelist' => $pagelist, 'search' => array('uname' => $uname, 'ip' => $ip, 'fdate' => $fdate, 'tdate' => $tdate));
  52. $this->put('admlogs.php', $data);
  53. }
  54. public function del()
  55. {
  56. $id = $this->req->get('id');
  57. if ($id) {
  58. if ($this->model()->from('adminlogs')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  59. echo json_encode(array('status' => 1));
  60. exit;
  61. }
  62. }
  63. echo json_encode(array('status' => 0));
  64. exit;
  65. }
  66. }