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

fix: 详情页未调接口/调整金额按钮保护/支付宝额度不存在时清理本地

alphah 2 недель назад
Родитель
Сommit
27238b457b

+ 12 - 1
backend/app/plugin/module_payment/expense/quota/service.py

@@ -828,7 +828,18 @@ class QuotaService:
 
         if not mod_result.is_success():
             sub_msg = getattr(mod_result, 'sub_msg', '') or ''
-            log.error(f"支付宝接口调用失败: {mod_result.code} - {mod_result.msg}")
+            sub_code = getattr(mod_result, 'sub_code', '') or ''
+            log.error(f"支付宝接口调用失败: {mod_result.code} - {mod_result.msg} (sub_code={sub_code}, sub_msg={sub_msg})")
+            # 如果 Alipay 提示额度不存在,清理本地陈旧记录
+            if '不存在' in sub_msg or 'INVALID' in sub_code:
+                try:
+                    from sqlalchemy import delete as sa_delete
+                    del_stmt = sa_delete(QuotaModel).where(QuotaModel.quota_id == data.quota_id)
+                    await auth.db.execute(del_stmt)
+                    await auth.db.flush()
+                    log.info(f"调整额度 - 支付宝侧额度不存在,已清理本地陈旧记录: quota_id={data.quota_id}")
+                except Exception as e:
+                    log.warning(f"清理本地陈旧记录失败: {e}")
             raise CustomException(msg=f"调整额度失败: {sub_msg or mod_result.msg}")
 
         # 更新本地额度记录

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

@@ -3,6 +3,7 @@
     v-model="visible"
     title="额度详情"
     width="700px"
+    destroy-on-close
     @close="handleClose"
   >
     <QuotaDetail :quota-id="quotaId" />

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

@@ -50,8 +50,8 @@
       <el-table-column label="操作" width="220" align="center" fixed="right">
         <template #default="scope">
           <el-button type="text" size="small" @click="handleDetail(scope.row)">详情</el-button>
-          <el-button type="text" size="small" @click="handleAdjust(scope.row)">调整金额</el-button>
-          <el-button type="text" size="small" @click="handleChanges(scope.row)">变更记录</el-button>
+          <el-button v-if="scope.row.quota_id" type="text" size="small" @click="handleAdjust(scope.row)">调整金额</el-button>
+          <el-button v-if="scope.row.quota_id" type="text" size="small" @click="handleChanges(scope.row)">变更记录</el-button>
         </template>
       </el-table-column>
     </el-table>

+ 4 - 0
frontend/src/views/module_payment/quota/components/AdjustAmountDialog.vue

@@ -61,6 +61,10 @@ watch(() => props.visible, (v) => {
 watch(visible, (v) => emit("update:visible", v));
 
 async function handleSubmit() {
+  if (!props.quotaData?.quota_id) {
+    ElMessage.error("额度ID不存在,无法调整");
+    return;
+  }
   const eid = useEnterpriseStore().getCurrentEnterprise?.enterprise_id;
   if (!eid) { ElMessage.error("企业ID不存在"); return; }
 

+ 8 - 1
frontend/src/views/module_payment/quota/components/QuotaDetail.vue

@@ -74,7 +74,7 @@ import QuotaAPI, {
   QUOTA_TYPE_OPTIONS,
   TARGET_TYPE_OPTIONS,
 } from "@/api/module_payment/quota";
-import { onMounted, ref } from "vue";
+import { onMounted, ref, watch } from "vue";
 
 interface Props {
   quotaId: string;
@@ -111,4 +111,11 @@ async function fetchDetail() {
 onMounted(() => {
   fetchDetail();
 });
+
+watch(() => props.quotaId, (newVal) => {
+  if (newVal) {
+    detailData.value = { status: "", created_time: "", updated_time: "" } as QuotaDetail;
+    fetchDetail();
+  }
+});
 </script>