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