f
This commit is contained in:
@@ -53,6 +53,27 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
isDevTestPayment := env == "development" && (req.PayMethod == "test" || req.PayMethod == "test_empty")
|
||||
isEmptyReportMode := env == "development" && req.PayMethod == "test_empty"
|
||||
|
||||
// 微信小程序:若未绑定 openid 但前端传了 code,则用 code 换取 openid 并写入 user_auth,以便 CreateWechatOrder 能拿到 openid 并返回 prepay_data
|
||||
if req.PayMethod == "wechat" && req.Code != "" {
|
||||
platformVal := l.ctx.Value("platform")
|
||||
platform, _ := platformVal.(string)
|
||||
if platform == model.PlatformWxMini {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr == nil {
|
||||
_, findErr := l.svcCtx.UserAuthModel.FindOneByUserIdAuthType(l.ctx, userID, model.UserAuthTypeWxMiniOpenID)
|
||||
if findErr != nil {
|
||||
openid, codeErr := l.svcCtx.VerificationService.GetWechatMiniOpenID(l.ctx, req.Code)
|
||||
if codeErr == nil {
|
||||
ua := &model.UserAuth{Id: uuid.NewString(), UserId: userID, AuthType: model.UserAuthTypeWxMiniOpenID, AuthKey: openid}
|
||||
if _, insertErr := l.svcCtx.UserAuthModel.Insert(l.ctx, nil, ua); insertErr != nil {
|
||||
logx.Infof("支付前绑定 openid 写入失败(可忽略): %v", insertErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
switch req.PayType {
|
||||
case "agent_vip":
|
||||
|
||||
Reference in New Issue
Block a user