|
|
@@ -3,6 +3,7 @@ from typing import Annotated, Any, Optional, Dict
|
|
|
|
|
|
from fastapi import APIRouter, Body, Depends, Path, Query
|
|
|
from fastapi.responses import JSONResponse, StreamingResponse
|
|
|
+from redis.asyncio import Redis
|
|
|
|
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
|
from app.common.response import ResponseSchema, SuccessResponse
|
|
|
@@ -10,6 +11,7 @@ from app.core.dependencies import AuthPermission
|
|
|
from app.core.logger import log
|
|
|
from app.core.router_class import OperationLogRoute
|
|
|
from app.core.base_params import PaginationQueryParam
|
|
|
+from app.core.dependencies import redis_getter
|
|
|
|
|
|
from .schema import (
|
|
|
AccountAuthorizeApplySchema,
|
|
|
@@ -21,6 +23,9 @@ from .schema import (
|
|
|
AccountQuerySchema,
|
|
|
AccountTransferSchema,
|
|
|
AccountWithdrawSchema,
|
|
|
+ ReceiptApplySchema,
|
|
|
+ ReceiptApplyOutSchema,
|
|
|
+ ReceiptQueryOutSchema,
|
|
|
TransferListOutSchema,
|
|
|
TransferOutSchema,
|
|
|
TransferTaskOutSchema,
|
|
|
@@ -277,25 +282,95 @@ async def transfer_export_controller(
|
|
|
# return SuccessResponse(data=result, msg="申请资金回单成功")
|
|
|
|
|
|
|
|
|
-# @AccountRouter.get(
|
|
|
-# "/receipt/{file_id}",
|
|
|
-# summary="查询资金回单",
|
|
|
-# description="查询资金业务回单状态",
|
|
|
-# response_model=ResponseSchema[ReceiptQueryOutSchema],
|
|
|
-# )
|
|
|
-# async def receipt_query_controller(
|
|
|
-# file_id: Annotated[str, Path(description="文件申请号")],
|
|
|
-# auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:account:receipt"]))],
|
|
|
-# enterprise_id: Annotated[str, Query(description="企业ID")] = None,
|
|
|
-# ) -> JSONResponse:
|
|
|
-# """查询资金回单"""
|
|
|
-# if not enterprise_id:
|
|
|
-# enterprise_id = auth.enterprise_id or ""
|
|
|
-# result = await AccountService.receipt_query_service(
|
|
|
-# auth=auth, enterprise_id=enterprise_id, file_id=file_id
|
|
|
-# )
|
|
|
-# log.info(f"查询资金回单成功: {file_id}")
|
|
|
-# return SuccessResponse(data=result, msg="查询资金回单成功")
|
|
|
+@AccountRouter.post(
|
|
|
+ "/receipt/apply",
|
|
|
+ summary="申请转账业务回单",
|
|
|
+ description="申请指定转账单号的业务回单,返回 file_id 用于查询状态",
|
|
|
+ response_model=ResponseSchema[ReceiptApplyOutSchema],
|
|
|
+)
|
|
|
+async def receipt_apply_controller(
|
|
|
+ data: ReceiptApplySchema,
|
|
|
+ auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:account:receipt"]))],
|
|
|
+ redis: Annotated[Redis, Depends(redis_getter)],
|
|
|
+) -> JSONResponse:
|
|
|
+ """
|
|
|
+ 申请转账业务回单
|
|
|
+
|
|
|
+ 调用: alipay.commerce.ec.trans.receipt.apply
|
|
|
+
|
|
|
+ 参数:
|
|
|
+ - enterprise_id: 企业ID
|
|
|
+ - order_no: 支付宝转账单号
|
|
|
+ """
|
|
|
+ file_id = await AccountService.apply_receipt_service(
|
|
|
+ auth=auth,
|
|
|
+ redis=redis,
|
|
|
+ data=data,
|
|
|
+ )
|
|
|
+ log.info(f"申请转账业务回单成功: order_no={data.order_no}, file_id={file_id}")
|
|
|
+ return SuccessResponse(data={"file_id": file_id}, msg="申请成功")
|
|
|
+
|
|
|
+
|
|
|
+@AccountRouter.get(
|
|
|
+ "/receipt/{enterprise_id}/{file_id}",
|
|
|
+ summary="查询回单状态",
|
|
|
+ description="查询转账回单的处理状态和下载链接",
|
|
|
+ response_model=ResponseSchema[ReceiptQueryOutSchema],
|
|
|
+)
|
|
|
+async def receipt_query_controller(
|
|
|
+ enterprise_id: Annotated[str, Path(description="企业ID")],
|
|
|
+ file_id: Annotated[str, Path(description="文件申请号")],
|
|
|
+ auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:account:receipt"]))],
|
|
|
+) -> JSONResponse:
|
|
|
+ """
|
|
|
+ 查询回单状态
|
|
|
+
|
|
|
+ 调用: alipay.commerce.ec.trans.receipt.query
|
|
|
+
|
|
|
+ 参数:
|
|
|
+ - file_id: 文件申请号(有效期2天)
|
|
|
+ """
|
|
|
+ result = await AccountService.query_receipt_service(
|
|
|
+ enterprise_id=enterprise_id,
|
|
|
+ file_id=file_id,
|
|
|
+ )
|
|
|
+ log.info(f"查询回单状态成功: file_id={file_id}, status={result['status']}")
|
|
|
+ return SuccessResponse(data=result, msg="查询成功")
|
|
|
+
|
|
|
+
|
|
|
+@AccountRouter.get(
|
|
|
+ "/receipt/download",
|
|
|
+ summary="获取回单下载链接",
|
|
|
+ description="获取回单下载链接(封装申请+查询,PROCESS状态直接返回,由前端轮询)",
|
|
|
+ response_model=ResponseSchema[ReceiptQueryOutSchema],
|
|
|
+)
|
|
|
+async def receipt_download_controller(
|
|
|
+ auth: Annotated[AuthSchema, Depends(AuthPermission(["module_payment:account:receipt"]))],
|
|
|
+ redis: Annotated[Redis, Depends(redis_getter)],
|
|
|
+ enterprise_id: Annotated[str, Query(description="企业ID")],
|
|
|
+ order_no: Annotated[str, Query(description="支付宝转账单号")],
|
|
|
+) -> JSONResponse:
|
|
|
+ """
|
|
|
+ 获取回单下载链接
|
|
|
+
|
|
|
+ 封装完整流程:
|
|
|
+ 1. 申请/获取 file_id(自动缓存)
|
|
|
+ 2. 查询回单状态
|
|
|
+ 3. 直接返回状态(PROCESS状态由前端主动查询)
|
|
|
+ """
|
|
|
+ file_id = await AccountService.apply_receipt_service(
|
|
|
+ auth=auth,
|
|
|
+ redis=redis,
|
|
|
+ data=ReceiptApplySchema(enterprise_id=enterprise_id, order_no=order_no),
|
|
|
+ )
|
|
|
+
|
|
|
+ result = await AccountService.query_receipt_service(
|
|
|
+ enterprise_id=enterprise_id,
|
|
|
+ file_id=file_id,
|
|
|
+ )
|
|
|
+
|
|
|
+ log.info(f"获取回单下载链接: file_id={file_id}, status={result['status']}")
|
|
|
+ return SuccessResponse(data=result, msg="操作成功")
|
|
|
|
|
|
|
|
|
# @AccountRouter.post(
|