Prechádzať zdrojové kódy

fix: 4 bugs - 已选人数/scope修改/限额字段/操作栏隐藏

alphah 2 týždňov pred
rodič
commit
d41c391194

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

@@ -500,22 +500,27 @@ class InstitutionService:
     @classmethod
     async def modify_institution_service(
         cls, auth: AuthSchema, data: AlipayEbppInvoiceInstitutionModifyModel, raw_data: dict | None = None
-    ) -> AlipayEbppInvoiceInstitutionModifyResponse:
+    ) -> dict:
         """
         编辑费控制度
         调用: alipay.ebpp.invoice.institution.modify
 
         支付宝成功后同步更新本地DB:
         - 制度基本信息
+        - 适用员工范围(scope)
         - 使用规则(standard_info_list → pay_expense_rule)
         - 额度(issuerule → pay_expense_quota)
         """
         if data.institution_id is None:
             raise CustomException(msg="编辑费控制度失败: 制度ID不能为空")
 
+        institution_id = data.institution_id
+        enterprise_id = getattr(data, 'enterprise_id', None) or (raw_data or {}).get("enterprise_id", "")
+        raw_data = raw_data or {}
+
+        # 第1步:修改支付宝制度信息
         request = AlipayEbppInvoiceInstitutionModifyRequest()
         request.biz_model = data
-
         response = await asyncio.to_thread(cls._execute_alipay, request)
 
         if not response:
@@ -528,11 +533,27 @@ class InstitutionService:
             log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
             raise CustomException(msg=f"编辑费控制度失败: {result.msg}")
 
-        # 同步更新本地数据库
-        institution_id = getattr(data, 'institution_id', None)
-        if not institution_id:
-            return result
+        # 第2步:同步适用员工范围
+        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步:同步更新本地数据库
         try:
             crud = InstitutionCRUD(auth)
             update_data = {}
@@ -551,6 +572,8 @@ class InstitutionService:
                 update_data['effective_start_date'] = data.effective_start_date
             if hasattr(data, 'effective_end_date') and data.effective_end_date:
                 update_data['effective_end_date'] = data.effective_end_date
+            if applicable_scope:
+                update_data['applicable_scope'] = applicable_scope
 
             if update_data:
                 await crud.update_by_institution_id(institution_id, update_data)

+ 2 - 0
backend/app/plugin/module_payment/expense/rule/schema.py

@@ -109,6 +109,8 @@ class RuleListOutSchema(BaseModel):
     expense_type_sub_category: Optional[str] = Field(default=None, description="费用类型子类")
     status: Optional[str] = Field(default=None, description="状态")
     enterprise_id: Optional[str] = Field(default=None, description="企业ID")
+    single_limit: Optional[float] = Field(default=None, description="单笔限额")
+    condition_info: Optional[list] = Field(default=None, description="规则条件列表")
     created_time: Optional[datetime] = Field(default=None, description="创建时间")
     updated_time: Optional[datetime] = Field(default=None, description="更新时间")
 

+ 1 - 1
frontend/src/views/module_payment/institution/components/EmployeeSelector.vue

@@ -64,7 +64,7 @@
 </template>
 
 <script setup lang="ts">
-import { ref, computed, watch } from "vue";
+import { ref, computed, watch, nextTick } from "vue";
 import EmployeeAPI from "@/api/module_payment/employee";
 
 interface Employee {

+ 2 - 2
frontend/src/views/module_payment/institution/components/InstitutionDetail.vue

@@ -59,11 +59,11 @@
       </el-tab-pane>
 
       <el-tab-pane label="使用规则" name="rule">
-        <RuleList :institution-id="props.institutionId" />
+        <RuleList :institution-id="props.institutionId" readonly />
       </el-tab-pane>
 
       <el-tab-pane label="额度管理" name="quota">
-        <QuotaList :institution-id="props.institutionId" />
+        <QuotaList :institution-id="props.institutionId" readonly />
       </el-tab-pane>
     </el-tabs>
   </div>

+ 4 - 3
frontend/src/views/module_payment/institution/components/QuotaList.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="quota-list">
-    <div class="quota-list__toolbar">
+    <div v-if="!readonly" class="quota-list__toolbar">
       <el-button
         v-hasPerm="['module_payment:quota:create']"
         type="primary"
@@ -41,7 +41,7 @@
         </template>
       </el-table-column>
       <el-table-column prop="created_time" label="创建时间" width="160" />
-      <el-table-column label="操作" width="120" align="center" fixed="right">
+      <el-table-column v-if="!readonly" label="操作" width="120" align="center" fixed="right">
         <template #default="scope">
           <el-button
             v-hasPerm="['module_payment:quota:detail']"
@@ -87,9 +87,10 @@ import { onMounted, ref } from "vue";
 
 interface Props {
   institutionId: string;
+  readonly?: boolean;
 }
 
-const props = defineProps<Props>();
+const props = withDefaults(defineProps<Props>(), { readonly: false });
 
 const list = ref<any[]>([]);
 const total = ref(0);

+ 8 - 7
frontend/src/views/module_payment/institution/components/RuleList.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="rule-list">
-    <div class="rule-list__toolbar">
+    <div v-if="!readonly" class="rule-list__toolbar">
       <el-button
         v-hasPerm="['module_payment:rule:create']"
         type="primary"
@@ -18,23 +18,23 @@
       <el-table-column type="index" label="序号" width="60" align="center" />
       <el-table-column prop="rule_id" label="规则ID" min-width="160" show-overflow-tooltip />
       <el-table-column prop="standard_name" label="规则名称" min-width="140" />
-      <el-table-column prop="max_amount" label="单笔限额" width="100" align="right">
+      <el-table-column label="单笔限额" width="100" align="right">
         <template #default="scope">
-          {{ scope.row.max_amount ? `¥${scope.row.max_amount}` : "-" }}
+          {{ scope.row.single_limit ? `¥${scope.row.single_limit}` : (scope.row.max_amount ? `¥${scope.row.max_amount}` : "-") }}
         </template>
       </el-table-column>
-      <el-table-column prop="max_day_amount" label="日限额" width="100" align="right">
+      <el-table-column label="日限额" width="100" align="right">
         <template #default="scope">
           {{ scope.row.max_day_amount ? `¥${scope.row.max_day_amount}` : "-" }}
         </template>
       </el-table-column>
-      <el-table-column prop="max_month_amount" label="月限额" width="100" align="right">
+      <el-table-column label="月限额" width="100" align="right">
         <template #default="scope">
           {{ scope.row.max_month_amount ? `¥${scope.row.max_month_amount}` : "-" }}
         </template>
       </el-table-column>
       <el-table-column prop="created_time" label="创建时间" width="160" />
-      <el-table-column label="操作" width="160" align="center" fixed="right">
+      <el-table-column v-if="!readonly" label="操作" width="160" align="center" fixed="right">
         <template #default="scope">
           <el-button
             v-hasPerm="['module_payment:rule:detail']"
@@ -84,9 +84,10 @@ import { onMounted, ref } from "vue";
 
 interface Props {
   institutionId: string;
+  readonly?: boolean;
 }
 
-const props = defineProps<Props>();
+const props = withDefaults(defineProps<Props>(), { readonly: false });
 
 const list = ref<any[]>([]);
 const total = ref(0);