|
@@ -39,12 +39,20 @@ class BillHandler(BaseHandler[dict]):
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
async def _process_bill(self, data: ConsumeChangeContent, auth: AuthSchema) -> bool:
|
|
async def _process_bill(self, data: ConsumeChangeContent, auth: AuthSchema) -> bool:
|
|
|
- """处理账单"""
|
|
|
|
|
|
|
+ """处理账单变动通知
|
|
|
|
|
+
|
|
|
|
|
+ 支付宝文档: alipay.commerce.ec.consume.change.notify
|
|
|
|
|
+ consume_type 标准枚举: CONSUME(消费), REFUND(退款)
|
|
|
|
|
+ notify_reason 标准枚举: COLLECT(归集), SUMMARY_SUCCESS(汇总成功), ORDER_COMPLETE(完结)
|
|
|
|
|
+
|
|
|
|
|
+ 注: TRANSFER(转账) 为支付宝企业码扩展值,不在标准文档枚举中
|
|
|
|
|
+ """
|
|
|
log.info(
|
|
log.info(
|
|
|
f"账单变动: pay_no={data.pay_no}, "
|
|
f"账单变动: pay_no={data.pay_no}, "
|
|
|
f"enterprise_id={data.enterprise_id}, "
|
|
f"enterprise_id={data.enterprise_id}, "
|
|
|
f"consume_amount={data.consume_amount}, "
|
|
f"consume_amount={data.consume_amount}, "
|
|
|
- f"consume_type={data.consume_type}"
|
|
|
|
|
|
|
+ f"consume_type={data.consume_type}, "
|
|
|
|
|
+ f"notify_reason={data.notify_reason}"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
# 1. 保存账单基础数据
|
|
# 1. 保存账单基础数据
|
|
@@ -61,13 +69,40 @@ class BillHandler(BaseHandler[dict]):
|
|
|
# if detail:
|
|
# if detail:
|
|
|
# await self._save_bill_detail(detail, auth)
|
|
# await self._save_bill_detail(detail, auth)
|
|
|
|
|
|
|
|
- # 处理转账类型
|
|
|
|
|
- if data.consume_type == "TRANSFER":
|
|
|
|
|
|
|
+ # ========== 标准消费通知 ==========
|
|
|
|
|
+ if data.consume_type == "CONSUME":
|
|
|
|
|
+ log.info(f"消费账单通知: pay_no={data.pay_no}, amount={data.consume_amount}, reason={data.notify_reason}")
|
|
|
|
|
+
|
|
|
|
|
+ elif data.consume_type == "REFUND":
|
|
|
|
|
+ log.info(
|
|
|
|
|
+ f"退款账单通知: pay_no={data.pay_no}, "
|
|
|
|
|
+ f"related_pay_no={data.related_pay_no}, "
|
|
|
|
|
+ f"amount={data.consume_amount}"
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # ========== 转账通知(企业码扩展) ==========
|
|
|
|
|
+ elif data.consume_type == "TRANSFER":
|
|
|
|
|
+ from app.plugin.module_payment.account.enums import TransferStatusEnum
|
|
|
|
|
+
|
|
|
|
|
+ reason = (data.notify_reason or "").upper()
|
|
|
|
|
+ if "SUCCESS" in reason:
|
|
|
|
|
+ status = TransferStatusEnum.SUCCESS.value
|
|
|
|
|
+ elif "FAIL" in reason:
|
|
|
|
|
+ status = TransferStatusEnum.FAIL.value
|
|
|
|
|
+ else:
|
|
|
|
|
+ status = TransferStatusEnum.DEALING.value
|
|
|
|
|
+ log.warning(f"转账状态无法判断: pay_no={data.pay_no}, notify_reason={data.notify_reason}")
|
|
|
|
|
+
|
|
|
await AccountService.update_transfer_status_service(
|
|
await AccountService.update_transfer_status_service(
|
|
|
- auth, data.pay_no, "SUCCESS", data.model_dump(exclude_none=True)
|
|
|
|
|
|
|
+ auth, data.pay_no, status, data.model_dump(exclude_none=True)
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+ # 无论成功/失败都回调商户,告知最终结果
|
|
|
await OpenTransferService.open_return_service(auth, data.pay_no)
|
|
await OpenTransferService.open_return_service(auth, data.pay_no)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ else:
|
|
|
|
|
+ log.info(f"未知账单类型: consume_type={data.consume_type}, pay_no={data.pay_no}")
|
|
|
|
|
+
|
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
async def _save_bill_base(self, data: ConsumeChangeContent, auth: AuthSchema) -> None:
|
|
async def _save_bill_base(self, data: ConsumeChangeContent, auth: AuthSchema) -> None:
|