diff --git a/app/Models/UsernameBlacklist.php b/app/Models/UsernameBlacklist.php index 91c1c76..5ac0284 100644 --- a/app/Models/UsernameBlacklist.php +++ b/app/Models/UsernameBlacklist.php @@ -50,17 +50,24 @@ class UsernameBlacklist extends Model */ public static function isBlocked(string $username): bool { - return static::where('username', $username) - ->where(function ($q) { - // 永久禁用 - $q->where('type', 'permanent') - // 或:临时保留且尚未到期 - ->orWhere(function ($q2) { - $q2->where('type', 'temp') - ->where('reserved_until', '>', now()); - }); - }) + // 1. 检查是否存在精确匹配且未过期的“临时改名保留”名称 + $hasTemp = static::where('type', 'temp') + ->where('username', $username) + ->where('reserved_until', '>', now()) ->exists(); + + if ($hasTemp) { + return true; + } + + // 2. 检查永久禁用词,改为【模糊匹配】(只要新注册的名字中包含禁用词,拦截) + // 比如数据库禁用了 "admin",那么 "admin123" 也会触发拦截 + $hasPermanent = static::where('type', 'permanent') + ->where('username', '!=', '') + ->whereRaw('? LIKE CONCAT("%", username, "%")', [$username]) + ->exists(); + + return $hasPermanent; } /**