|
@@ -14,6 +14,7 @@ from app.plugin.module_payment.enterprise.crud import EnterpriseCRUD
|
|
|
from .crud import AccountCRUD, TransferCRUD, DepositCRUD, WithdrawCRUD
|
|
from .crud import AccountCRUD, TransferCRUD, DepositCRUD, WithdrawCRUD
|
|
|
from .enums import (
|
|
from .enums import (
|
|
|
DepositStatusEnum,
|
|
DepositStatusEnum,
|
|
|
|
|
+ WithdrawStatusEnum,
|
|
|
)
|
|
)
|
|
|
from .schema import (
|
|
from .schema import (
|
|
|
AccountAuthorizeApplySchema,
|
|
AccountAuthorizeApplySchema,
|
|
@@ -25,6 +26,7 @@ from .schema import (
|
|
|
AccountQuerySchema,
|
|
AccountQuerySchema,
|
|
|
AccountTransferSchema,
|
|
AccountTransferSchema,
|
|
|
AccountTransferOutSchema,
|
|
AccountTransferOutSchema,
|
|
|
|
|
+ AccountWithdrawSchema,
|
|
|
TransferListOutSchema,
|
|
TransferListOutSchema,
|
|
|
TransferOutSchema,
|
|
TransferOutSchema,
|
|
|
TenantTransferCreate,
|
|
TenantTransferCreate,
|
|
@@ -400,72 +402,82 @@ class AccountService:
|
|
|
fund_order_id=result.fund_order_id,
|
|
fund_order_id=result.fund_order_id,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- # @classmethod
|
|
|
|
|
- # async def withdraw_service(
|
|
|
|
|
- # cls,
|
|
|
|
|
- # auth: AuthSchema,
|
|
|
|
|
- # data: AccountWithdrawSchema
|
|
|
|
|
- # ) -> AccountOperationOutSchema:
|
|
|
|
|
- # """
|
|
|
|
|
- # 资金专户提现
|
|
|
|
|
-
|
|
|
|
|
- # 调用: alipay.commerce.ec.trans.account.withdraw
|
|
|
|
|
- # """
|
|
|
|
|
- # from alipay.aop.api.request.AlipayCommerceEcTransAccountWithdrawRequest import (
|
|
|
|
|
- # AlipayCommerceEcTransAccountWithdrawRequest,
|
|
|
|
|
- # )
|
|
|
|
|
- # from alipay.aop.api.domain.AlipayCommerceEcTransAccountWithdrawModel import (
|
|
|
|
|
- # AlipayCommerceEcTransAccountWithdrawModel,
|
|
|
|
|
- # )
|
|
|
|
|
- # from alipay.aop.api.response.AlipayCommerceEcTransAccountWithdrawResponse import (
|
|
|
|
|
- # AlipayCommerceEcTransAccountWithdrawResponse,
|
|
|
|
|
- # )
|
|
|
|
|
-
|
|
|
|
|
- # crud = AccountCRUD(auth)
|
|
|
|
|
- # enterprise = await crud.get_by_enterprise_id(data.enterprise_id)
|
|
|
|
|
-
|
|
|
|
|
- # if not enterprise:
|
|
|
|
|
- # raise CustomException(msg="企业不存在")
|
|
|
|
|
-
|
|
|
|
|
- # model = AlipayCommerceEcTransAccountWithdrawModel()
|
|
|
|
|
- # model.enterprise_id = enterprise.alipay_enterprise_id
|
|
|
|
|
- # model.account_book_id = data.account_book_id
|
|
|
|
|
- # model.amount = str(data.amount)
|
|
|
|
|
- # model.out_biz_no = data.out_biz_no
|
|
|
|
|
-
|
|
|
|
|
- # request = AlipayCommerceEcTransAccountWithdrawRequest()
|
|
|
|
|
- # request.biz_model = model
|
|
|
|
|
-
|
|
|
|
|
- # client = AlipayClient.get_client()
|
|
|
|
|
- # response = client.execute(request)
|
|
|
|
|
-
|
|
|
|
|
- # if not response:
|
|
|
|
|
- # raise CustomException(msg="提现失败: 无响应")
|
|
|
|
|
-
|
|
|
|
|
- # result = AlipayCommerceEcTransAccountWithdrawResponse()
|
|
|
|
|
- # result.parse_response_content(response)
|
|
|
|
|
-
|
|
|
|
|
- # if not result.is_success():
|
|
|
|
|
- # log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
|
|
|
|
|
- # raise CustomException(msg=f"提现失败: {result.msg}")
|
|
|
|
|
-
|
|
|
|
|
- # withdraw_crud = WithdrawCRUD(auth)
|
|
|
|
|
- # withdraw_data = {
|
|
|
|
|
- # "enterprise_id": data.enterprise_id,
|
|
|
|
|
- # "out_biz_no": data.out_biz_no,
|
|
|
|
|
- # "account_book_id": data.account_book_id,
|
|
|
|
|
- # "amount": data.amount,
|
|
|
|
|
- # "status": WithdrawStatusEnum.DEALING.value,
|
|
|
|
|
- # "order_no": result.order_no,
|
|
|
|
|
- # }
|
|
|
|
|
- # await withdraw_crud.create(withdraw_data)
|
|
|
|
|
-
|
|
|
|
|
- # return AccountOperationOutSchema(
|
|
|
|
|
- # enterprise_id=data.enterprise_id,
|
|
|
|
|
- # account_book_id=data.account_book_id,
|
|
|
|
|
- # out_biz_no=data.out_biz_no,
|
|
|
|
|
- # status=WithdrawStatusEnum.DEALING.value,
|
|
|
|
|
- # )
|
|
|
|
|
|
|
+ @classmethod
|
|
|
|
|
+ async def withdraw_service(
|
|
|
|
|
+ cls,
|
|
|
|
|
+ auth: AuthSchema,
|
|
|
|
|
+ data: AccountWithdrawSchema
|
|
|
|
|
+ ) -> AccountOperationOutSchema:
|
|
|
|
|
+ """
|
|
|
|
|
+ 资金专户提现
|
|
|
|
|
+
|
|
|
|
|
+ 调用: alipay.commerce.ec.trans.account.withdraw
|
|
|
|
|
+
|
|
|
|
|
+ 接口文档: https://opendocs.alipay.com/pre-open/d651859b_alipay.commerce.ec.trans.account.withdraw
|
|
|
|
|
+
|
|
|
|
|
+ 参数说明:
|
|
|
|
|
+ - enterprise_id: 企业ID
|
|
|
|
|
+ - account_book_id: 资金专户号
|
|
|
|
|
+ - amount: 提现金额
|
|
|
|
|
+ - out_biz_no: 商家侧订单号(唯一)
|
|
|
|
|
+ """
|
|
|
|
|
+ from alipay.aop.api.request.AlipayCommerceEcTransAccountWithdrawRequest import (
|
|
|
|
|
+ AlipayCommerceEcTransAccountWithdrawRequest,
|
|
|
|
|
+ )
|
|
|
|
|
+ from alipay.aop.api.domain.AlipayCommerceEcTransAccountWithdrawModel import (
|
|
|
|
|
+ AlipayCommerceEcTransAccountWithdrawModel,
|
|
|
|
|
+ )
|
|
|
|
|
+ from alipay.aop.api.response.AlipayCommerceEcTransAccountWithdrawResponse import (
|
|
|
|
|
+ AlipayCommerceEcTransAccountWithdrawResponse,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ crud = AccountCRUD(auth)
|
|
|
|
|
+ enterprise = await crud.get_by_enterprise_id(data.enterprise_id)
|
|
|
|
|
+
|
|
|
|
|
+ if not enterprise:
|
|
|
|
|
+ raise CustomException(msg="企业不存在")
|
|
|
|
|
+
|
|
|
|
|
+ model = AlipayCommerceEcTransAccountWithdrawModel()
|
|
|
|
|
+ model.enterprise_id = enterprise.enterprise_id
|
|
|
|
|
+ model.account_book_id = data.account_book_id
|
|
|
|
|
+ model.amount = str(data.amount)
|
|
|
|
|
+ model.out_biz_no = get_snowflake_id_str(auth.tenant_id)
|
|
|
|
|
+
|
|
|
|
|
+ request = AlipayCommerceEcTransAccountWithdrawRequest()
|
|
|
|
|
+ request.biz_model = model
|
|
|
|
|
+
|
|
|
|
|
+ client = AlipayClient.get_client()
|
|
|
|
|
+ response = client.execute(request)
|
|
|
|
|
+
|
|
|
|
|
+ if not response:
|
|
|
|
|
+ raise CustomException(msg="提现失败: 无响应")
|
|
|
|
|
+
|
|
|
|
|
+ result = AlipayCommerceEcTransAccountWithdrawResponse()
|
|
|
|
|
+ result.parse_response_content(response)
|
|
|
|
|
+
|
|
|
|
|
+ if not result.is_success():
|
|
|
|
|
+ log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
|
|
|
|
|
+ raise CustomException(msg=f"提现失败: {result.msg}")
|
|
|
|
|
+
|
|
|
|
|
+ withdraw_crud = WithdrawCRUD(auth)
|
|
|
|
|
+ withdraw_data = {
|
|
|
|
|
+ "enterprise_id": data.enterprise_id,
|
|
|
|
|
+ "out_biz_no": model.out_biz_no,
|
|
|
|
|
+ "account_book_id": data.account_book_id,
|
|
|
|
|
+ "amount": data.amount,
|
|
|
|
|
+ # 专户提现到余额户是同步操作,要么执行成功,要么执行异常,
|
|
|
|
|
+ # 出参status设计多余,遵循规范使用业务码区分成功与失败
|
|
|
|
|
+ "status": WithdrawStatusEnum.SUCCESS.value,
|
|
|
|
|
+ "order_no": result.order_no,
|
|
|
|
|
+ }
|
|
|
|
|
+ await withdraw_crud.create(withdraw_data)
|
|
|
|
|
+
|
|
|
|
|
+ log.info(f"资金专户提现发起成功: 企业: {data.enterprise_id}, 金额: {data.amount}")
|
|
|
|
|
+
|
|
|
|
|
+ return AccountOperationOutSchema(
|
|
|
|
|
+ enterprise_id=data.enterprise_id,
|
|
|
|
|
+ account_book_id=data.account_book_id,
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
|
async def query_account_service(
|
|
async def query_account_service(
|