refactor:拆分 API 路由与请求校验,统一 final 类和代码风格

This commit is contained in:
2026-05-13 11:54:40 +08:00
parent 5d2dbdbe1d
commit 805847954d
281 changed files with 1886 additions and 1308 deletions

View File

@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);
namespace App\Support;
use App\Lottery\ErrorCode;
use Illuminate\Http\Request;
/**
* 【管理后台业务文案翻译辅助类】
*
* lang/{locale}/admin.php 等语言包取字符串,供 JSON 里「msg」字段使用。
* LotteryMessage 对应,专门处理管理端错误消息。
*/
final class AdminMessage
{
/**
* 取通用管理后台错误的用户可见文案lang/{locale}/admin.php
*
* @param string $key 语言包键名,如 'unauthenticated', 'permission_denied'
*/
public static function get(Request $request, string $key): string
{
$fallback = (string) config('lottery.locales.fallback', 'en');
$locale = (string) ($request->attributes->get('lottery_locale') ?? LotteryLocale::resolve($request));
$fullKey = 'admin.'.$key;
$msg = trans($fullKey, [], $locale);
if ($msg !== $fullKey) {
return $msg;
}
return trans($fullKey, [], $fallback);
}
/**
* 取错误码对应的用户可见文案。
*
* @param int $code {@see ErrorCode} 管理端段81108114
*/
public static function errorCode(Request $request, int $code): string
{
$fallback = (string) config('lottery.locales.fallback', 'en');
$locale = (string) ($request->attributes->get('lottery_locale') ?? LotteryLocale::resolve($request));
$key = 'admin.'.$code;
$msg = trans($key, [], $locale);
if ($msg !== $key) {
return $msg;
}
return trans($key, [], $fallback);
}
}