first commit
This commit is contained in:
@@ -0,0 +1,433 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/global"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/dto"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/mysqldao"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/mysqlmodel"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/redisdao"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/internal/redismodel"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/pkg/errcode"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-backend/pkg/wechat"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// VirtualOrderCreate 创建虚拟支付订单:本地落单(pay_channel=2)并返回前端调起
|
||||
// wx.requestVirtualPayment 所需的 signData / paySig / signature。
|
||||
func (s *OrderService) VirtualOrderCreate(ctx context.Context, userID int64, request *dto.VirtualOrderCreateRequest) (*dto.VirtualOrderCreateResponse, *errcode.Error) {
|
||||
ctx, span := global.Tracer.Start(ctx, "svc.VirtualOrderCreate")
|
||||
defer span.End()
|
||||
|
||||
if !wechat.IsVirtualPayEnabled() {
|
||||
return nil, errcode.VirtualPayNotEnabled
|
||||
}
|
||||
// 订单记录当前激活的虚拟支付环境(现网 0 / 沙箱 1),发货推送按此校验。
|
||||
xpayEnv, verr := wechat.GetVirtualPayEnv()
|
||||
if verr != nil {
|
||||
return nil, errcode.VirtualPayNotEnabled
|
||||
}
|
||||
|
||||
goods, err := s.goodsDao.GoodsGetByCode(ctx, request.GoodsCode)
|
||||
if err != nil {
|
||||
if isNotFound(err) {
|
||||
return nil, errcode.GoodsNotFound
|
||||
}
|
||||
return nil, errcode.DatabaseError
|
||||
}
|
||||
if goods.Status != GoodsStatusOnShelf {
|
||||
return nil, errcode.GoodsOffShelf
|
||||
}
|
||||
if goods.ProductID == "" || goods.ProductStatus != GoodsProductPublished {
|
||||
return nil, errcode.VirtualPayGoodsNotPublished
|
||||
}
|
||||
// iOS 端微信限制最低支付 1 元(100 分),低于此金额调起支付必失败,提前拒绝以降低垃圾订单。
|
||||
// 注意:platform 由前端上报(不可作为安全边界,可伪造为 android 绕过此限制);
|
||||
// 此校验仅作体验优化,不构成资损防线——真正的资损防线是发货推送 verifyXPayOrderPaid
|
||||
// 对微信侧订单真实性、金额、道具的反查。低金额商品在 iOS 上的垃圾订单靠过期清理兜底。
|
||||
if request.Platform == XPayPlatformIOS && goods.DiscountPrice < 100 {
|
||||
return nil, errcode.VirtualPayAmountTooLow
|
||||
}
|
||||
|
||||
// 虚拟支付 signature 依赖用户 session_key(登录时缓存),缺失说明需重新登录。
|
||||
sessionKey, serr := redisdao.AuthSessionKeyGet(ctx, userID)
|
||||
if serr != nil {
|
||||
if serr == redis.Nil {
|
||||
return nil, errcode.UnauthorizedTokenError.WithDetails("缺少 session_key,请重新登录")
|
||||
}
|
||||
return nil, errcode.CacheError
|
||||
}
|
||||
|
||||
orderNo := genOrderNo()
|
||||
expireTime := nowUnix() + orderPayTTLSeconds
|
||||
payAmount := goods.DiscountPrice
|
||||
platform := request.Platform
|
||||
|
||||
order := &mysqlmodel.Order{
|
||||
OrderNo: orderNo,
|
||||
UserID: userID,
|
||||
GoodsID: goods.ID,
|
||||
GoodsName: goods.GoodsName,
|
||||
UnitPrice: goods.DiscountPrice,
|
||||
TotalAmount: payAmount,
|
||||
PayAmount: payAmount,
|
||||
PayChannel: PayChannelVirtual,
|
||||
OrderStatus: OrderStatusPending,
|
||||
MemberDays: goods.MemberDays,
|
||||
CosQuota: goods.CosQuota,
|
||||
AIRecommendQuota: goods.AIRecommendQuota,
|
||||
ClosetShareQuota: goods.ClosetShareQuota,
|
||||
OutfitShareQuota: goods.OutfitShareQuota,
|
||||
ExpireTime: expireTime,
|
||||
XPayProductID: goods.ProductID,
|
||||
XPayPlatform: platform,
|
||||
XPayEnv: int8(xpayEnv),
|
||||
}
|
||||
if cerr := s.orderDao.OrderCreate(ctx, order); cerr != nil {
|
||||
return nil, errcode.VirtualOrderCreateFailed
|
||||
}
|
||||
|
||||
sign, perr := wechat.BuildPaymentSign(
|
||||
global.VirtualPaySetting.OfferID,
|
||||
goods.ProductID,
|
||||
orderNo,
|
||||
"",
|
||||
sessionKey,
|
||||
payAmount,
|
||||
)
|
||||
if perr != nil {
|
||||
return nil, errcode.VirtualOrderCreateFailed
|
||||
}
|
||||
|
||||
return &dto.VirtualOrderCreateResponse{
|
||||
OrderNo: orderNo,
|
||||
PayAmount: payAmount,
|
||||
ExpireTime: expireTime,
|
||||
SignData: sign.SignData,
|
||||
PaySig: sign.PaySig,
|
||||
Signature: sign.Signature,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ---- 消息推送回调 ----
|
||||
|
||||
// XPayNotify 处理虚拟支付消息推送(发货/退款/iOS 退款问询/其它),返回应答报文。
|
||||
func (s *OrderService) XPayNotify(ctx context.Context, raw []byte) []byte {
|
||||
ctx, span := global.Tracer.Start(ctx, "svc.XPayNotify")
|
||||
defer span.End()
|
||||
|
||||
base, err := wechat.ParseNotify(raw)
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "xpay notify parse failed", "error", err)
|
||||
return wechat.BuildNotifyResponse(false)
|
||||
}
|
||||
|
||||
switch base.Event {
|
||||
case wechat.EventGoodsDeliverNotify:
|
||||
var deliver wechat.XPayGoodsDeliverNotify
|
||||
if err := json.Unmarshal(raw, &deliver); err != nil {
|
||||
slog.ErrorContext(ctx, "xpay deliver notify decode failed", "error", err)
|
||||
return wechat.BuildNotifyResponse(false)
|
||||
}
|
||||
if e := s.handleGoodsDeliver(ctx, &deliver, string(raw)); e != nil {
|
||||
slog.ErrorContext(ctx, "xpay deliver notify handle failed", "error", e)
|
||||
return wechat.BuildNotifyResponse(false)
|
||||
}
|
||||
return wechat.BuildNotifyResponse(true)
|
||||
|
||||
case wechat.EventRefundNotify:
|
||||
var refund wechat.XPayRefundNotify
|
||||
if err := json.Unmarshal(raw, &refund); err != nil {
|
||||
slog.ErrorContext(ctx, "xpay refund notify decode failed", "error", err)
|
||||
return wechat.BuildNotifyResponse(false)
|
||||
}
|
||||
if e := s.handleRefundNotify(ctx, &refund); e != nil {
|
||||
slog.ErrorContext(ctx, "xpay refund notify handle failed", "error", e)
|
||||
return wechat.BuildNotifyResponse(false)
|
||||
}
|
||||
return wechat.BuildNotifyResponse(true)
|
||||
|
||||
case wechat.EventIOSRefundQueryNotify:
|
||||
var query wechat.XPayIOSRefundQueryNotify
|
||||
if err := json.Unmarshal(raw, &query); err != nil {
|
||||
slog.ErrorContext(ctx, "xpay ios refund query decode failed", "error", err)
|
||||
return wechat.BuildNotifyResponse(false)
|
||||
}
|
||||
return s.handleIOSRefundQuery(ctx, &query)
|
||||
|
||||
default:
|
||||
// 投诉/代币/风控等推送:结构化记录即可,暂不实现业务。
|
||||
slog.WarnContext(ctx, "xpay notify ignored", "event", base.Event, "out_trade_no", base.OutTradeNo)
|
||||
return wechat.BuildNotifyResponse(true)
|
||||
}
|
||||
}
|
||||
|
||||
// verifyXPayOrderPaid 反查微信侧订单真实性:消息推送无签名,发货前必须通过
|
||||
// query_order(带 HMAC 签名的服务端 API)确认订单已真实支付、金额与道具一致,
|
||||
// 防止伪造发货推送零成本获取权益。任一校验不通过返回错误(fail-closed,触发微信重试)。
|
||||
func (s *OrderService) verifyXPayOrderPaid(ctx context.Context, order *mysqlmodel.Order, deliver *wechat.XPayGoodsDeliverNotify) *errcode.Error {
|
||||
if deliver.OpenID == "" {
|
||||
slog.ErrorContext(ctx, "xpay deliver: empty openid", "order_no", order.OrderNo)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
|
||||
info, err := wechat.QueryOrder(ctx, deliver.OpenID, deliver.OutTradeNo, "")
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "xpay deliver: query order failed",
|
||||
"order_no", order.OrderNo, "error", err)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
|
||||
// 微信侧无支付记录/未支付:伪造推送或数据异常,拒绝发放。
|
||||
if !wechat.IsOrderPaidStatus(info.Status) {
|
||||
slog.ErrorContext(ctx, "xpay deliver: order not paid in wechat side",
|
||||
"order_no", order.OrderNo, "query_status", info.Status)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
// 反查金额与道具必须与下单快照一致(资损防线)。
|
||||
if info.PayFee != order.PayAmount {
|
||||
slog.ErrorContext(ctx, "xpay deliver: query amount mismatch",
|
||||
"order_no", order.OrderNo, "query_amount", info.PayFee, "order_amount", order.PayAmount)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
if info.ProductID != order.XPayProductID {
|
||||
slog.ErrorContext(ctx, "xpay deliver: query product mismatch",
|
||||
"order_no", order.OrderNo, "query_product", info.ProductID, "order_product", order.XPayProductID)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// verifyXPayRefund 反查微信侧退款真实性:退款推送无签名,回退权益前必须通过
|
||||
// query_order(带 HMAC 签名的服务端 API)确认订单在微信侧已真实退款、金额一致,
|
||||
// 防止伪造退款推送回收权益。任一校验不通过返回错误(fail-closed,触发微信重试)。
|
||||
func (s *OrderService) verifyXPayRefund(ctx context.Context, order *mysqlmodel.Order, refund *wechat.XPayRefundNotify) *errcode.Error {
|
||||
if refund.OpenID == "" {
|
||||
slog.ErrorContext(ctx, "xpay refund: empty openid", "order_no", order.OrderNo)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
|
||||
info, err := wechat.QueryOrder(ctx, refund.OpenID, refund.OutTradeNo, "")
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "xpay refund: query order failed",
|
||||
"order_no", order.OrderNo, "error", err)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
|
||||
// 微信侧无退款记录/未退款:伪造推送或数据异常,拒绝回退权益。
|
||||
if !wechat.IsOrderRefundedStatus(info.RefundStatus) {
|
||||
slog.ErrorContext(ctx, "xpay refund: order not refunded in wechat side",
|
||||
"order_no", order.OrderNo, "refund_status", info.RefundStatus)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
// 反查退款金额必须与推送一致(资损防线)。
|
||||
if info.RefundFee != refund.RefundFee {
|
||||
slog.ErrorContext(ctx, "xpay refund: refund amount mismatch",
|
||||
"order_no", order.OrderNo, "query_refund_fee", info.RefundFee, "notify_refund_fee", refund.RefundFee)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleGoodsDeliver 处理道具发货推送:幂等锁 + 金额/道具校验 + 条件流转 + 发放权益。
|
||||
func (s *OrderService) handleGoodsDeliver(ctx context.Context, deliver *wechat.XPayGoodsDeliverNotify, raw string) *errcode.Error {
|
||||
lockKey := fmtLockKey(redismodel.KeyLockPayCallback, deliver.OutTradeNo)
|
||||
lockVal := genUUID()
|
||||
if ok, _ := redisdao.TryLock(ctx, lockKey, lockVal, 30*time.Second); !ok {
|
||||
return nil // 并发回调,交由持锁者处理。
|
||||
}
|
||||
defer func() { _ = redisdao.Unlock(ctx, lockKey, lockVal) }()
|
||||
|
||||
order, gerr := s.orderDao.OrderGetByOrderNo(ctx, deliver.OutTradeNo)
|
||||
if gerr != nil {
|
||||
if isNotFound(gerr) {
|
||||
slog.ErrorContext(ctx, "xpay deliver: order not found", "out_trade_no", deliver.OutTradeNo)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
return errcode.DatabaseError
|
||||
}
|
||||
|
||||
// 仅虚拟支付订单走此链路,防止与普通支付回调串单。
|
||||
if order.PayChannel != PayChannelVirtual {
|
||||
slog.ErrorContext(ctx, "xpay deliver: order not virtual pay", "order_no", order.OrderNo, "pay_channel", order.PayChannel)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
// 防篡改:道具 ID 与实付金额必须与下单快照一致。
|
||||
if deliver.GoodsInfo.ProductID != order.XPayProductID {
|
||||
slog.ErrorContext(ctx, "xpay deliver: product mismatch",
|
||||
"order_no", order.OrderNo, "notify_product", deliver.GoodsInfo.ProductID, "order_product", order.XPayProductID)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
if deliver.GoodsInfo.ActualPrice != order.PayAmount {
|
||||
slog.ErrorContext(ctx, "xpay deliver: amount mismatch",
|
||||
"order_no", order.OrderNo, "notify_amount", deliver.GoodsInfo.ActualPrice, "order_amount", order.PayAmount)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
// 防环境串单:沙箱推送不得发放现网订单。
|
||||
if int8(deliver.Env) != order.XPayEnv {
|
||||
slog.ErrorContext(ctx, "xpay deliver: env mismatch",
|
||||
"order_no", order.OrderNo, "notify_env", deliver.Env, "order_env", order.XPayEnv)
|
||||
return errcode.OrderRealityCheckFailed
|
||||
}
|
||||
|
||||
// 订单真实性反查:消息推送无签名,必须反查微信侧订单确认真实支付,
|
||||
// 防止伪造发货推送零成本获取权益;未通过返回错误 -> 应答 ErrCode:1,微信重试。
|
||||
if verr := s.verifyXPayOrderPaid(ctx, order, deliver); verr != nil {
|
||||
return verr
|
||||
}
|
||||
|
||||
// 条件流转:待支付 -> 已支付,防重复回调。
|
||||
updated, uerr := s.orderDao.OrderUpdateStatusByOrderNo(ctx, deliver.OutTradeNo, OrderStatusPending, OrderStatusPaid)
|
||||
if uerr != nil {
|
||||
return errcode.DatabaseError
|
||||
}
|
||||
if updated {
|
||||
s.finalizeVirtualPaidOrder(ctx, order, deliver, raw)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 流转失败:处理「订单已过期但用户实际已付款」的竞态(与普通支付 PayNotify 一致)。
|
||||
current, gerr := s.orderDao.OrderGetByOrderNo(ctx, deliver.OutTradeNo)
|
||||
if gerr != nil {
|
||||
if isNotFound(gerr) {
|
||||
return nil
|
||||
}
|
||||
return errcode.DatabaseError
|
||||
}
|
||||
switch current.OrderStatus {
|
||||
case OrderStatusPaid:
|
||||
// 已被并发回调处理,兜底补发(幂等)。
|
||||
_ = s.orderDao.OrderUpdateByOrderNo(ctx, current.OrderNo, map[string]any{
|
||||
"pay_time": resolvePaidTime(deliver.WeChatPayInfo.PaidTime),
|
||||
"transaction_id": deliver.WeChatPayInfo.TransactionID,
|
||||
"callback_raw": raw,
|
||||
})
|
||||
s.grantOrderBenefits(ctx, current)
|
||||
case OrderStatusExpired:
|
||||
// 订单被系统过期但用户已付款:过期 -> 已支付并补发货。
|
||||
if ok, uerr := s.orderDao.OrderUpdateStatusByOrderNo(ctx, deliver.OutTradeNo, OrderStatusExpired, OrderStatusPaid); uerr != nil {
|
||||
return errcode.DatabaseError
|
||||
} else if ok {
|
||||
s.finalizeVirtualPaidOrder(ctx, current, deliver, raw)
|
||||
}
|
||||
case OrderStatusCancelled:
|
||||
// 防御分支:历史上已取消的虚拟支付订单用户仍完成了支付,补发货避免「钱已扣、权益不到账」。
|
||||
// 当前虚拟支付订单已禁止取消,此分支兜底存量数据与并发竞态。
|
||||
if ok, uerr := s.orderDao.OrderUpdateStatusByOrderNo(ctx, deliver.OutTradeNo, OrderStatusCancelled, OrderStatusPaid); uerr != nil {
|
||||
return errcode.DatabaseError
|
||||
} else if ok {
|
||||
s.finalizeVirtualPaidOrder(ctx, current, deliver, raw)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleRefundNotify 处理退款推送:复用退款成功回退权益链路(settleRefundSuccess)。
|
||||
func (s *OrderService) handleRefundNotify(ctx context.Context, refund *wechat.XPayRefundNotify) *errcode.Error {
|
||||
lockKey := fmtLockKey(redismodel.KeyLockRefundCallback, refund.RefundOrderID)
|
||||
lockVal := genUUID()
|
||||
if ok, _ := redisdao.TryLock(ctx, lockKey, lockVal, 30*time.Second); !ok {
|
||||
return nil
|
||||
}
|
||||
defer func() { _ = redisdao.Unlock(ctx, lockKey, lockVal) }()
|
||||
|
||||
// 白名单判断:仅「退款成功」才回退权益;空串/未知/中间状态仅记录,防止误回退
|
||||
// (退款推送按官方文档在退款完成时触发,状态枚举联调时以官方为准)。
|
||||
if refund.RefundStatus != wechat.XPayRefundStatusSuccess {
|
||||
slog.WarnContext(ctx, "xpay refund notify not success, skip revoke",
|
||||
"order_no", refund.OutTradeNo, "refund_status", refund.RefundStatus)
|
||||
return nil
|
||||
}
|
||||
|
||||
order, gerr := s.orderDao.OrderGetByOrderNo(ctx, refund.OutTradeNo)
|
||||
if gerr != nil {
|
||||
if isNotFound(gerr) {
|
||||
slog.ErrorContext(ctx, "xpay refund: order not found", "out_trade_no", refund.OutTradeNo)
|
||||
return nil
|
||||
}
|
||||
return errcode.DatabaseError
|
||||
}
|
||||
// 已终态则幂等返回。
|
||||
if order.OrderStatus == OrderStatusRefunded {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 订单真实性反查:退款推送无签名,回退权益前必须反查微信侧确认真实退款,
|
||||
// 防止伪造退款推送回收权益;未通过返回错误 -> 应答 ErrCode:1,微信重试。
|
||||
if verr := s.verifyXPayRefund(ctx, order, refund); verr != nil {
|
||||
return verr
|
||||
}
|
||||
|
||||
// settleRefundSuccess 内部含条件流转(Paid -> Refunded),重复推送不会重复回退。
|
||||
s.settleRefundSuccess(ctx, order, refund.RefundFee)
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleIOSRefundQuery 处理 iOS 退款问询(3 秒内应答,仅本地查询)。
|
||||
// 按权益使用情况细化:权益已消耗则拒绝退款(result_code=1 + evidence),未消耗则建议退款;
|
||||
// 建议退款后权益由后续退款推送 settleRefundSuccess 回收(回收链路保证「已消耗部分不回退」)。
|
||||
func (s *OrderService) handleIOSRefundQuery(ctx context.Context, query *wechat.XPayIOSRefundQueryNotify) []byte {
|
||||
order, err := s.orderDao.OrderGetByOrderNo(ctx, query.OutTradeNo)
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "xpay ios refund query: order not found", "out_trade_no", query.OutTradeNo, "error", err)
|
||||
return wechat.BuildIOSRefundQueryResponse(1, "order not found")
|
||||
}
|
||||
if order.OrderStatus == OrderStatusRefunded {
|
||||
return wechat.BuildIOSRefundQueryResponse(0, "already refunded")
|
||||
}
|
||||
// 权益已消耗则拒绝退款,防止「已使用权益后白嫖退款」。
|
||||
if s.iosRefundBenefitsConsumed(ctx, order) {
|
||||
return wechat.BuildIOSRefundQueryResponse(1, "权益已使用,不支持退款")
|
||||
}
|
||||
return wechat.BuildIOSRefundQueryResponse(0, order.OrderNo)
|
||||
}
|
||||
|
||||
// iosRefundBenefitsConsumed 判断订单发放的权益是否已被消耗(用于 iOS 退款问询拒绝策略)。
|
||||
// 额度类:Cos 凭证已用 >0 视为已消耗;会员类:会员已生效(在有效期内)视为已使用。
|
||||
func (s *OrderService) iosRefundBenefitsConsumed(ctx context.Context, order *mysqlmodel.Order) bool {
|
||||
// 额度类:该订单发放的 Cos 凭证已消耗则视为已使用。
|
||||
if order.CosQuota > 0 {
|
||||
grants, err := mysqldao.NewQuotaGrantDao().QuotaGrantListByUserIDAndType(ctx, order.UserID, QuotaTypeCos)
|
||||
if err == nil {
|
||||
for _, g := range grants {
|
||||
if g.RefID == order.OrderNo && g.Used > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 会员类:会员已生效(vip_expire 在未来且非非会员),说明用户已开始享受会员权益。
|
||||
if order.MemberDays > 0 {
|
||||
if user, err := s.userDao.UserGetByID(ctx, order.UserID); err == nil {
|
||||
if user.VIPExpire > nowUnix() && user.VIPType != VIPTypeNone {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// finalizeVirtualPaidOrder 虚拟支付发货:记录支付信息、发放权益并发送通知。
|
||||
func (s *OrderService) finalizeVirtualPaidOrder(ctx context.Context, order *mysqlmodel.Order, deliver *wechat.XPayGoodsDeliverNotify, raw string) {
|
||||
_ = s.orderDao.OrderUpdateByOrderNo(ctx, order.OrderNo, map[string]any{
|
||||
"pay_time": resolvePaidTime(deliver.WeChatPayInfo.PaidTime),
|
||||
"transaction_id": deliver.WeChatPayInfo.TransactionID,
|
||||
"callback_raw": raw,
|
||||
})
|
||||
|
||||
s.grantOrderBenefits(ctx, order)
|
||||
|
||||
sendNotification(ctx, order.UserID, 0, NotificationTypeOrder, "订单支付成功", "你购买的「"+order.GoodsName+"」已到账")
|
||||
}
|
||||
|
||||
// resolvePaidTime 兜底支付时间:推送字段缺失/非法(<=0)时用当前时间,避免 pay_time 写入 0。
|
||||
func resolvePaidTime(paidTime int64) int64 {
|
||||
if paidTime <= 0 {
|
||||
return nowUnix()
|
||||
}
|
||||
return paidTime
|
||||
}
|
||||
Reference in New Issue
Block a user