Explorar el Código

fix: 制度创建时不再将issue_rule_id误存为quota_id;调整失败不改删记录改为清quota_id

alphah hace 1 semana
padre
commit
23c855bd5c

+ 0 - 1
backend/app/plugin/module_payment/expense/institution/service.py

@@ -377,7 +377,6 @@ class InstitutionService:
                 quota_type="CAP" if grant_mode == "period" else None,
                 target_type="INSTITUTION",
                 target_id=institution_id,
-                quota_id=issue_rule_id,
                 out_biz_no=f"inst_{institution_id}_{emp_id}",
                 total_amount=total,
                 available_amount=available,

+ 6 - 7
backend/app/plugin/module_payment/expense/quota/service.py

@@ -884,16 +884,15 @@ class QuotaService:
             sub_msg = getattr(mod_result, 'sub_msg', '') or ''
             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:
+            # 如果 Alipay 提示额度不存在,清除本地错误的 quota_id(可能是 issue_rule_id 误存),后续可重试查询回填
+            if ('不存在' in sub_msg or 'INVALID' in sub_code) and quota:
                 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)
+                    upd = sa_update(QuotaModel).where(QuotaModel.id == quota.id).values(quota_id=None)
+                    await auth.db.execute(upd)
                     await auth.db.flush()
-                    log.info(f"调整额度 - 支付宝侧额度不存在,已清理本地陈旧记录: quota_id={data.quota_id}")
+                    log.info(f"调整额度 - 本地quota_id无效({data.quota_id})已清除,后续可从支付宝查询回填")
                 except Exception as e:
-                    log.warning(f"清理本地陈旧记录失败: {e}")
+                    log.warning(f"清除本地无效quota_id失败: {e}")
             raise CustomException(msg=f"调整额度失败: {sub_msg or mod_result.msg}")
 
         # 更新本地额度记录