- 在多个控制器中引入 ApiMessage,替换原有的 ApiResponse 错误处理逻辑,确保错误信息的一致性与可读性。 - 更新错误返回信息,使用更具语义的键值,提升 API 的可维护性与用户体验。 - 适配相关控制器的请求参数,确保在处理错误时能够正确返回相应的错误信息。
38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
use App\Lottery\ErrorCode;
|
||
use Illuminate\Http\Request;
|
||
|
||
/**
|
||
* 【业务文案翻译辅助类】
|
||
*
|
||
* 从 lang/{locale}/sso.php 等语言包取字符串,供 JSON 里「msg」字段使用。
|
||
* `App\Lottery\ErrorCode` 中玩家 SSO 段(8001–8005)的各语言 `msg`。
|
||
*
|
||
* 依赖 NegotiateLotteryLocale 已写入 lottery_locale;若未写则使用 fallback 语言包。
|
||
*/
|
||
final class LotteryMessage
|
||
{
|
||
/**
|
||
* 取钱包划转类错误的用户可见文案(lang/{locale}/wallet.php 键名为数字错误码)。
|
||
*
|
||
* @param int $code {@see ErrorCode} 钱包段(1001–1010 等与钱包相关的业务码)
|
||
*/
|
||
public static function wallet(Request $request, int $code): string
|
||
{
|
||
return ApiMessage::get($request, 'wallet.'.$code);
|
||
}
|
||
|
||
/**
|
||
* 取 SSO 鉴权类错误的用户可见文案(与 ApiResponse 的 msg 对应)。
|
||
*
|
||
* @param int $code {@see ErrorCode} 玩家 SSO 段(8001–8005)
|
||
*/
|
||
public static function sso(Request $request, int $code): string
|
||
{
|
||
return ApiMessage::get($request, 'sso.'.$code);
|
||
}
|
||
}
|