|
|
@@ -590,10 +590,61 @@ class QuotaService:
|
|
|
) -> dict:
|
|
|
crud = QuotaCRUD(auth)
|
|
|
offset = (page_no - 1) * page_size
|
|
|
- return await crud.page(
|
|
|
+ result = await crud.page(
|
|
|
offset=offset,
|
|
|
limit=page_size,
|
|
|
order_by=[{"id": "desc"}],
|
|
|
search=search or {},
|
|
|
out_schema=QuotaListOutSchema,
|
|
|
)
|
|
|
+ # 如果指定了 institution_id,同时查询支付宝端自动发放的额度
|
|
|
+ if search and search.get("institution_id"):
|
|
|
+ try:
|
|
|
+ from alipay.aop.api.request.AlipayEbppInvoiceExpensecontrolQuotaQueryRequest import (
|
|
|
+ AlipayEbppInvoiceExpensecontrolQuotaQueryRequest,
|
|
|
+ )
|
|
|
+ from alipay.aop.api.domain.AlipayEbppInvoiceExpensecontrolQuotaQueryModel import (
|
|
|
+ AlipayEbppInvoiceExpensecontrolQuotaQueryModel,
|
|
|
+ )
|
|
|
+ from alipay.aop.api.response.AlipayEbppInvoiceExpensecontrolQuotaQueryResponse import (
|
|
|
+ AlipayEbppInvoiceExpensecontrolQuotaQueryResponse,
|
|
|
+ )
|
|
|
+
|
|
|
+ alipay_model = AlipayEbppInvoiceExpensecontrolQuotaQueryModel()
|
|
|
+ alipay_model.target_type = "INSTITUTION"
|
|
|
+ alipay_model.target_id = search["institution_id"]
|
|
|
+ alipay_model.page_size = 100
|
|
|
+ alipay_model.page_num = 1
|
|
|
+
|
|
|
+ request = AlipayEbppInvoiceExpensecontrolQuotaQueryRequest()
|
|
|
+ request.biz_model = alipay_model
|
|
|
+
|
|
|
+ client = AlipayClient.get_client()
|
|
|
+ response = client.execute(request)
|
|
|
+
|
|
|
+ if response:
|
|
|
+ alipay_result = AlipayEbppInvoiceExpensecontrolQuotaQueryResponse()
|
|
|
+ alipay_result.parse_response_content(response)
|
|
|
+ if alipay_result.is_success() and hasattr(alipay_result, 'quota_detail_info_list') and alipay_result.quota_detail_info_list:
|
|
|
+ # 将支付宝端额度合并到结果中(去重)
|
|
|
+ existing_ids = {item.get("quota_id") for item in result.get("items", []) if item.get("quota_id")}
|
|
|
+ for q in alipay_result.quota_detail_info_list:
|
|
|
+ qid = getattr(q, 'quota_id', None)
|
|
|
+ if qid and qid not in existing_ids:
|
|
|
+ result["items"].append({
|
|
|
+ "quota_id": qid,
|
|
|
+ "target_type": getattr(q, 'target_type', None),
|
|
|
+ "target_id": getattr(q, 'target_id', None),
|
|
|
+ "quota_type": getattr(q, 'quota_type', None),
|
|
|
+ "employee_id": getattr(q, 'owner_id', None),
|
|
|
+ "total_amount": getattr(q, 'total_amount', None),
|
|
|
+ "available_amount": getattr(q, 'available_amount', None),
|
|
|
+ "status": getattr(q, 'status', "QUOTA_ACTIVE"),
|
|
|
+ "created_time": getattr(q, 'effective_start_date', None),
|
|
|
+ })
|
|
|
+ existing_ids.add(qid)
|
|
|
+ result["total"] = len(result["items"])
|
|
|
+ except Exception as e:
|
|
|
+ log.warning(f"查询支付宝端额度失败(不影响本地数据): {e}")
|
|
|
+
|
|
|
+ return result
|