Files
qnc-server-v3/app/main/api/internal/logic/pay/xpay_notify.go
2026-06-06 17:03:08 +08:00

49 lines
1.5 KiB
Go

package pay
import (
"context"
"qnc-server/app/main/api/internal/svc"
"qnc-server/app/main/model"
"github.com/zeromicro/go-zero/core/logx"
)
// NotifyXpayGoodsAfterReport 报告生成成功后通知微信虚拟支付已发货(合规/结算)
func NotifyXpayGoodsAfterReport(ctx context.Context, svcCtx *svc.ServiceContext, order *model.Order) {
if order == nil || !model.IsXpayOrder(order) {
return
}
if svcCtx.XpayService == nil || !svcCtx.XpayService.Enabled() {
return
}
already, err := svcCtx.XpayService.AlreadyNotified(ctx, order.OrderNo)
if err != nil {
logx.WithContext(ctx).Errorf("[xpay] 检查发货通知状态失败 order_no=%s err=%v", order.OrderNo, err)
return
}
if already {
return
}
openid, err := svcCtx.XpayService.GetWxMiniOpenID(ctx, svcCtx.UserAuthModel, order.UserId)
if err != nil {
logx.WithContext(ctx).Errorf("[xpay] 报告成功后通知发货:获取 openid 失败 order_no=%s err=%v", order.OrderNo, err)
return
}
sessionKey, _ := svcCtx.XpayService.GetSessionKey(ctx, order.UserId)
wxOrderID := ""
if order.PlatformOrderId.Valid {
wxOrderID = order.PlatformOrderId.String
}
if notifyErr := svcCtx.XpayService.NotifyProvideGoods(ctx, openid, order.OrderNo, wxOrderID, sessionKey); notifyErr != nil {
logx.WithContext(ctx).Errorf("[xpay] 报告成功后 notify_provide_goods 失败 order_no=%s err=%v", order.OrderNo, notifyErr)
return
}
_ = svcCtx.XpayService.MarkNotified(ctx, order.OrderNo)
logx.WithContext(ctx).Infof("[xpay] 报告成功后已通知微信发货 order_no=%s", order.OrderNo)
}