|
|
@@ -471,22 +471,49 @@ async def modify_scope_controller(
|
|
|
add_ids = list(new_employee_ids - old_employee_ids)
|
|
|
delete_ids = list(old_employee_ids - new_employee_ids)
|
|
|
|
|
|
- # ====== 4. 调用支付宝 scope.modify(只传差异) ======
|
|
|
- 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,
|
|
|
- )
|
|
|
+ # ====== 4. 调用支付宝 scope.modify ======
|
|
|
+ # 如果适配类型变更,需先单独改类型(不加员工ID),再增删员工
|
|
|
+ if old_adapter != new_adapter:
|
|
|
+ # 第1步:只改适配类型
|
|
|
+ await InstitutionScopeService.scope_modify_service(
|
|
|
+ auth=auth,
|
|
|
+ institution_id=institution_id,
|
|
|
+ data={
|
|
|
+ "enterprise_id": enterprise_id,
|
|
|
+ "adapter_type": new_adapter,
|
|
|
+ "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:
|
|
|
+ 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,
|
|
|
+ )
|
|
|
|
|
|
# ====== 5. 更新本地库 + 额度联动 ======
|
|
|
try:
|