Server : nginx/1.20.1 System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64 User : www ( 1000) PHP Version : 7.3.28 Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/0531yanglao.com/app/admin/controller/ |
<?php /* * @Description : 日志管理 * @Author : https://github.com/skyselang * @Date : 2020-05-06 * @LastEditTime : 2021-03-20 */ namespace app\admin\controller; use think\facade\Request; use app\admin\validate\AdminLogValidate; use app\admin\service\AdminLogService; use app\admin\service\AdminMenuService; use app\admin\service\AdminUserService; class AdminLog { /** * 日志列表 * * @method GET * * @return json */ public function logList() { $page = Request::param('page/d', 1); $limit = Request::param('limit/d', 10); $sort_field = Request::param('sort_field/s ', ''); $sort_type = Request::param('sort_type/s', ''); $log_type = Request::param('log_type/d', ''); $request_keyword = Request::param('request_keyword/s', ''); $user_keyword = Request::param('user_keyword/s', ''); $menu_keyword = Request::param('menu_keyword/s', ''); $create_time = Request::param('create_time/a', []); $response_code = Request::param('response_code/s', ''); $where = []; if ($log_type) { $where[] = ['log_type', '=', $log_type]; } if ($request_keyword) { $where[] = ['request_ip|request_region|request_isp', 'like', '%' . $request_keyword . '%']; } if ($user_keyword) { $admin_user = AdminUserService::etQuery($user_keyword); $admin_user_ids = array_column($admin_user, 'admin_user_id'); $where[] = ['admin_user_id', 'in', $admin_user_ids]; } if ($menu_keyword) { $admin_menu = AdminMenuService::etQuery($menu_keyword); $admin_menu_ids = array_column($admin_menu, 'admin_menu_id'); $where[] = ['admin_menu_id', 'in', $admin_menu_ids]; } if ($create_time) { $where[] = ['create_time', '>=', $create_time[0] . ' 00:00:00']; $where[] = ['create_time', '<=', $create_time[1] . ' 23:59:59']; } if ($response_code) { $where[] = ['response_code', '=', $response_code]; } $order = []; if ($sort_field && $sort_type) { $order = [$sort_field => $sort_type]; } $data = AdminLogService::list($where, $page, $limit, $order); return success($data); } /** * 日志信息 * * @method GET * * @return json */ public function logInfo() { $param['admin_log_id'] = Request::param('admin_log_id/d', ''); validate(AdminLogValidate::class)->scene('log_id')->check($param); $data = AdminLogService::info($param['admin_log_id']); if ($data['is_delete'] == 1) { exception('日志已被删除:' . $param['admin_log_id']); } return success($data); } /** * 日志删除 * * @method POST * * @return json */ public function logDele() { $param['admin_log_id'] = Request::param('admin_log_id/d', ''); validate(AdminLogValidate::class)->scene('log_dele')->check($param); $data = AdminLogService::dele($param['admin_log_id']); return success($data); } /** * 日志统计 * * @method POST * * @return json */ public function LogStatistic() { $type = Request::param('type/s', ''); $date = Request::param('date/a', []); $region = Request::param('region/s', 'city'); $data = []; $date_arr = ['total', 'today', 'yesterday', 'thisweek', 'lastweek', 'thismonth', 'lastmonth']; if ($type == 'number') { $number = []; foreach ($date_arr as $k => $v) { $number[$v] = AdminLogService::staNumber($v); } $data['number'] = $number; } elseif ($type == 'date') { $data['date'] = AdminLogService::staDate($date); } elseif ($type == 'region') { $data['region'] = AdminLogService::staRegion($date, $region); } else { $number = []; foreach ($date_arr as $k => $v) { $number[$v] = AdminLogService::staNumber($v); } $data['number'] = $number; $data['date'] = AdminLogService::staDate($date); $data['region'] = AdminLogService::staRegion($date, $region); } return success($data); } }