Przeglądaj źródła

fix: 修改制度传 scope/额度等所有字段 + 后端同步本地DB

alphah 2 tygodni temu
rodzic
commit
c600af29d5

+ 14 - 0
backend/app/plugin/module_payment/expense/institution/controller.py

@@ -277,6 +277,20 @@ async def modify_institution_controller(
     EXPENSE_TYPE_MAP = {"GENERAL": "DEFAULT", "DEFAULT": "DEFAULT"}
     EXPENSE_TYPE_MAP = {"GENERAL": "DEFAULT", "DEFAULT": "DEFAULT"}
     if data.get("expense_type") in EXPENSE_TYPE_MAP:
     if data.get("expense_type") in EXPENSE_TYPE_MAP:
         data["expense_type"] = EXPENSE_TYPE_MAP[data["expense_type"]]
         data["expense_type"] = EXPENSE_TYPE_MAP[data["expense_type"]]
+    # 构造 scope 变更信息写入支付宝模型
+    applicable_scope = data.get("applicable_scope", "")
+    if applicable_scope and applicable_scope not in ("NONE", "none"):
+        ADAPTER_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "DEPARTMENT_SELECT"}
+        scope_info = {
+            "adapter_type": ADAPTER_MAP.get(applicable_scope, applicable_scope),
+            "owner_type": "ENTERPRISE_PAY_UID",
+        }
+        if applicable_scope == "employee" and data.get("scope_owner_id_list"):
+            scope_info["add_owner_id_list"] = data["scope_owner_id_list"]
+        elif applicable_scope == "department" and data.get("scope_owner_id_list"):
+            scope_info["add_owner_id_list"] = data["scope_owner_id_list"]
+        data["modify_scope_info"] = scope_info
+
     institution_modify_model = AlipayEbppInvoiceInstitutionModifyModel.from_alipay_dict(data)
     institution_modify_model = AlipayEbppInvoiceInstitutionModifyModel.from_alipay_dict(data)
     result = await InstitutionService.modify_institution_service(
     result = await InstitutionService.modify_institution_service(
         auth=auth, data=institution_modify_model, raw_data=data
         auth=auth, data=institution_modify_model, raw_data=data

+ 6 - 19
backend/app/plugin/module_payment/expense/institution/service.py

@@ -533,27 +533,9 @@ class InstitutionService:
             log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
             log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
             raise CustomException(msg=f"编辑费控制度失败: {result.msg}")
             raise CustomException(msg=f"编辑费控制度失败: {result.msg}")
 
 
-        # 第2步:同步适用员工范围
         applicable_scope = raw_data.get("applicable_scope", "")
         applicable_scope = raw_data.get("applicable_scope", "")
-        if applicable_scope and applicable_scope not in ("NONE", "none"):
-            ADAPTER_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "DEPARTMENT_SELECT"}
-            mapped = ADAPTER_MAP.get(applicable_scope, applicable_scope)
-            scope_payload = {
-                "enterprise_id": enterprise_id,
-                "adapter_type": mapped,
-                "owner_type": "ENTERPRISE_PAY_UID",
-            }
-            if applicable_scope == "employee" and raw_data.get("scope_owner_id_list"):
-                scope_payload["add_owner_id_list"] = raw_data["scope_owner_id_list"]
-            try:
-                await InstitutionScopeService.scope_modify_service(
-                    auth=auth, institution_id=institution_id, data=scope_payload
-                )
-                log.info(f"适用员工范围已同步: {applicable_scope}")
-            except Exception as e:
-                log.warning(f"适用员工范围同步失败(不影响主流程): {e}")
 
 
-        # 第3步:同步更新本地数据库
+        # 第2步:同步更新本地数据库(scope 已在 Alipay modify 请求中通过 modify_scope_info 处理)
         try:
         try:
             crud = InstitutionCRUD(auth)
             crud = InstitutionCRUD(auth)
             update_data = {}
             update_data = {}
@@ -574,6 +556,11 @@ class InstitutionService:
                 update_data['effective_end_date'] = data.effective_end_date
                 update_data['effective_end_date'] = data.effective_end_date
             if applicable_scope:
             if applicable_scope:
                 update_data['applicable_scope'] = applicable_scope
                 update_data['applicable_scope'] = applicable_scope
+            # 同步额外配置字段
+            for field in ("grant_mode", "period_type", "amount", "single_limit", "effective_time_type", "expense_type"):
+                val = raw_data.get(field)
+                if val is not None:
+                    update_data[field] = val
 
 
             if update_data:
             if update_data:
                 await crud.update_by_institution_id(institution_id, update_data)
                 await crud.update_by_institution_id(institution_id, update_data)

+ 14 - 0
frontend/src/views/module_payment/institution/components/InstitutionForm.vue

@@ -461,7 +461,21 @@ async function submitForm() {
         effective_start_date: formData.effective_start_date || undefined,
         effective_start_date: formData.effective_start_date || undefined,
         effective_end_date: formData.is_long_term ? undefined : (formData.effective_end_date || undefined),
         effective_end_date: formData.is_long_term ? undefined : (formData.effective_end_date || undefined),
         consult_mode: formData.consult_mode || undefined,
         consult_mode: formData.consult_mode || undefined,
+        // 适用员工范围
+        applicable_scope: formData.applicable_scope,
+        scope_owner_type: "PHONE",
+        scope_owner_id_list: formData.employee_ids || formData.department_id ? [formData.department_id] : undefined,
+        // 额度发放与周期参数
+        grant_mode: formData.grant_mode,
+        period_type: formData.period_type || "monthly",
+        amount: formData.amount,
+        single_limit: formData.single_limit,
+        effective_time_type: formData.effective_time_type || "unlimited",
+        expense_type: formData.expense_type,
       };
       };
+      if (formData.applicable_scope === "department" && formData.department_id) {
+        modifyData.scope_owner_id_list = [formData.department_id];
+      }
       await InstitutionAPI.updateInstitution(props.institutionId, modifyData);
       await InstitutionAPI.updateInstitution(props.institutionId, modifyData);
     }
     }
     emit("success");
     emit("success");