fix
This commit is contained in:
@@ -53,7 +53,6 @@ func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *type
|
|||||||
if req.Referrer == "" {
|
if req.Referrer == "" {
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("请填写邀请信息"), "")
|
return nil, errors.Wrapf(xerr.NewErrMsg("请填写邀请信息"), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 校验验证码(开发环境下跳过验证码校验)
|
// 2. 校验验证码(开发环境下跳过验证码校验)
|
||||||
if os.Getenv("ENV") != "development" {
|
if os.Getenv("ENV") != "development" {
|
||||||
redisKey := fmt.Sprintf("%s:%s", "agentApply", encryptedMobile)
|
redisKey := fmt.Sprintf("%s:%s", "agentApply", encryptedMobile)
|
||||||
|
|||||||
@@ -82,41 +82,36 @@ func (s *UserService) GeneralUserToken(ctx context.Context, userID string) (stri
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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 isAgent int64
|
||||||
var agentID string
|
var agentID string
|
||||||
var authType string
|
var authType string
|
||||||
var authKey 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)才可能是代理
|
// 根据mobile判断用户类型
|
||||||
if userType == model.UserTypeNormal {
|
var userType int64
|
||||||
agent, err := s.agentModel.FindOneByUserId(ctx, userID)
|
if user.Mobile.Valid && user.Mobile.String != "" {
|
||||||
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
userType = model.UserTypeNormal
|
||||||
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
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 临时用户获取其他平台的auth信息
|
userType = model.UserTypeTemp
|
||||||
platAuthType := s.getAuthTypeByPlatform(platform)
|
}
|
||||||
ua, err := s.userAuthModel.FindOneByUserIdAuthType(ctx, userID, platAuthType)
|
agent, err := s.agentModel.FindOneByUserId(ctx, userID)
|
||||||
if err == nil && ua != nil {
|
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||||
authType = ua.AuthType
|
return "", errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新token, 获取用户代理信息失败: %v", err)
|
||||||
authKey = ua.AuthKey
|
}
|
||||||
}
|
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{
|
token, generaErr := jwtx.GenerateJwtToken(jwtx.JwtClaims{
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
|
|||||||
Reference in New Issue
Block a user