Merge branch 'main' of http://1.117.67.95:3000/team/qnc-server-v3
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.2
|
||||
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/common/xerr"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GenerateInvitePosterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGenerateInvitePosterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateInvitePosterLogic {
|
||||
return &GenerateInvitePosterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GenerateInvitePosterLogic) GenerateInvitePoster(req *types.GenerateInvitePosterReq) (resp *types.GenerateInvitePosterResp, err error) {
|
||||
if req.InviteLink == "" {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("邀请链接不能为空"), "")
|
||||
}
|
||||
|
||||
// 调用ImageService生成海报
|
||||
imageData, mimeType, err := l.svcCtx.ImageService.ProcessImageWithQRCode("invitation", req.InviteLink)
|
||||
if err != nil {
|
||||
l.Errorf("生成邀请海报失败: %v", err)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成海报失败: %v", err)
|
||||
}
|
||||
|
||||
// 将图片数据转换为base64编码的data URL
|
||||
base64Data := base64.StdEncoding.EncodeToString(imageData)
|
||||
posterUrl := fmt.Sprintf("data:%s;base64,%s", mimeType, base64Data)
|
||||
|
||||
return &types.GenerateInvitePosterResp{
|
||||
PosterUrl: posterUrl,
|
||||
}, nil
|
||||
}
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/globalkey"
|
||||
"qnc-server/common/tool"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -124,7 +124,18 @@ func (l *GetInviteLinkLogic) createInviteShortLink(inviteCodeId string, inviteCo
|
||||
// 先查询是否已存在短链
|
||||
existingShortLink, err := l.svcCtx.AgentShortLinkModel.FindOneByInviteCodeIdTypeDelState(l.ctx, sql.NullString{String: inviteCodeId, Valid: inviteCodeId != ""}, 2, globalkey.DelStateNo)
|
||||
if err == nil && existingShortLink != nil {
|
||||
// 已存在短链,直接返回
|
||||
// 已存在短链,检查 target_path 是否需要更新
|
||||
if existingShortLink.TargetPath != targetPath {
|
||||
// target_path 已变化,更新短链记录
|
||||
oldTargetPath := existingShortLink.TargetPath
|
||||
existingShortLink.TargetPath = targetPath
|
||||
if updateErr := l.svcCtx.AgentShortLinkModel.UpdateWithVersion(l.ctx, nil, existingShortLink); updateErr != nil {
|
||||
l.Errorf("更新短链 target_path 失败: %v", updateErr)
|
||||
// 即使更新失败,也返回旧短链,避免影响用户体验
|
||||
} else {
|
||||
l.Infof("短链 target_path 已更新: shortCode=%s, old=%s, new=%s", existingShortLink.ShortCode, oldTargetPath, targetPath)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s/s/%s", promotionConfig.PromotionDomain, existingShortLink.ShortCode), nil
|
||||
}
|
||||
|
||||
@@ -136,6 +147,18 @@ func (l *GetInviteLinkLogic) createInviteShortLink(inviteCodeId string, inviteCo
|
||||
if inviteCodeId == "" && inviteCode != "" {
|
||||
existingByCode, err2 := l.svcCtx.AgentShortLinkModel.FindOneByInviteCodeTypeDelState(l.ctx, sql.NullString{String: inviteCode, Valid: true}, 2, globalkey.DelStateNo)
|
||||
if err2 == nil && existingByCode != nil {
|
||||
// 已存在短链,检查 target_path 是否需要更新
|
||||
if existingByCode.TargetPath != targetPath {
|
||||
// target_path 已变化,更新短链记录
|
||||
oldTargetPath := existingByCode.TargetPath
|
||||
existingByCode.TargetPath = targetPath
|
||||
if updateErr := l.svcCtx.AgentShortLinkModel.UpdateWithVersion(l.ctx, nil, existingByCode); updateErr != nil {
|
||||
l.Errorf("更新短链 target_path 失败: %v", updateErr)
|
||||
// 即使更新失败,也返回旧短链,避免影响用户体验
|
||||
} else {
|
||||
l.Infof("短链 target_path 已更新: shortCode=%s, old=%s, new=%s", existingByCode.ShortCode, oldTargetPath, targetPath)
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("%s/s/%s", promotionConfig.PromotionDomain, existingByCode.ShortCode), nil
|
||||
}
|
||||
if err2 != nil && !errors.Is(err2, model.ErrNotFound) {
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/globalkey"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/crypto"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@@ -6,15 +6,15 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"qnc-server/app/main/api/internal/svc"
|
||||
"qnc-server/app/main/api/internal/types"
|
||||
"qnc-server/app/main/model"
|
||||
"qnc-server/common/ctxdata"
|
||||
"qnc-server/common/xerr"
|
||||
"qnc-server/pkg/lzkit/lzUtils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
@@ -35,6 +35,9 @@ type PaymentTypeResp struct {
|
||||
orderID string // 订单ID,用于开发环境测试支付模式
|
||||
}
|
||||
|
||||
// enableDevTestPayment 测试支付功能开关,设置为 true 以启用测试支付功能
|
||||
const enableDevTestPayment = false
|
||||
|
||||
func NewPaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PaymentLogic {
|
||||
return &PaymentLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
@@ -50,8 +53,8 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
|
||||
// 检查是否为开发环境的测试支付模式
|
||||
env := os.Getenv("ENV")
|
||||
isDevTestPayment := env == "development" && (req.PayMethod == "test" || req.PayMethod == "test_empty")
|
||||
isEmptyReportMode := env == "development" && req.PayMethod == "test_empty"
|
||||
isDevTestPayment := enableDevTestPayment && env == "development" && (req.PayMethod == "test" || req.PayMethod == "test_empty")
|
||||
isEmptyReportMode := enableDevTestPayment && env == "development" && req.PayMethod == "test_empty"
|
||||
|
||||
l.svcCtx.OrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
switch req.PayType {
|
||||
@@ -95,7 +98,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
// 正常支付流程
|
||||
var createOrderErr error
|
||||
if req.PayMethod == "wechat" {
|
||||
prepayData, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, paymentTypeResp.amount, paymentTypeResp.description, paymentTypeResp.outTradeNo)
|
||||
prepayData, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, paymentTypeResp.amount, paymentTypeResp.description, paymentTypeResp.outTradeNo, req.Code)
|
||||
} else if req.PayMethod == "alipay" {
|
||||
prepayData, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, paymentTypeResp.amount, paymentTypeResp.description, paymentTypeResp.outTradeNo)
|
||||
} else if req.PayMethod == "appleiap" {
|
||||
|
||||
@@ -118,7 +118,37 @@ func (l *WxMiniAuthLogic) GetSessionKey(code string) (*SessionKeyResp, error) {
|
||||
|
||||
// 检查微信返回的错误码
|
||||
if sessionKeyResp.ErrCode != 0 {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR),
|
||||
// 针对不同的微信错误码返回更明确的错误信息
|
||||
var errMsg string
|
||||
switch sessionKeyResp.ErrCode {
|
||||
case 40029:
|
||||
// code 无效(已使用、已过期或格式错误)
|
||||
errMsg = "微信授权码无效或已过期,请重新打开小程序"
|
||||
l.Errorf("微信code无效: errcode=%d, errmsg=%s, code前6位=%s",
|
||||
sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg,
|
||||
func() string {
|
||||
if len(code) > 6 {
|
||||
return code[:6] + "..."
|
||||
}
|
||||
return code
|
||||
}())
|
||||
case 40013:
|
||||
// 无效的 AppID
|
||||
errMsg = "小程序配置错误,请联系管理员"
|
||||
l.Errorf("微信AppID无效: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
case 40125:
|
||||
// 无效的 AppSecret
|
||||
errMsg = "小程序配置错误,请联系管理员"
|
||||
l.Errorf("微信AppSecret无效: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
case 45011:
|
||||
// 频率限制
|
||||
errMsg = "请求过于频繁,请稍后再试"
|
||||
l.Errorf("微信API频率限制: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
default:
|
||||
errMsg = fmt.Sprintf("微信授权失败: %s", sessionKeyResp.ErrMsg)
|
||||
l.Errorf("微信接口返回错误: errcode=%d, errmsg=%s", sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg(errMsg),
|
||||
"微信接口返回错误: errcode=%d, errmsg=%s",
|
||||
sessionKeyResp.ErrCode, sessionKeyResp.ErrMsg)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user