Эх сурвалжийг харах

fix: 发放批次重复时显示友好提示 + 本地先校验批次号是否已存在

alphah 2 долоо хоног өмнө
parent
commit
ce3d88667e

+ 15 - 2
backend/app/plugin/module_payment/expense/quota/service.py

@@ -348,6 +348,17 @@ class QuotaService:
         except ImportError:
             raise CustomException(msg="支付宝SDK未正确安装,请检查alipay-sdk-python依赖")
 
+        # 本地检查批次号是否已存在,避免无效调用支付宝
+        try:
+            issue_batch_crud = IssueBatchCRUD(auth)
+            existing_batch = await issue_batch_crud.get_by_batch_no(data.batch_no)
+            if existing_batch:
+                raise CustomException(msg=f"批次号 {data.batch_no} 已存在,请勿重复创建")
+        except CustomException:
+            raise
+        except Exception:
+            pass
+
         model = AlipayEbppInvoiceExpensecontrolIssuebatchCreateModel()
         model.enterprise_id = data.enterprise_id
         model.issue_name = data.issue_name
@@ -388,8 +399,10 @@ class QuotaService:
         result.parse_response_content(response)
 
         if not result.is_success():
-            log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
-            raise CustomException(msg=f"手工批量发放额度失败: {result.msg}")
+            sub_msg = getattr(result, 'sub_msg', '') or ''
+            err_detail = f"{result.msg}" + (f" - {sub_msg}" if sub_msg else "")
+            log.error(f"支付宝接口调用失败: {result.code} - {err_detail}")
+            raise CustomException(msg=f"手工批量发放额度失败: {sub_msg or result.msg}")
 
         # 保存批次记录到本地
         try: