|
|
@@ -875,25 +875,25 @@ class AccountService:
|
|
|
|
|
|
now = datetime.now()
|
|
|
if not end_date:
|
|
|
- end_date = now.strftime("%Y%m%d")
|
|
|
+ end_date = now.strftime("%Y-%m-%d 23:59:59")
|
|
|
if not start_date:
|
|
|
- start_date = (now - timedelta(days=90)).strftime("%Y%m%d")
|
|
|
+ start_date = (now - timedelta(days=90)).strftime("%Y-%m-%d 00:00:00")
|
|
|
|
|
|
- # 检查 consume.detail.batchquery 是否可用
|
|
|
+ # 检查 jointaccountbill.detail.batchquery 是否可用
|
|
|
_can_batch = False
|
|
|
try:
|
|
|
- from alipay.aop.api.request.AlipayCommerceEcConsumeDetailBatchqueryRequest import (
|
|
|
- AlipayCommerceEcConsumeDetailBatchqueryRequest,
|
|
|
+ from alipay.aop.api.request.AlipayCommerceEcJointaccountbillDetailBatchqueryRequest import (
|
|
|
+ AlipayCommerceEcJointaccountbillDetailBatchqueryRequest,
|
|
|
)
|
|
|
- from alipay.aop.api.domain.AlipayCommerceEcConsumeDetailBatchqueryModel import (
|
|
|
- AlipayCommerceEcConsumeDetailBatchqueryModel,
|
|
|
+ from alipay.aop.api.domain.AlipayCommerceEcJointaccountbillDetailBatchqueryModel import (
|
|
|
+ AlipayCommerceEcJointaccountbillDetailBatchqueryModel,
|
|
|
)
|
|
|
- from alipay.aop.api.response.AlipayCommerceEcConsumeDetailBatchqueryResponse import (
|
|
|
- AlipayCommerceEcConsumeDetailBatchqueryResponse,
|
|
|
+ from alipay.aop.api.response.AlipayCommerceEcJointaccountbillDetailBatchqueryResponse import (
|
|
|
+ AlipayCommerceEcJointaccountbillDetailBatchqueryResponse,
|
|
|
)
|
|
|
_can_batch = True
|
|
|
except ImportError:
|
|
|
- log.warning("SDK 不支持 consume.detail.batchquery,降级为仅同步 DEALING 转账")
|
|
|
+ log.warning("SDK 不支持 jointaccountbill.detail.batchquery,降级为仅同步 DEALING 转账")
|
|
|
|
|
|
from app.core.alipay import AlipayClient
|
|
|
|
|
|
@@ -917,7 +917,7 @@ class AccountService:
|
|
|
"bill_synced": 0,
|
|
|
"transfer_synced": 0,
|
|
|
"details": [{"out_biz_no": t.out_biz_no, "status": "DEALING", "hint": "手动同步"} for t in dealing],
|
|
|
- "note": "SDK不支持批量查询,请逐一使用 sync-status 同步",
|
|
|
+ "note": "SDK不支持 jointaccountbill 批量查询,请逐一使用 sync-status 同步",
|
|
|
}
|
|
|
|
|
|
client = AlipayClient.get_client()
|
|
|
@@ -936,21 +936,22 @@ class AccountService:
|
|
|
|
|
|
while True:
|
|
|
try:
|
|
|
- batch_model = AlipayCommerceEcConsumeDetailBatchqueryModel()
|
|
|
+ batch_model = AlipayCommerceEcJointaccountbillDetailBatchqueryModel()
|
|
|
batch_model.enterprise_id = eid
|
|
|
+ batch_model.biz_scene = "ISV_DEFAULT"
|
|
|
batch_model.start_date = start_date
|
|
|
batch_model.end_date = end_date
|
|
|
batch_model.page_num = page_num
|
|
|
batch_model.page_size = page_size
|
|
|
|
|
|
- request = AlipayCommerceEcConsumeDetailBatchqueryRequest()
|
|
|
+ request = AlipayCommerceEcJointaccountbillDetailBatchqueryRequest()
|
|
|
request.biz_model = batch_model
|
|
|
|
|
|
response = client.execute(request)
|
|
|
if not response:
|
|
|
break
|
|
|
|
|
|
- batch_result = AlipayCommerceEcConsumeDetailBatchqueryResponse()
|
|
|
+ batch_result = AlipayCommerceEcJointaccountbillDetailBatchqueryResponse()
|
|
|
batch_result.parse_response_content(response)
|
|
|
if not batch_result.is_success():
|
|
|
errors += 1
|
|
|
@@ -959,11 +960,11 @@ class AccountService:
|
|
|
log.warning(f"全量同步 - 企业 {eid} 第 {page_num} 页查询失败: [{err_code}] {err_msg}")
|
|
|
break
|
|
|
|
|
|
- consume_list = getattr(batch_result, 'consume_info_list', None)
|
|
|
- if not consume_list:
|
|
|
+ bill_list = getattr(batch_result, 'bill_list', None)
|
|
|
+ if not bill_list:
|
|
|
break
|
|
|
|
|
|
- for c in consume_list:
|
|
|
+ for c in bill_list:
|
|
|
total_records += 1
|
|
|
pay_no = getattr(c, 'pay_no', None)
|
|
|
consume_type = getattr(c, 'consume_type', None)
|
|
|
@@ -1049,8 +1050,8 @@ class AccountService:
|
|
|
log.warning(f"全量同步 - 企业 {eid} 第 {page_num} 页异常: {e}", exc_info=True)
|
|
|
break
|
|
|
|
|
|
- # 翻页:API 无 total_page_count,用返回条数判断
|
|
|
- if len(consume_list) < page_size:
|
|
|
+ # 翻页:用 has_next_page 判断
|
|
|
+ if not getattr(batch_result, 'has_next_page', False):
|
|
|
break
|
|
|
page_num += 1
|
|
|
|
|
|
@@ -1064,7 +1065,7 @@ class AccountService:
|
|
|
"transfer_detail_synced": transfer_detail_synced,
|
|
|
"errors": errors,
|
|
|
"date_range": {"start": start_date, "end": end_date},
|
|
|
- "note": "pay_bill 已同步,TRANSFER 类型记录已写入/更新 pay_transfer",
|
|
|
+ "note": "使用 jointaccountbill.detail.batchquery 拉取,pay_bill 已同步,TRANSFER 已写入 pay_transfer",
|
|
|
}
|
|
|
|
|
|
@classmethod
|