Files
video/server/app/payment/usdt.py
T
2026-10-25 20:30:33 +08:00

18 lines
933 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""USDT (TRC20) 渠道:唯一金额生成。
USDT 无支付平台回调,到账由服务端每 15s 轮询 TronGrid 完成
(settle_service.poll_usdt_deposits,随 main.py lifespan 启动):
匹配条件 = 收款地址一致 + 金额(含尾差)精确相等 + 转账时间在订单有效期内 + 交易已固化(≥19 确认);
匹配成功即入账(tx_hash 写入 third_trade_no,唯一索引保证幂等)。
后台另有"人工补单"入口兜底(链上查询异常时手动核实入账)。
"""
import random
from decimal import ROUND_HALF_UP, Decimal
def gen_usdt_amount(amount_yuan: int, rate: Decimal) -> Decimal:
"""base(元/汇率) + 随机尾差(0.001~0.999),保留 3 位小数;有效期内金额唯一用于订单匹配"""
base = (Decimal(amount_yuan) / rate).quantize(Decimal("0.001"), rounding=ROUND_HALF_UP)
tail = Decimal(random.randint(1, 999)) / Decimal(1000)
return base + tail