|
|
@@ -375,15 +375,6 @@ async def modify_institution_controller(
|
|
|
|
|
|
if institution_id and enterprise_id and (new_amount is not None or new_single_limit is not None):
|
|
|
try:
|
|
|
- log.info(f"金额变更检测: grant_mode={grant_mode}, period_type={period_type}, new_amount={new_amount}, new_single_limit={new_single_limit}")
|
|
|
-
|
|
|
- def _to_dict(obj):
|
|
|
- """Alipay SDK 对象转 dict,已经是 dict 则直接返回"""
|
|
|
- if isinstance(obj, dict):
|
|
|
- return obj
|
|
|
- if hasattr(obj, 'to_alipay_dict'):
|
|
|
- return obj.to_alipay_dict()
|
|
|
- return {}
|
|
|
|
|
|
# 从支付宝查询当前制度详情
|
|
|
detail_dict = await InstitutionService.detailinfo_query_service(
|
|
|
@@ -392,88 +383,58 @@ async def modify_institution_controller(
|
|
|
|
|
|
# 构建 modify_standard_detail_info
|
|
|
modify_standard_list = []
|
|
|
- if detail_dict and detail_dict.get("standard_info_list"):
|
|
|
- std_list = detail_dict["standard_info_list"]
|
|
|
- log.info(f"找到 standard_info_list, 数量={len(std_list) if isinstance(std_list, list) else 1}")
|
|
|
+ if detail_dict:
|
|
|
+ std_list = detail_dict.get("standard_info_list") or []
|
|
|
if not isinstance(std_list, list):
|
|
|
std_list = [std_list]
|
|
|
- for std_obj in std_list:
|
|
|
- std = _to_dict(std_obj)
|
|
|
- std_id = std.get("standard_id")
|
|
|
- log.info(f"标准规则: std_id={std_id}, std={std}")
|
|
|
+ for std in std_list:
|
|
|
+ # 兼容 SDK 对象和 dict
|
|
|
+ std_id = std.standard_id if hasattr(std, 'standard_id') else std.get("standard_id", "")
|
|
|
if not std_id:
|
|
|
continue
|
|
|
- conditions = std.get("standard_condition_info_list") or []
|
|
|
+ conditions = std.standard_condition_info_list if hasattr(std, 'standard_condition_info_list') else (std.get("standard_condition_info_list") or [])
|
|
|
if not isinstance(conditions, list):
|
|
|
conditions = [conditions]
|
|
|
modify_condition_list = []
|
|
|
|
|
|
- for cond_obj in conditions:
|
|
|
- cond = _to_dict(cond_obj)
|
|
|
- cond_factor = cond.get("rule_factor", "")
|
|
|
- cond_id = cond.get("rule_id", "")
|
|
|
- log.info(f"条件: rule_factor={cond_factor}, rule_id={cond_id}, cond={cond}")
|
|
|
+ for cond in conditions:
|
|
|
+ cond_factor = cond.rule_factor if hasattr(cond, 'rule_factor') else cond.get("rule_factor", "")
|
|
|
+ cond_id = cond.rule_id if hasattr(cond, 'rule_id') else cond.get("rule_id", "")
|
|
|
+
|
|
|
+ PERIOD_FACTOR_MAP = {"daily": "QUOTA_DAY", "weekly": "QUOTA_WEEK", "monthly": "QUOTA_MONTH", "quarterly": "QUOTA_QUARTER", "yearly": "QUOTA_YEAR"}
|
|
|
|
|
|
# 周期限额变更
|
|
|
- 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",
|
|
|
- }
|
|
|
+ if grant_mode == "period" and period_type and new_amount is not None:
|
|
|
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 target_factor and cond_factor == target_factor:
|
|
|
+ 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),
|
|
|
- })
|
|
|
+ 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,
|
|
|
- })
|
|
|
+ modify_standard_list.append({"standard_id": std_id, "modify_condition_list": modify_condition_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}")
|
|
|
+ data["modify_standard_detail_info"] = {"modify_standard_list": modify_standard_list}
|
|
|
+ log.info(f"已构建金额变更: amount={new_amount}, single_limit={new_single_limit}")
|
|
|
|
|
|
- # 周期发放制度:更新发放规则金额 — 独立调 issuerule.modify
|
|
|
+ # 周期发放制度:独立调 issuerule.modify
|
|
|
if grant_mode == "period" and new_amount is not None and detail_dict:
|
|
|
issue_rule_list = detail_dict.get("issue_rule_info_list") or []
|
|
|
if not isinstance(issue_rule_list, list):
|
|
|
issue_rule_list = [issue_rule_list]
|
|
|
for rule in issue_rule_list:
|
|
|
- rule_dict = _to_dict(rule)
|
|
|
- issue_rule_id = rule_dict.get("issue_rule_id", "")
|
|
|
- if issue_rule_id:
|
|
|
- try:
|
|
|
- await IssueruleService.modify_issuerule_service(
|
|
|
- auth=auth,
|
|
|
- institution_id=institution_id,
|
|
|
- issue_rule_id=issue_rule_id,
|
|
|
- enterprise_id=enterprise_id,
|
|
|
- issue_amount_value=str(new_amount),
|
|
|
- )
|
|
|
- log.info(f"已同步发放规则金额: issue_rule_id={issue_rule_id}, amount={new_amount}")
|
|
|
- break
|
|
|
- except Exception as e:
|
|
|
- log.warning(f"同步发放规则失败(不影响制度修改): {e}")
|
|
|
- else:
|
|
|
- log.warning(f"未查询到制度详情,跳过金额同步: institution_id={institution_id}")
|
|
|
+ ir_id = rule.issue_rule_id if hasattr(rule, 'issue_rule_id') else rule.get("issue_rule_id", "")
|
|
|
+ if ir_id:
|
|
|
+ await IssueruleService.modify_issuerule_service(
|
|
|
+ auth=auth, institution_id=institution_id,
|
|
|
+ issue_rule_id=ir_id, enterprise_id=enterprise_id,
|
|
|
+ issue_amount_value=str(new_amount),
|
|
|
+ )
|
|
|
+ log.info(f"已同步发放规则金额: issue_rule_id={ir_id}")
|
|
|
+ break
|
|
|
except Exception as e:
|
|
|
log.warning(f"构建标准规则变更信息失败(将跳过金额同步): {e}")
|
|
|
|