From a87326a085fdbf625c7aaa15c910f4d15fe40e82 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Wed, 10 Dec 2025 13:56:45 +0800 Subject: [PATCH] fix --- .../logic/agent/applyforagentlogic.go | 1 - app/main/api/internal/service/userService.go | 53 +++++++++---------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/main/api/internal/logic/agent/applyforagentlogic.go b/app/main/api/internal/logic/agent/applyforagentlogic.go index a466f21..9b3e586 100644 --- a/app/main/api/internal/logic/agent/applyforagentlogic.go +++ b/app/main/api/internal/logic/agent/applyforagentlogic.go @@ -53,7 +53,6 @@ func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *type if req.Referrer == "" { return nil, errors.Wrapf(xerr.NewErrMsg("请填写邀请信息"), "") } - // 2. 校验验证码(开发环境下跳过验证码校验) if os.Getenv("ENV") != "development" { redisKey := fmt.Sprintf("%s:%s", "agentApply", encryptedMobile) diff --git a/app/main/api/internal/service/userService.go b/app/main/api/internal/service/userService.go index 8003657..f636082 100644 --- a/app/main/api/internal/service/userService.go +++ b/app/main/api/internal/service/userService.go @@ -82,41 +82,36 @@ func (s *UserService) GeneralUserToken(ctx context.Context, userID string) (stri if err != nil { return "", err } - - // 动态计算userType - userType, err := s.GetUserType(ctx, userID) - if err != nil { - return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取用户信息失败: %v", err) - } - var isAgent int64 var agentID string var authType string var authKey string + // 获取用户信息,根据mobile字段动态计算userType + user, err := s.userModel.FindOne(ctx, userID) + if err != nil { + return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "获取用户信息失败: %v", err) + } - // 只有正式用户(有mobile)才可能是代理 - if userType == model.UserTypeNormal { - agent, err := s.agentModel.FindOneByUserId(ctx, userID) - if err != nil && !errors.Is(err, model.ErrNotFound) { - return "", err - } - if agent != nil { - agentID = agent.Id - isAgent = model.AgentStatusYes - } - userAuth, err := s.userAuthModel.FindOneByUserIdAuthType(ctx, userID, model.UserAuthTypeMobile) - if err == nil && userAuth != nil { - authType = userAuth.AuthType - authKey = userAuth.AuthKey - } + // 根据mobile判断用户类型 + var userType int64 + if user.Mobile.Valid && user.Mobile.String != "" { + userType = model.UserTypeNormal } else { - // 临时用户获取其他平台的auth信息 - platAuthType := s.getAuthTypeByPlatform(platform) - ua, err := s.userAuthModel.FindOneByUserIdAuthType(ctx, userID, platAuthType) - if err == nil && ua != nil { - authType = ua.AuthType - authKey = ua.AuthKey - } + userType = model.UserTypeTemp + } + agent, err := s.agentModel.FindOneByUserId(ctx, userID) + if err != nil && !errors.Is(err, model.ErrNotFound) { + return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新token, 获取用户代理信息失败: %v", err) + } + if agent != nil { + agentID = agent.Id + isAgent = model.AgentStatusYes + } + platAuthType := s.getAuthTypeByPlatform(platform) + ua, err := s.userAuthModel.FindOneByUserIdAuthType(ctx, userID, platAuthType) + if err == nil && ua != nil { + authType = ua.AuthType + authKey = ua.AuthKey } token, generaErr := jwtx.GenerateJwtToken(jwtx.JwtClaims{ UserId: userID,