fix
This commit is contained in:
@@ -87,6 +87,18 @@ func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *type
|
|||||||
} else {
|
} else {
|
||||||
// 用户已存在
|
// 用户已存在
|
||||||
if claims != nil && claims.UserType == model.UserTypeTemp {
|
if claims != nil && claims.UserType == model.UserTypeTemp {
|
||||||
|
// 临时用户,检查手机号是否已绑定其他微信号
|
||||||
|
userTemp, err := l.svcCtx.UserTempModel.FindOne(l.ctx, claims.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询临时用户失败, %v", err)
|
||||||
|
}
|
||||||
|
userAuth, err := l.svcCtx.UserAuthModel.FindOneByUserIdAuthType(l.ctx, user.Id, userTemp.AuthType)
|
||||||
|
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询用户认证失败, %v", err)
|
||||||
|
}
|
||||||
|
if userAuth != nil && userAuth.AuthKey != userTemp.AuthKey {
|
||||||
|
return errors.Wrapf(xerr.NewErrMsg("该手机号已绑定其他微信号"), "")
|
||||||
|
}
|
||||||
// 临时用户,转为正式用户
|
// 临时用户,转为正式用户
|
||||||
err = l.svcCtx.UserService.TempUserBindUser(l.ctx, session, user.Id)
|
err = l.svcCtx.UserService.TempUserBindUser(l.ctx, session, user.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
"ycc-server/app/main/model"
|
"ycc-server/app/main/model"
|
||||||
|
"ycc-server/common/ctxdata"
|
||||||
"ycc-server/common/xerr"
|
"ycc-server/common/xerr"
|
||||||
"ycc-server/pkg/lzkit/crypto"
|
"ycc-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
@@ -107,6 +108,29 @@ func (l *RegisterByInviteCodeLogic) RegisterByInviteCode(req *types.RegisterByIn
|
|||||||
if existingAgent != nil {
|
if existingAgent != nil {
|
||||||
return errors.Wrapf(xerr.NewErrMsg("您已经是代理"), "")
|
return errors.Wrapf(xerr.NewErrMsg("您已经是代理"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果是临时用户(微信环境下),检查手机号是否已绑定其他微信号,并绑定临时用户到正式用户
|
||||||
|
// 注意:非微信环境下 claims 为 nil,此逻辑不会执行,直接使用已存在的 user.Id
|
||||||
|
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
|
||||||
|
if err == nil && claims != nil && claims.UserType == model.UserTypeTemp {
|
||||||
|
userTemp, err := l.svcCtx.UserTempModel.FindOne(l.ctx, claims.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询临时用户失败, %v", err)
|
||||||
|
}
|
||||||
|
userAuth, err := l.svcCtx.UserAuthModel.FindOneByUserIdAuthType(l.ctx, user.Id, userTemp.AuthType)
|
||||||
|
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询用户认证失败, %v", err)
|
||||||
|
}
|
||||||
|
if userAuth != nil && userAuth.AuthKey != userTemp.AuthKey {
|
||||||
|
return errors.Wrapf(xerr.NewErrMsg("该手机号已绑定其他微信号"), "")
|
||||||
|
}
|
||||||
|
// 绑定临时用户到正式用户
|
||||||
|
err = l.svcCtx.UserService.TempUserBindUser(l.ctx, session, user.Id)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "绑定用户失败: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
userID = user.Id
|
userID = user.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,9 +143,9 @@ func (l *RegisterByInviteCodeLogic) RegisterByInviteCode(req *types.RegisterByIn
|
|||||||
|
|
||||||
// 4.3 创建代理记录
|
// 4.3 创建代理记录
|
||||||
newAgent := &model.Agent{
|
newAgent := &model.Agent{
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
Level: targetLevel,
|
Level: targetLevel,
|
||||||
Mobile: encryptedMobile,
|
Mobile: encryptedMobile,
|
||||||
}
|
}
|
||||||
if req.Region != "" {
|
if req.Region != "" {
|
||||||
newAgent.Region = sql.NullString{String: req.Region, Valid: true}
|
newAgent.Region = sql.NullString{String: req.Region, Valid: true}
|
||||||
@@ -163,7 +187,7 @@ func (l *RegisterByInviteCodeLogic) RegisterByInviteCode(req *types.RegisterByIn
|
|||||||
// 建立关系
|
// 建立关系
|
||||||
relation := &model.AgentRelation{
|
relation := &model.AgentRelation{
|
||||||
ParentId: parentAgent.Id,
|
ParentId: parentAgent.Id,
|
||||||
ChildId: agentID,
|
ChildId: agentID,
|
||||||
RelationType: 1, // 直接关系
|
RelationType: 1, // 直接关系
|
||||||
}
|
}
|
||||||
if _, err := l.svcCtx.AgentRelationModel.Insert(transCtx, session, relation); err != nil {
|
if _, err := l.svcCtx.AgentRelationModel.Insert(transCtx, session, relation); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user