Просмотр исходного кода

fix: NONE→ALL时支付宝不分步传ID + 查旧scope失败默认NONE

alphah 2 недель назад
Родитель
Сommit
63f3b7d864
1 измененных файлов с 31 добавлено и 25 удалено
  1. 31 25
      backend/app/plugin/module_payment/expense/institution/controller.py

+ 31 - 25
backend/app/plugin/module_payment/expense/institution/controller.py

@@ -407,7 +407,7 @@ async def modify_scope_controller(
     new_adapter = data.get("adapter_type", "EMPLOYEE_ALL")
 
     # ====== 1. 查询旧适配类型和老员工ID列表 ======
-    old_adapter = new_adapter
+    old_adapter = "NONE"
     old_employee_ids: set[str] = set()
     try:
         scope_old = await InstitutionScopeService.scopepageinfo_query_service(
@@ -440,6 +440,7 @@ async def modify_scope_controller(
         else:
             old_employee_ids = set(raw_old)
     except Exception:
+        old_adapter = "NONE"  # 查不到旧范围时标记为NONE,确保走分步调用的逻辑
         log.warning(f"查询旧scope失败(将全量处理): institution_id={institution_id}")
 
     # ====== 2. 计算新员工ID列表 ======
@@ -470,6 +471,8 @@ async def modify_scope_controller(
     # ====== 3. 计算差异 ======
     add_ids = list(new_employee_ids - old_employee_ids)
     delete_ids = list(old_employee_ids - new_employee_ids)
+    # 全体员工(ALL)模式:支付宝端不需要传员工ID列表,但本地配额同步需要
+    send_ids_to_alipay = new_adapter not in ("EMPLOYEE_ALL",)
 
     # ====== 4. 调用支付宝 scope.modify ======
     # 如果适配类型变更,需先单独改类型(不加员工ID),再增删员工
@@ -484,36 +487,39 @@ async def modify_scope_controller(
                 "owner_type": data.get("owner_type", "EMPLOYEE"),
             },
         )
-        # 第2步:增删员工
-        scope_data = {
-            "enterprise_id": enterprise_id,
-            "adapter_type": new_adapter,
-            "owner_type": data.get("owner_type", "EMPLOYEE"),
-        }
-        if add_ids:
-            scope_data["add_owner_id_list"] = add_ids
-        if delete_ids:
-            scope_data["delete_owner_id_list"] = delete_ids
-        if add_ids or delete_ids:
+        # 第2步:增删员工(ALL模式跳过,支付宝不传员工列表)
+        if send_ids_to_alipay and (add_ids or delete_ids):
+            scope_data = {
+                "enterprise_id": enterprise_id,
+                "adapter_type": new_adapter,
+                "owner_type": data.get("owner_type", "EMPLOYEE"),
+            }
+            if add_ids:
+                scope_data["add_owner_id_list"] = add_ids
+            if delete_ids:
+                scope_data["delete_owner_id_list"] = delete_ids
             result = await InstitutionScopeService.scope_modify_service(
                 auth=auth, institution_id=institution_id, data=scope_data,
             )
         else:
             result = {"result": True}
     else:
-        # 适配类型不变,直接增删员工
-        scope_data = {
-            "enterprise_id": enterprise_id,
-            "adapter_type": new_adapter,
-            "owner_type": data.get("owner_type", "EMPLOYEE"),
-        }
-        if add_ids:
-            scope_data["add_owner_id_list"] = add_ids
-        if delete_ids:
-            scope_data["delete_owner_id_list"] = delete_ids
-        result = await InstitutionScopeService.scope_modify_service(
-            auth=auth, institution_id=institution_id, data=scope_data,
-        )
+        # 适配类型不变,直接增删员工(ALL模式跳过)
+        if send_ids_to_alipay and (add_ids or delete_ids):
+            scope_data = {
+                "enterprise_id": enterprise_id,
+                "adapter_type": new_adapter,
+                "owner_type": data.get("owner_type", "EMPLOYEE"),
+            }
+            if add_ids:
+                scope_data["add_owner_id_list"] = add_ids
+            if delete_ids:
+                scope_data["delete_owner_id_list"] = delete_ids
+            result = await InstitutionScopeService.scope_modify_service(
+                auth=auth, institution_id=institution_id, data=scope_data,
+            )
+        else:
+            result = {"result": True}
 
     # ====== 5. 更新本地库 + 额度联动 ======
     try: