|
|
@@ -4,6 +4,7 @@ namespace App\Module\OpenAPI\Handlers\Fund;
|
|
|
|
|
|
use App\Module\OpenAPI\Handlers\BaseHandler;
|
|
|
use App\Module\OpenAPI\Services\ScopeService;
|
|
|
+use App\Module\OpenAPI\Enums\SCOPE_TYPE;
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
|
/**
|
|
|
@@ -21,11 +22,11 @@ class FundBalanceHandler extends BaseHandler
|
|
|
/**
|
|
|
* 获取所需的权限范围
|
|
|
*
|
|
|
- * @return array
|
|
|
+ * @return SCOPE_TYPE[]
|
|
|
*/
|
|
|
public function getRequiredScopes(): array
|
|
|
{
|
|
|
- return ['FUND_READ'];
|
|
|
+ return [SCOPE_TYPE::FUND_READ];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -35,55 +36,40 @@ class FundBalanceHandler extends BaseHandler
|
|
|
* @param array $context 上下文信息
|
|
|
* @return JsonResponse
|
|
|
*/
|
|
|
- public function handle(array $data, array $context = []): JsonResponse
|
|
|
+ protected function process(array $data, array $context = []): JsonResponse
|
|
|
{
|
|
|
- try {
|
|
|
- // 验证权限
|
|
|
- $app = $this->getApp($context);
|
|
|
- if (!$app) {
|
|
|
- return $this->errorResponse('应用信息不存在', null, 404);
|
|
|
- }
|
|
|
-
|
|
|
- if (!$this->validatePermissions($app->scopes ?? [], $context)) {
|
|
|
- return $this->errorResponse('权限不足', null, 403);
|
|
|
- }
|
|
|
-
|
|
|
- // 验证请求参数
|
|
|
- $validationErrors = $this->validateData($data, [
|
|
|
- 'user_id' => 'required|integer|min:1',
|
|
|
- 'currency_types' => 'array',
|
|
|
- 'currency_types.*' => 'string|max:20',
|
|
|
- 'include_frozen' => 'boolean',
|
|
|
- ]);
|
|
|
-
|
|
|
- if ($validationErrors) {
|
|
|
- return $this->errorResponse('参数验证失败', $validationErrors, 422);
|
|
|
- }
|
|
|
-
|
|
|
- // 获取参数
|
|
|
- $userId = $data['user_id'];
|
|
|
- $currencyTypes = $data['currency_types'] ?? [];
|
|
|
- $includeFrozen = $data['include_frozen'] ?? false;
|
|
|
+ // 验证请求参数
|
|
|
+ $validationErrors = $this->validateData($data, [
|
|
|
+ 'user_id' => 'required|integer|min:1',
|
|
|
+ 'currency_types' => 'array',
|
|
|
+ 'currency_types.*' => 'string|max:20',
|
|
|
+ 'include_frozen' => 'boolean',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($validationErrors) {
|
|
|
+ return $this->errorResponse('参数验证失败', $validationErrors, 422);
|
|
|
+ }
|
|
|
|
|
|
- // 调用Fund模块服务获取余额信息
|
|
|
- $balanceInfo = $this->getFundBalance($userId, $currencyTypes, $includeFrozen);
|
|
|
+ // 获取参数
|
|
|
+ $userId = $data['user_id'];
|
|
|
+ $currencyTypes = $data['currency_types'] ?? [];
|
|
|
+ $includeFrozen = $data['include_frozen'] ?? false;
|
|
|
|
|
|
- if (!$balanceInfo) {
|
|
|
- return $this->errorResponse('用户不存在或无资金账户', null, 404);
|
|
|
- }
|
|
|
+ // 调用Fund模块服务获取余额信息
|
|
|
+ $balanceInfo = $this->getFundBalance($userId, $currencyTypes, $includeFrozen);
|
|
|
|
|
|
- // 记录操作日志
|
|
|
- $this->logAction('fund.balance.get', [
|
|
|
- 'user_id' => $userId,
|
|
|
- 'currency_types' => $currencyTypes,
|
|
|
- 'include_frozen' => $includeFrozen,
|
|
|
- ], $context);
|
|
|
+ if (!$balanceInfo) {
|
|
|
+ return $this->errorResponse('用户不存在或无资金账户', null, 404);
|
|
|
+ }
|
|
|
|
|
|
- return $this->successResponse('获取资金余额成功', $balanceInfo);
|
|
|
+ // 记录操作日志
|
|
|
+ $this->logAction('fund.balance.get', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'currency_types' => $currencyTypes,
|
|
|
+ 'include_frozen' => $includeFrozen,
|
|
|
+ ], $context);
|
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
- return $this->errorResponse('获取资金余额失败', ['error' => $e->getMessage()], 500);
|
|
|
- }
|
|
|
+ return $this->successResponse('获取资金余额成功', $balanceInfo);
|
|
|
}
|
|
|
|
|
|
/**
|