diff --git a/app/Console/Commands/AutoClearLogs.php b/app/Console/Commands/AutoClearLogs.php index 41a63f3e..7ca43f20 100644 --- a/app/Console/Commands/AutoClearLogs.php +++ b/app/Console/Commands/AutoClearLogs.php @@ -7,14 +7,10 @@ use App\Models\NodeHeartbeat; use App\Models\NodeHourlyDataFlow; use App\Models\NodeOnlineIp; use App\Models\NodeOnlineLog; -use App\Models\NotificationLog; -use App\Models\Payment; use App\Models\RuleLog; -use App\Models\UserBanedLog; use App\Models\UserDailyDataFlow; use App\Models\UserDataFlowLog; use App\Models\UserHourlyDataFlow; -use App\Models\UserLoginLog; use App\Models\UserSubscribeLog; use Exception; use Illuminate\Console\Command; @@ -41,50 +37,28 @@ class AutoClearLogs extends Command private function clearLog() { try { - // 清除节点每天流量数据日志 - NodeDailyDataFlow::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.node_daily_logs'))))->delete(); + NodeDailyDataFlow::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.node_daily_logs'))))->delete(); // 清除节点每天流量数据日志 - // 清除节点每小时流量数据日志 - NodeHourlyDataFlow::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.node_hourly_logs'))))->delete(); + NodeHourlyDataFlow::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.node_hourly_logs'))))->delete(); // 清除节点每小时流量数据日志 - // 清理通知日志 - NotificationLog::where('updated_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.notification_logs'))))->delete(); + NodeHeartbeat::where('log_time', '<=', strtotime(config('tasks.clean.node_heartbeats')))->delete(); // 清除节点负载信息日志 - // 清除节点负载信息日志 - NodeHeartbeat::where('log_time', '<=', strtotime(config('tasks.clean.node_heartbeats')))->delete(); + NodeOnlineLog::where('log_time', '<=', strtotime(config('tasks.clean.node_online_logs')))->delete(); // 清除节点在线用户数日志 - // 清除节点在线用户数日志 - NodeOnlineLog::where('log_time', '<=', strtotime(config('tasks.clean.node_online_logs')))->delete(); + RuleLog::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.rule_logs'))))->delete(); // 清理审计触发日志 - // 清理在线支付日志 - Payment::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.payments'))))->delete(); + NodeOnlineIp::where('created_at', '<=', strtotime(config('tasks.clean.node_online_ips')))->delete(); // 清除用户连接IP - // 清理审计触发日志 - RuleLog::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.rule_logs'))))->delete(); - - // 清除用户连接IP - NodeOnlineIp::where('created_at', '<=', strtotime(config('tasks.clean.node_online_ips')))->delete(); - - // 清除用户封禁日志 - UserBanedLog::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.user_baned_logs'))))->delete(); - - // 清除用户各节点 / 节点总计的每天流量数据日志 UserDailyDataFlow::where('node_id', '<>', null) ->where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.user_daily_logs_nodes')))) ->orWhere('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.user_daily_logs_total')))) - ->delete(); + ->delete(); // 清除用户各节点 / 节点总计的每天流量数据日志 - // 清除用户每时各流量数据日志 - UserHourlyDataFlow::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.user_hourly_logs'))))->delete(); + UserHourlyDataFlow::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.user_hourly_logs'))))->delete(); // 清除用户每时各流量数据日志 - // 清除用户登陆日志 - UserLoginLog::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.login_logs'))))->delete(); // 清除用户订阅记录 + UserSubscribeLog::where('request_time', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.subscribe_logs'))))->delete(); // 清理用户订阅请求日志 - // 清理用户订阅请求日志 - UserSubscribeLog::where('request_time', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.subscribe_logs'))))->delete(); - - // 清除用户流量日志 - UserDataFlowLog::where('log_time', '<=', strtotime(config('tasks.clean.traffic_logs')))->delete(); + UserDataFlowLog::where('log_time', '<=', strtotime(config('tasks.clean.traffic_logs')))->delete(); // 清除用户流量日志 } catch (Exception $e) { Log::emergency('【清理日志】错误: '.$e->getMessage()); } diff --git a/app/Console/Commands/TaskMonthly.php b/app/Console/Commands/TaskMonthly.php index fef175a0..6c82f373 100644 --- a/app/Console/Commands/TaskMonthly.php +++ b/app/Console/Commands/TaskMonthly.php @@ -2,7 +2,13 @@ namespace App\Console\Commands; +use App\Models\NotificationLog; +use App\Models\Order; +use App\Models\Payment; use App\Models\User; +use App\Models\UserBanedLog; +use App\Models\UserLoginLog; +use Exception; use Illuminate\Console\Command; use Log; @@ -16,8 +22,10 @@ class TaskMonthly extends Command { $jobTime = microtime(true); - if (sysConfig('data_exhaust_notification')) { - $this->cleanAccounts(); // 用户流量超过警告阈值提醒 + $this->cleanAccounts(); // 清理僵尸账号 + + if (sysConfig('is_clear_log')) { + $this->clearLog(); // 清除小日志 } $jobTime = round(microtime(true) - $jobTime, 4); @@ -26,8 +34,24 @@ class TaskMonthly extends Command private function cleanAccounts() { - // 账号遗留结算的流量 User::where('expired_at', '<', date('Y-m-d'))->where('transfer_enable', '==', 0)->whereEnable(0) ->whereRaw('u + d > transfer_enable')->update(['u' => 0, 'd' => 0]); } + + private function clearLog() + { + try { + NotificationLog::where('updated_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.notification_logs'))))->delete(); // 清理通知日志 + + UserLoginLog::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.login_logs'))))->delete(); // 清除用户登陆日志 + + Payment::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.payments'))))->delete(); // 清理在线支付日志 + + UserBanedLog::where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.user_baned_logs'))))->delete(); // 清理用户封禁日志 + + Order::whereStatus(-1)->where('created_at', '<=', date('Y-m-d H:i:s', strtotime(config('tasks.clean.unpaid_orders'))))->delete(); // 清理用户未支付订单 + } catch (Exception $e) { + Log::emergency('【清理日志】错误: '.$e->getMessage()); + } + } } diff --git a/config/tasks.php b/config/tasks.php index 758fd5d4..71530dec 100644 --- a/config/tasks.php +++ b/config/tasks.php @@ -18,6 +18,7 @@ return [ 'login_logs' => env('TASKS_LOGIN_LOGS', '-3 month'), // 清除用户登陆日志 'subscribe_logs' => env('TASKS_SUBSCRIBE_LOGS', '-1 month'), // 清理用户订阅请求日志 'traffic_logs' => env('TASKS_TRAFFIC_LOGS', '-3 days'), // 清除用户流量日志 + 'unpaid_orders' => env('UNPAID_ORDERS', '-1 year'), // 清除用户流量日志 ], 'close' => [ 'tickets' => env('TASKS_TICKETS', 72), // 自动关闭工单,单位:小时 diff --git a/resources/views/user/layouts.blade.php b/resources/views/user/layouts.blade.php index 299ee5c3..3f219511 100644 --- a/resources/views/user/layouts.blade.php +++ b/resources/views/user/layouts.blade.php @@ -118,7 +118,7 @@ {{trans('user.menu.nodes')}} -