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,7 +4,9 @@ namespace App\Http\Controllers\Api\V1\Admin\Currency;
use App\Models\Currency;
use App\Lottery\ErrorCode;
use App\Support\ApiMessage;
use App\Support\ApiResponse;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\DB;
use App\Services\LotterySettings;
@@ -12,26 +14,23 @@ use App\Http\Controllers\Controller;
final class AdminCurrencyDestroyController extends Controller
{
public function __invoke(Currency $currency): JsonResponse
public function __invoke(Request $request, Currency $currency): JsonResponse
{
$code = strtoupper((string) $currency->code);
if ($code === LotterySettings::defaultCurrency()) {
return ApiResponse::error(
'默认币种不可删除',
ErrorCode::ValidationFailed->value,
null,
422,
);
return ApiMessage::errorResponse($request, 'admin.currency_default_cannot_delete', ErrorCode::ValidationFailed->value, null, 422);
}
$references = $this->referenceSummary($code);
if ($references !== []) {
return ApiResponse::error(
'该币种已被业务数据引用,暂不可删除:'.implode('、', $references),
return ApiMessage::errorResponse(
$request,
'admin.currency_referenced_cannot_delete',
ErrorCode::ValidationFailed->value,
['references' => $references],
422,
['refs' => implode('、', $references)],
);
}