|
|
@@ -375,59 +375,71 @@ 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:
|
|
|
-
|
|
|
- # 从支付宝查询当前制度详情
|
|
|
- detail_dict = await InstitutionService.detailinfo_query_service(
|
|
|
- auth=auth, institution_id=institution_id, enterprise_id=enterprise_id
|
|
|
+ import json as _json
|
|
|
+ from alipay.aop.api.request.AlipayEbppInvoiceInstitutionDetailinfoQueryRequest import (
|
|
|
+ AlipayEbppInvoiceInstitutionDetailinfoQueryRequest,
|
|
|
+ )
|
|
|
+ from alipay.aop.api.domain.AlipayEbppInvoiceInstitutionDetailinfoQueryModel import (
|
|
|
+ AlipayEbppInvoiceInstitutionDetailinfoQueryModel,
|
|
|
+ )
|
|
|
+ from alipay.aop.api.response.AlipayEbppInvoiceInstitutionDetailinfoQueryResponse import (
|
|
|
+ AlipayEbppInvoiceInstitutionDetailinfoQueryResponse,
|
|
|
)
|
|
|
+ from app.core.alipay.client import AlipayClient
|
|
|
+
|
|
|
+ # 直接调支付宝 API,绕过 SDK 的单元素 bug
|
|
|
+ detail_model = AlipayEbppInvoiceInstitutionDetailinfoQueryModel()
|
|
|
+ detail_model.enterprise_id = enterprise_id
|
|
|
+ detail_model.institution_id = institution_id
|
|
|
+ detail_req = AlipayEbppInvoiceInstitutionDetailinfoQueryRequest()
|
|
|
+ detail_req.biz_model = detail_model
|
|
|
+ detail_resp = AlipayClient.get_client().execute(detail_req)
|
|
|
+ detail_raw = {}
|
|
|
+
|
|
|
+ if detail_resp:
|
|
|
+ parsed = AlipayEbppInvoiceInstitutionDetailinfoQueryResponse()
|
|
|
+ parsed.parse_response_content(detail_resp)
|
|
|
+ resp_body = _json.loads(detail_resp)
|
|
|
+ detail_raw = resp_body.get("alipay_ebpp_invoice_institution_detailinfo_query_response", {})
|
|
|
|
|
|
# 构建 modify_standard_detail_info
|
|
|
modify_standard_list = []
|
|
|
- if detail_dict and detail_dict.get("standard_info_list"):
|
|
|
- std_list = detail_dict["standard_info_list"]
|
|
|
- if not isinstance(std_list, list):
|
|
|
- std_list = [std_list]
|
|
|
- for std in std_list:
|
|
|
- std_dict = std.to_alipay_dict() if hasattr(std, 'to_alipay_dict') else (std if isinstance(std, dict) else {})
|
|
|
- import json as _json; import sys; sys.stderr.write(f"STD_TO_DICT: {_json.dumps(std_dict, ensure_ascii=False)}\n")
|
|
|
- std_id = std_dict.get("standard_id", "")
|
|
|
- if not std_id:
|
|
|
- continue
|
|
|
- conditions = std_dict.get("standard_condition_info_list") or []
|
|
|
- if not isinstance(conditions, list):
|
|
|
- conditions = [conditions]
|
|
|
- modify_condition_list = []
|
|
|
-
|
|
|
- for cond in conditions:
|
|
|
- cond_dict = cond.to_alipay_dict() if hasattr(cond, 'to_alipay_dict') else (cond if isinstance(cond, dict) else {})
|
|
|
- cond_factor = cond_dict.get("rule_factor", "")
|
|
|
- cond_id = cond_dict.get("rule_id", "")
|
|
|
-
|
|
|
- PERIOD_FACTORS = {"QUOTA_DAY", "QUOTA_WEEK", "QUOTA_MONTH", "QUOTA_QUARTER", "QUOTA_YEAR"}
|
|
|
-
|
|
|
- # 周期限额变更(匹配所有 QUOTA_* 因子)
|
|
|
- if grant_mode == "period" and new_amount is not None and cond_factor in PERIOD_FACTORS:
|
|
|
- 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})
|
|
|
+ std_list = detail_raw.get("standard_info_list") or []
|
|
|
+ if not isinstance(std_list, list):
|
|
|
+ std_list = [std_list]
|
|
|
+ for std in std_list:
|
|
|
+ std_id = std.get("standard_id", "")
|
|
|
+ if not std_id:
|
|
|
+ continue
|
|
|
+ conditions = std.get("standard_condition_info_list") or []
|
|
|
+ if not isinstance(conditions, list):
|
|
|
+ conditions = [conditions]
|
|
|
+ modify_condition_list = []
|
|
|
+
|
|
|
+ for cond in conditions:
|
|
|
+ cond_factor = cond.get("rule_factor", "")
|
|
|
+ cond_id = cond.get("rule_id", "")
|
|
|
+ PERIOD_FACTORS = {"QUOTA_DAY", "QUOTA_WEEK", "QUOTA_MONTH", "QUOTA_QUARTER", "QUOTA_YEAR"}
|
|
|
+
|
|
|
+ if grant_mode == "period" and new_amount is not None and cond_factor in PERIOD_FACTORS:
|
|
|
+ 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 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}")
|
|
|
+ log.info(f"已构建金额变更: amount={new_amount}")
|
|
|
|
|
|
# 周期发放制度:独立调 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 grant_mode == "period" and new_amount is not None:
|
|
|
+ issue_rule_list = detail_raw.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 = rule.to_alipay_dict() if hasattr(rule, 'to_alipay_dict') else (rule if isinstance(rule, dict) else {})
|
|
|
- ir_id = rule_dict.get("issue_rule_id", "")
|
|
|
+ ir_id = rule.get("issue_rule_id", "")
|
|
|
if ir_id:
|
|
|
await IssueruleService.modify_issuerule_service(
|
|
|
auth=auth, institution_id=institution_id,
|