Log.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\controller;
  9. use app\admin\BaseController;
  10. use think\facade\Db;
  11. use think\facade\View;
  12. class Log extends BaseController
  13. {
  14. //管理员操作日志
  15. public function index()
  16. {
  17. if (request()->isAjax()) {
  18. $param = get_params();
  19. $where = array();
  20. if (!empty($param['keywords'])) {
  21. $where[] = ['nickname|content|param_id', 'like', '%' . $param['keywords'] . '%'];
  22. }
  23. if (!empty($param['action'])) {
  24. $where['action'] = $param['action'];
  25. }
  26. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  27. $content = DB::name('AdminLog')
  28. ->field("id,uid,nickname,action,title,content,rule_menu,ip,param_id,param,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') create_time")
  29. ->order('create_time desc')
  30. ->where($where)
  31. ->paginate($rows, false, ['query' => $param]);
  32. $content->toArray();
  33. foreach ($content as $k => $v) {
  34. $data = $v;
  35. $param_array = json_decode($v['param'], true);
  36. if(is_array($param_array)){
  37. $param_value = '';
  38. foreach ($param_array as $key => $value) {
  39. if (is_array($value)) {
  40. $value = implode(',', $value);
  41. }
  42. $param_value .= $key . ':' . $value . '&nbsp;&nbsp;|&nbsp;&nbsp;';
  43. }
  44. $data['param'] = $param_value;
  45. }
  46. else{
  47. $data['param'] = $param_array;
  48. }
  49. $content->offsetSet($k, $data);
  50. }
  51. return table_assign(0, '', $content);
  52. } else {
  53. $type_action = get_config('log.admin_action');
  54. View::assign('type_action', $type_action);
  55. return view();
  56. }
  57. }
  58. }