openapi_controller.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from typing import Annotated
  2. from agno.agent import AgentSession
  3. from fastapi import APIRouter, Depends, HTTPException
  4. from fastapi.responses import JSONResponse
  5. from app.core.dependencies import db_getter
  6. from app.plugin.module_payment.apikey.model import TenantApiKeyModel
  7. from app.common.response import ResponseSchema, SuccessResponse
  8. from app.core.logger import log
  9. from app.core.tenant_api_auth import TenantApiKeyAuth
  10. from app.plugin.module_payment.account.schema import AccountTransferSchema
  11. from app.plugin.module_payment.account.service import AccountService
  12. from app.api.v1.module_system.auth.schema import AuthSchema
  13. from sqlalchemy.ext.asyncio import AsyncSession
  14. OpenapiRouter = APIRouter(
  15. prefix="/openapi",
  16. tags=["开放接口"],
  17. )
  18. @OpenapiRouter.post(
  19. "/account/transfer",
  20. summary="租户资金专户转账",
  21. description="从资金专户转账到支付宝账户/银行卡/资金专户(支持API Key认证)",
  22. response_model=ResponseSchema[dict],
  23. )
  24. async def tenant_transfer_controller(
  25. db: Annotated[AsyncSession, Depends(db_getter)],
  26. data: AccountTransferSchema,
  27. api_key: TenantApiKeyModel = Depends(TenantApiKeyAuth()),
  28. ) -> JSONResponse:
  29. """
  30. 租户资金专户转账接口
  31. 支持通过API Key进行认证,适用于平台租户调用
  32. """
  33. # 构建认证信息
  34. auth = AuthSchema(
  35. user=None,
  36. check_data_scope=False,
  37. tenant_id=api_key.tenant_id,
  38. db=db,
  39. )
  40. # 执行转账
  41. result = await AccountService.transfer_service(auth=auth, data=data)
  42. log.info(f"租户资金专户转账发起成功: 企业: {data.enterprise_id}, 金额: {data.amount}")
  43. return SuccessResponse(data=result, msg="")