Log.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\LogModel;
  4. use think\Db;
  5. class Log extends Base
  6. {
  7. /**
  8. * [operate_log 操作日志]
  9. * @return [type] [description]
  10. * @author
  11. */
  12. public function operate_log()
  13. {
  14. $key = input('key');
  15. $start = input('start');
  16. $end = input('end');
  17. $arr=Db::name("admin")->column("id,username"); //获取用户列表
  18. if(request()->isAjax ()){
  19. $map = [];
  20. if($key&&$key!==""){
  21. $map['admin_id'] = $key;
  22. }
  23. if($start&&$start!==""&&$end=="")
  24. {
  25. $map['add_time'] = ['>= time',$start];
  26. }
  27. if($end&&$end!==""&&$start=="")
  28. {
  29. $map['add_time'] = ['<= time',$end];
  30. }
  31. if($start&&$start!==""&&$end&&$end!=="")
  32. {
  33. $map['add_time'] = ['between time',[$start,$end]];
  34. }
  35. $field=input('field');//字段
  36. $order=input('order');//排序方式
  37. if($field && $order){
  38. $od=$field." ".$order;
  39. }else{
  40. $od="add_time desc";
  41. }
  42. $Nowpage = input('get.page') ? input('get.page'):1;
  43. $limits = input("limit")?input("limit"):10;// 获取总条数;
  44. $count = Db::name('log')->where($map)->count();//计算总页面
  45. $lists = Db::name('log')->where($map)->page($Nowpage, $limits)->order($od)->select();
  46. return json(['code'=>220,'msg'=>'','count'=>$count,'data'=>$lists]);
  47. }
  48. $this->assign('val', $key);
  49. $this->assign("search_user",$arr);
  50. return $this->fetch();
  51. }
  52. /**
  53. * [del_log 删除日志]
  54. * @return [type] [description]
  55. * @author
  56. */
  57. public function del_log()
  58. {
  59. $id = input('param.id');
  60. $log = new LogModel();
  61. $flag = $log->delLog($id);
  62. return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
  63. }
  64. /**
  65. * batchDelLog 批量删除日志
  66. * @return \think\response\Json
  67. */
  68. public function batchDelLog(){
  69. extract(input());
  70. if(empty($ids)){
  71. return json(['code'=>100,'msg'=>'请选择要删除的记录!']);
  72. }
  73. $log = new LogModel();
  74. $flag = $log->batchDelLog($ids);
  75. return json(['code' => $flag['code'], 'msg' => $flag['msg']]);
  76. }
  77. }