AdminLog.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\admin\model;
  9. use dateset\Dateset;
  10. use think\Model;
  11. class AdminLog extends Model
  12. {
  13. public function get_log_list($param = [])
  14. {
  15. $where = array();
  16. if (!empty($param['no_delete'])) {
  17. $where['type'] = ['neq', 'delete']; //过滤删除操作
  18. }
  19. if (!empty($param['no_admin'])) {
  20. $where['uid'] = ['neq', 1]; //超级管理员删除操作
  21. }
  22. if (!empty($param['uid'])) {
  23. $where['uid'] = $param['uid']; //查询指定用户的操作
  24. }
  25. $where['status'] = 1;
  26. $rows = empty($param['limit']) ? get_config('app.pages') : $param['limit'];
  27. $content = \think\facade\Db::name('AdminLog')
  28. ->field("id,uid,nickname,type,title,module,controller,function,param,content,create_time")
  29. ->order('create_time desc')
  30. ->where($where)
  31. ->paginate($rows, false, ['query' => $param]);
  32. $content->toArray();
  33. $date_set = new Dateset();
  34. foreach ($content as $k => $v) {
  35. $data = $v;
  36. $param_array = json_decode($v['param'], true);
  37. $name = '';
  38. if (!empty($param_array['name'])) {
  39. $name = ':' . $param_array['name'];
  40. }
  41. if (!empty($param_array['title'])) {
  42. $name = ':' . $param_array['title'];
  43. }
  44. $data['content'] = $v['content'] . $name;
  45. $data['times'] = $date_set->time_trans($v['create_time']);
  46. $content->offsetSet($k, $data);
  47. }
  48. return $content;
  49. }
  50. }