diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 607c7bd..c3139b8 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -74,9 +74,16 @@ class UserController extends Controller try { $position = Location::get($ipToLookup); if ($position) { + $region = $this->translateLocation($position->regionName ?? ''); + $city = $this->translateLocation($position->cityName ?? ''); + $data['location'] = ($position->countryName === 'China' || $position->countryName === 'Local') ? - ($position->regionName ?? '') . ' ' . ($position->cityName ?? '') : - $position->countryName; + trim($region . ' ' . ($region === $city ? '' : $city)) : + $this->translateLocation($position->countryName ?? ''); + + if (empty($data['location'])) { + $data['location'] = '未知区域'; + } } else { $data['location'] = '未知区域'; } @@ -84,7 +91,7 @@ class UserController extends Controller $data['location'] = '解析失败'; } } else { - $data['location'] = 'IP解析库未安装'; + $data['location'] = '未安装IP库'; } } else { $data['location'] = '暂无记录'; @@ -320,4 +327,53 @@ class UserController extends Controller return response()->json(['status' => 'success', 'message' => "用户 {$username} 已被封号并封IP{$ipInfo}。"]); } + + /** + * 将英文省市名称简单翻译为中文 + */ + private function translateLocation(string $name): string + { + if (empty($name)) return ''; + + $map = [ + 'China' => '中国', + 'Beijing' => '北京', + 'Shanghai' => '上海', + 'Tianjin' => '天津', + 'Chongqing' => '重庆', + 'Hebei' => '河北', + 'Shanxi' => '山西', + 'Liaoning' => '辽宁', + 'Jilin' => '吉林', + 'Heilongjiang' => '黑龙江', + 'Jiangsu' => '江苏', + 'Zhejiang' => '浙江', + 'Anhui' => '安徽', + 'Fujian' => '福建', + 'Jiangxi' => '江西', + 'Shandong' => '山东', + 'Henan' => '河南', + 'Hubei' => '湖北', + 'Hunan' => '湖南', + 'Guangdong' => '广东', + 'Hainan' => '海南', + 'Sichuan' => '四川', + 'Guizhou' => '贵州', + 'Yunnan' => '云南', + 'Shaanxi' => '陕西', + 'Gansu' => '甘肃', + 'Qinghai' => '青海', + 'Taiwan' => '台湾', + 'Inner Mongolia' => '内蒙古', + 'Guangxi' => '广西', + 'Tibet' => '西藏', + 'Ningxia' => '宁夏', + 'Xinjiang' => '新疆', + 'Hong Kong' => '香港', + 'Macau' => '澳门', + 'Local' => '本地局域网', + ]; + + return $map[$name] ?? $name; + } } diff --git a/resources/views/chat/partials/user-actions.blade.php b/resources/views/chat/partials/user-actions.blade.php index 1408fc7..86ae0fb 100644 --- a/resources/views/chat/partials/user-actions.blade.php +++ b/resources/views/chat/partials/user-actions.blade.php @@ -332,25 +332,25 @@ {{-- 详细信息区 (等级高看等级低,或自己看自己时才有这些字段) --}}
+ style="margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;">
- 经验 + style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; justify-content: center;"> + 经验 + style="font-weight: 700; color: #4f46e5; font-size: 14px;">
- 金币 - + style="background: #fdfae8; border: 1px solid #fef08a; border-radius: 8px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; justify-content: center;"> + 金币 +
- 魅力 - + style="background: #fdf2f8; border: 1px solid #fbcfe8; border-radius: 8px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; justify-content: center;"> + 魅力 +