mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-03 11:09:27 +00:00
Fixed sometime getIPInfo return will cause error
This commit is contained in:
@@ -172,15 +172,17 @@ class LogsController extends Controller
|
||||
});
|
||||
|
||||
$onlineIPLogs = $query->groupBy(['user_id', 'node_id'])->latest()->paginate(20)->appends($request->except('page'));
|
||||
foreach ($onlineIPLogs as $log) {
|
||||
// 跳过上报多IP的
|
||||
if ($log->ip === null || str_contains($log->ip, ',')) {
|
||||
continue;
|
||||
// 提前过滤 IP 数据以减少循环中的判断
|
||||
$onlineIPLogs->transform(function ($log) {
|
||||
if ($log->ip && ! str_contains($log->ip, ',')) {
|
||||
$ipInfo = IP::getIPInfo($log->ip);
|
||||
if ($ipInfo) {
|
||||
$log->ipInfo = $ipInfo['address'].' '.$ipInfo['isp'];
|
||||
}
|
||||
}
|
||||
$ipInfo = IP::getIPInfo($log->ip);
|
||||
|
||||
$log->ipInfo = $ipInfo['address'].' '.$ipInfo['isp'];
|
||||
}
|
||||
return $log;
|
||||
});
|
||||
|
||||
return view('admin.logs.onlineIPMonitor', [
|
||||
'onlineIPLogs' => $onlineIPLogs,
|
||||
|
||||
@@ -46,13 +46,13 @@ class SubscribeController extends Controller
|
||||
$query->whereBetween('request_time', [$request->input('start').' 00:00:00', $request->input('end').' 23:59:59']);
|
||||
}
|
||||
|
||||
$subscribeLogs = $query->latest()->paginate(20)->appends($request->except('page'));
|
||||
foreach ($subscribeLogs as $log) {
|
||||
// 跳过上报多IP的
|
||||
$subscribeLogs = $query->latest()->paginate(20)->appends($request->except('page'))->transform(function ($log) {
|
||||
if ($log->request_ip) {
|
||||
$log->ipInfo = IP::getIPInfo($log->request_ip)['address'] ?? null;
|
||||
$log->ipInfo = optional(IP::getIPInfo($log->request_ip))['address'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
return $log;
|
||||
});
|
||||
|
||||
return view('admin.subscribe.log', ['subscribeLog' => $subscribeLogs, 'subscribe' => $userSubscribe]);
|
||||
}
|
||||
|
||||
@@ -251,22 +251,25 @@ class Helpers
|
||||
{
|
||||
$ipLocation = IP::getIPInfo($ip);
|
||||
|
||||
if (empty($ipLocation)) {
|
||||
$logData = [
|
||||
'user_id' => $user->id,
|
||||
'ip' => $ip,
|
||||
'country' => $ipLocation['country'] ?? '',
|
||||
'province' => $ipLocation['region'] ?? '',
|
||||
'city' => $ipLocation['city'] ?? '',
|
||||
'county' => '', // 未使用的字段
|
||||
'isp' => $ipLocation['isp'] ?? '',
|
||||
'area' => $ipLocation['area'] ?? '',
|
||||
];
|
||||
|
||||
// 记录错误日志仅在 IP 信息无效时
|
||||
if (! $ipLocation) {
|
||||
Log::warning(trans('errors.get_ip').':'.$ip);
|
||||
}
|
||||
|
||||
$log = new UserLoginLog;
|
||||
$log->user_id = $user->id;
|
||||
$log->ip = $ip;
|
||||
$log->country = $ipLocation['country'] ?? '';
|
||||
$log->province = $ipLocation['region'] ?? '';
|
||||
$log->city = $ipLocation['city'] ?? '';
|
||||
$log->county = '';
|
||||
$log->isp = $ipLocation['isp'] ?? '';
|
||||
$log->area = $ipLocation['area'] ?? '';
|
||||
$log->save();
|
||||
|
||||
$user->update(['last_login' => time()]); // 更新登录信息
|
||||
// 批量插入日志记录并更新用户登录时间
|
||||
UserLoginLog::create($logData);
|
||||
$user->update(['last_login' => time()]);
|
||||
}
|
||||
|
||||
public static function getPriceTag(int|float $amount): string
|
||||
|
||||
Reference in New Issue
Block a user