f
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user