Adminlog.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * lemocms
  4. * ============================================================================
  5. * 版权所有 2018-2027 lemocms,并保留所有权利。
  6. * 网站地址: https://www.lemocms.com
  7. * ----------------------------------------------------------------------------
  8. * 采用最新Thinkphp6实现
  9. * ============================================================================
  10. * Author: yuege
  11. * Date: 2019/8/2
  12. */
  13. namespace app\admin\controller;
  14. use app\common\controller\Backend;
  15. use think\facade\Config;
  16. use think\facade\Request;
  17. use app\admin\model\AdminLog as LogModel;
  18. use think\facade\View;
  19. class Adminlog extends Backend {
  20. public function initialize()
  21. {
  22. parent::initialize(); // TODO: Change the autogenerated stub
  23. }
  24. /**
  25. * @return array|string
  26. * @throws \think\db\exception\DbException
  27. */
  28. public function index(){
  29. if(Request::isPost()){
  30. $keys=Request::post('keys','','trim');
  31. $page = Request::post('page')?Request::post('page'):1;
  32. $list = LogModel::where('status',1)
  33. ->where('username|log_title','like','%'.$keys.'%')
  34. ->order('id desc')
  35. ->paginate(array('list_rows'=> $this->pageSize,'page'=>$page))
  36. ->toArray();
  37. if(!empty($list['data'])){
  38. foreach ($list['data'] as $k => $v) {
  39. $useragent = explode('(', $v['log_agent']);
  40. $list['data'][$k]['log_agent'] = $useragent[0];
  41. }
  42. }
  43. $result = ['code'=>0,'msg'=>lang('get info success'),'data'=>$list['data'],'count'=>$list['total']];
  44. return $result;
  45. }
  46. return View::fetch();
  47. }
  48. /**
  49. * @throws \Exception
  50. * 删除日志 单个+批量
  51. */
  52. public function delete(){
  53. $id = Request::post('id');
  54. if(!$id){
  55. $this->error(lang('id is not exist'));
  56. }
  57. if(!is_array($id)){
  58. $id = [$id];
  59. }
  60. if(LogModel::destroy($id)){
  61. $this->success(lang('delete success'));
  62. }else{
  63. $this->error(lang('delete fail'));
  64. }
  65. }
  66. }