feat(points): 充值档位添加积分有效期字段
- config/points-config.yaml: 每个档位添加 validity_days(7/30/90/180/365/0) - points.py: 支付回调和主动查询补单时根据档位配置设置 batch_expired_at - RechargeModal: 卡片展示有效期(永久有效 / N 天内有效)
This commit is contained in:
@@ -329,6 +329,21 @@ async def handle_wxpay_notify(
|
||||
await db.commit() # 提交 notify_raw 等记录
|
||||
return _wx_response()
|
||||
|
||||
# 根据档位确定积分有效期
|
||||
validity_days = point_service.EXPIRATION_DAYS
|
||||
for opt in point_service.get_recharge_options():
|
||||
if opt.get("points") == order.points and opt.get("price") == order.amount_rmb:
|
||||
validity_days = opt.get("validity_days", point_service.EXPIRATION_DAYS)
|
||||
break
|
||||
|
||||
if validity_days is not None and validity_days > 0:
|
||||
batch_expired_at = datetime.now(UTC) + timedelta(days=validity_days)
|
||||
elif validity_days == 0:
|
||||
# 永久有效
|
||||
batch_expired_at = datetime.now(UTC) + timedelta(days=36500)
|
||||
else:
|
||||
batch_expired_at = None
|
||||
|
||||
# 更新订单状态并充值积分(同一事务)
|
||||
try:
|
||||
order.status = "paid"
|
||||
@@ -342,6 +357,7 @@ async def handle_wxpay_notify(
|
||||
source="wxpay",
|
||||
description=f"微信支付充值 {order.points} 积分",
|
||||
order_id=order.id,
|
||||
batch_expired_at=batch_expired_at,
|
||||
)
|
||||
|
||||
await db.commit()
|
||||
@@ -397,6 +413,20 @@ async def query_recharge_status(
|
||||
order.paid_at = datetime.now(UTC)
|
||||
order.wx_order_no = wx_result.get("transaction_id")
|
||||
|
||||
# 根据档位确定积分有效期
|
||||
validity_days = point_service.EXPIRATION_DAYS
|
||||
for opt in point_service.get_recharge_options():
|
||||
if opt.get("points") == order.points and opt.get("price") == order.amount_rmb:
|
||||
validity_days = opt.get("validity_days", point_service.EXPIRATION_DAYS)
|
||||
break
|
||||
|
||||
if validity_days is not None and validity_days > 0:
|
||||
batch_expired_at = datetime.now(UTC) + timedelta(days=validity_days)
|
||||
elif validity_days == 0:
|
||||
batch_expired_at = datetime.now(UTC) + timedelta(days=36500)
|
||||
else:
|
||||
batch_expired_at = None
|
||||
|
||||
await point_service.recharge(
|
||||
db,
|
||||
user_id=order.user_id,
|
||||
@@ -404,6 +434,7 @@ async def query_recharge_status(
|
||||
source="wxpay",
|
||||
description=f"微信支付充值 {order.points} 积分(主动查询补单)",
|
||||
order_id=order.id,
|
||||
batch_expired_at=batch_expired_at,
|
||||
)
|
||||
logger.info(
|
||||
f"[Points] 订单 {order.out_trade_no} 通过主动查询确认支付成功,"
|
||||
|
||||
Reference in New Issue
Block a user