refactor: 使用 ApiMessage 统一错误响应格式

- 在多个控制器中引入 ApiMessage,替换原有的 ApiResponse 错误处理逻辑,确保错误信息的一致性与可读性。
- 更新错误返回信息,使用更具语义的键值,提升 API 的可维护性与用户体验。
- 适配相关控制器的请求参数,确保在处理错误时能够正确返回相应的错误信息。
This commit is contained in:
2026-06-01 14:23:48 +08:00
parent e547e2b4a6
commit e6cf94af46
59 changed files with 518 additions and 230 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Support;
use App\Lottery\ErrorCode;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* 对外 API 统一 JSON 结构:{ code, msg, data }
@@ -13,11 +14,11 @@ use Illuminate\Http\JsonResponse;
*/
final class ApiResponse
{
public static function success(mixed $data = null, string $msg = 'ok', int $code = 0): JsonResponse
public static function success(mixed $data = null, ?string $msg = null, int $code = 0, ?Request $request = null): JsonResponse
{
return response()->json([
'code' => $code,
'msg' => $msg,
'msg' => $msg ?? ApiMessage::successMessage($request),
'data' => $data,
]);
}