|
|
@@ -373,53 +373,61 @@ async def modify_institution_controller(
|
|
|
period_type = data.get("period_type", "")
|
|
|
grant_mode = data.get("grant_mode", "")
|
|
|
|
|
|
- if institution_id and (new_amount is not None or new_single_limit is not None):
|
|
|
+ if institution_id and enterprise_id and (new_amount is not None or new_single_limit is not None):
|
|
|
try:
|
|
|
- from app.plugin.module_payment.expense.rule.model import ExpenseRuleModel
|
|
|
- from sqlalchemy import select as sa_select
|
|
|
- stmt = sa_select(ExpenseRuleModel).where(
|
|
|
- ExpenseRuleModel.institution_id == institution_id
|
|
|
+ # 从支付宝查询当前制度的 standard_info_list,获取现有 condition 的 rule_id
|
|
|
+ detail_dict = await InstitutionService.detailinfo_query_service(
|
|
|
+ auth=auth, institution_id=institution_id, enterprise_id=enterprise_id
|
|
|
)
|
|
|
- exec_result = await auth.db.execute(stmt)
|
|
|
- rules = exec_result.scalars().all()
|
|
|
-
|
|
|
- modify_standard_list = []
|
|
|
- for rule in rules:
|
|
|
- if not rule.rule_id:
|
|
|
- continue
|
|
|
- std_item = {"standard_id": rule.rule_id}
|
|
|
- condition_list = []
|
|
|
-
|
|
|
- if new_single_limit is not None:
|
|
|
- condition_list.append({
|
|
|
- "rule_factor": "QUOTA_TOTAL",
|
|
|
- "rule_name": "单次消费金额",
|
|
|
- "rule_value": str(new_single_limit),
|
|
|
- })
|
|
|
-
|
|
|
- if grant_mode == "period" and period_type and new_amount:
|
|
|
- PERIOD_FACTOR_MAP = {
|
|
|
- "daily": "QUOTA_DAY", "weekly": "QUOTA_WEEK",
|
|
|
- "monthly": "QUOTA_MONTH", "quarterly": "QUOTA_QUARTER",
|
|
|
- "yearly": "QUOTA_YEAR",
|
|
|
- }
|
|
|
- factor = PERIOD_FACTOR_MAP.get(period_type)
|
|
|
- if factor:
|
|
|
- condition_list.append({
|
|
|
- "rule_factor": factor,
|
|
|
- "rule_name": f"{period_type}限额",
|
|
|
- "rule_value": str(new_amount),
|
|
|
+ if detail_dict and detail_dict.get("standard_info_list"):
|
|
|
+ modify_standard_list = []
|
|
|
+ for std in detail_dict["standard_info_list"]:
|
|
|
+ std_id = std.get("standard_id")
|
|
|
+ if not std_id:
|
|
|
+ continue
|
|
|
+ conditions = std.get("standard_condition_info_list") or []
|
|
|
+ modify_condition_list = []
|
|
|
+
|
|
|
+ for cond in conditions:
|
|
|
+ cond_factor = cond.get("rule_factor", "")
|
|
|
+ cond_id = cond.get("rule_id", "")
|
|
|
+
|
|
|
+ # 周期限额变更
|
|
|
+ if grant_mode == "period" and period_type:
|
|
|
+ PERIOD_FACTOR_MAP = {
|
|
|
+ "daily": "QUOTA_DAY", "weekly": "QUOTA_WEEK",
|
|
|
+ "monthly": "QUOTA_MONTH", "quarterly": "QUOTA_QUARTER",
|
|
|
+ "yearly": "QUOTA_YEAR",
|
|
|
+ }
|
|
|
+ target_factor = PERIOD_FACTOR_MAP.get(period_type)
|
|
|
+ if target_factor and cond_factor == target_factor and new_amount is not None:
|
|
|
+ modify_condition_list.append({
|
|
|
+ "rule_id": cond_id,
|
|
|
+ "rule_factor": cond_factor,
|
|
|
+ "rule_value": str(new_amount),
|
|
|
+ })
|
|
|
+
|
|
|
+ # 单笔限额变更
|
|
|
+ if cond_factor == "QUOTA_TOTAL" and new_single_limit is not None:
|
|
|
+ modify_condition_list.append({
|
|
|
+ "rule_id": cond_id,
|
|
|
+ "rule_factor": "QUOTA_TOTAL",
|
|
|
+ "rule_value": str(new_single_limit),
|
|
|
+ })
|
|
|
+
|
|
|
+ if modify_condition_list:
|
|
|
+ modify_standard_list.append({
|
|
|
+ "standard_id": std_id,
|
|
|
+ "modify_condition_list": modify_condition_list,
|
|
|
})
|
|
|
|
|
|
- if condition_list:
|
|
|
- std_item["standard_condition_info_list"] = condition_list
|
|
|
- modify_standard_list.append(std_item)
|
|
|
-
|
|
|
- if modify_standard_list:
|
|
|
- data["modify_standard_detail_info"] = {
|
|
|
- "modify_standard_list": modify_standard_list
|
|
|
- }
|
|
|
- log.info(f"已构建金额变更信息: amount={new_amount}, single_limit={new_single_limit}, rules_count={len(modify_standard_list)}")
|
|
|
+ if modify_standard_list:
|
|
|
+ data["modify_standard_detail_info"] = {
|
|
|
+ "modify_standard_list": modify_standard_list
|
|
|
+ }
|
|
|
+ log.info(f"已构建金额变更信息: amount={new_amount}, single_limit={new_single_limit}, rules={len(modify_standard_list)}")
|
|
|
+ else:
|
|
|
+ log.warning(f"未查询到制度详情,跳过金额同步: institution_id={institution_id}")
|
|
|
except Exception as e:
|
|
|
log.warning(f"构建标准规则变更信息失败(将跳过金额同步): {e}")
|
|
|
|