Files
lotteryLaravel/app/Http/Controllers/Api/V1/Play/PlayEffectiveCatalogController.php
kang e6cf94af46 refactor: 使用 ApiMessage 统一错误响应格式
- 在多个控制器中引入 ApiMessage,替换原有的 ApiResponse 错误处理逻辑,确保错误信息的一致性与可读性。
- 更新错误返回信息,使用更具语义的键值,提升 API 的可维护性与用户体验。
- 适配相关控制器的请求参数,确保在处理错误时能够正确返回相应的错误信息。
2026-06-01 14:23:48 +08:00

37 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1\Play;
use App\Lottery\ErrorCode;
use App\Support\ApiMessage;
use App\Support\ApiResponse;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Services\Config\EffectivePlayCatalogService;
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
* GET /api/v1/play/effective — 当前生效的玩法目录 + 赔率 + 封顶(公开,无需登录)。
*/
final class PlayEffectiveCatalogController extends Controller
{
public function __invoke(Request $request, EffectivePlayCatalogService $catalog): JsonResponse
{
$currency = $request->query('currency');
$c = is_string($currency) && $currency !== '' ? $currency : null;
try {
return ApiResponse::success($catalog->build($c));
} catch (ModelNotFoundException) {
return ApiMessage::errorResponse($request, 'effective_config_not_initialized', ErrorCode::NotFound->value, null, 404);
} catch (\InvalidArgumentException $e) {
if ($e->getMessage() === 'currency') {
return ApiMessage::errorResponse($request, 'invalid_or_disabled_currency', ErrorCode::ConfigCurrencyInvalid->value, null, 400);
}
throw $e;
}
}
}