|
|
@@ -500,22 +500,27 @@ class InstitutionService:
|
|
|
@classmethod
|
|
|
async def modify_institution_service(
|
|
|
cls, auth: AuthSchema, data: AlipayEbppInvoiceInstitutionModifyModel, raw_data: dict | None = None
|
|
|
- ) -> AlipayEbppInvoiceInstitutionModifyResponse:
|
|
|
+ ) -> dict:
|
|
|
"""
|
|
|
编辑费控制度
|
|
|
调用: alipay.ebpp.invoice.institution.modify
|
|
|
|
|
|
支付宝成功后同步更新本地DB:
|
|
|
- 制度基本信息
|
|
|
+ - 适用员工范围(scope)
|
|
|
- 使用规则(standard_info_list → pay_expense_rule)
|
|
|
- 额度(issuerule → pay_expense_quota)
|
|
|
"""
|
|
|
if data.institution_id is None:
|
|
|
raise CustomException(msg="编辑费控制度失败: 制度ID不能为空")
|
|
|
|
|
|
+ institution_id = data.institution_id
|
|
|
+ enterprise_id = getattr(data, 'enterprise_id', None) or (raw_data or {}).get("enterprise_id", "")
|
|
|
+ raw_data = raw_data or {}
|
|
|
+
|
|
|
+ # 第1步:修改支付宝制度信息
|
|
|
request = AlipayEbppInvoiceInstitutionModifyRequest()
|
|
|
request.biz_model = data
|
|
|
-
|
|
|
response = await asyncio.to_thread(cls._execute_alipay, request)
|
|
|
|
|
|
if not response:
|
|
|
@@ -528,11 +533,27 @@ class InstitutionService:
|
|
|
log.error(f"支付宝接口调用失败: {result.code} - {result.msg}")
|
|
|
raise CustomException(msg=f"编辑费控制度失败: {result.msg}")
|
|
|
|
|
|
- # 同步更新本地数据库
|
|
|
- institution_id = getattr(data, 'institution_id', None)
|
|
|
- if not institution_id:
|
|
|
- return result
|
|
|
+ # 第2步:同步适用员工范围
|
|
|
+ applicable_scope = raw_data.get("applicable_scope", "")
|
|
|
+ if applicable_scope and applicable_scope not in ("NONE", "none"):
|
|
|
+ ADAPTER_MAP = {"all": "EMPLOYEE_ALL", "employee": "EMPLOYEE_SELECT", "department": "DEPARTMENT_SELECT"}
|
|
|
+ mapped = ADAPTER_MAP.get(applicable_scope, applicable_scope)
|
|
|
+ scope_payload = {
|
|
|
+ "enterprise_id": enterprise_id,
|
|
|
+ "adapter_type": mapped,
|
|
|
+ "owner_type": "ENTERPRISE_PAY_UID",
|
|
|
+ }
|
|
|
+ if applicable_scope == "employee" and raw_data.get("scope_owner_id_list"):
|
|
|
+ scope_payload["add_owner_id_list"] = raw_data["scope_owner_id_list"]
|
|
|
+ try:
|
|
|
+ await InstitutionScopeService.scope_modify_service(
|
|
|
+ auth=auth, institution_id=institution_id, data=scope_payload
|
|
|
+ )
|
|
|
+ log.info(f"适用员工范围已同步: {applicable_scope}")
|
|
|
+ except Exception as e:
|
|
|
+ log.warning(f"适用员工范围同步失败(不影响主流程): {e}")
|
|
|
|
|
|
+ # 第3步:同步更新本地数据库
|
|
|
try:
|
|
|
crud = InstitutionCRUD(auth)
|
|
|
update_data = {}
|
|
|
@@ -551,6 +572,8 @@ class InstitutionService:
|
|
|
update_data['effective_start_date'] = data.effective_start_date
|
|
|
if hasattr(data, 'effective_end_date') and data.effective_end_date:
|
|
|
update_data['effective_end_date'] = data.effective_end_date
|
|
|
+ if applicable_scope:
|
|
|
+ update_data['applicable_scope'] = applicable_scope
|
|
|
|
|
|
if update_data:
|
|
|
await crud.update_by_institution_id(institution_id, update_data)
|