This commit is contained in:
2025-12-10 13:10:39 +08:00
parent c23ab8338b
commit 0f676d3c76
31 changed files with 375 additions and 5916 deletions

View File

@@ -105,10 +105,16 @@ func (l *RegisterByInviteCodeLogic) RegisterByInviteCode(req *types.RegisterByIn
return errors.Wrapf(xerr.NewErrMsg("您已经是代理"), "")
}
// 如果是临时用户(微信环境下),检查手机号是否已绑定其他微信号,并绑定临时用户到正式用户
// 注意:非微信环境下 claims 为 nil此逻辑不会执行直接使用已存在的 user.Id
// 检查用户是否有mobile绑定没有mobile则不能成为代理
// 如果是临时用户(微信环境下),需要先绑定手机号
claims, err := ctxdata.GetClaimsFromCtx(l.ctx)
if err == nil && claims != nil && claims.UserType == model.UserTypeTemp {
if err == nil && claims != nil {
// 获取用户的mobile信息
if !user.Mobile.Valid || user.Mobile.String == "" {
// 临时用户无mobile不能直接成为代理需要先绑定mobile
return errors.Wrapf(xerr.NewErrMsg("请先绑定手机号后再申请成为代理"), "")
}
// 检查是否已绑定手机号认证(用于确保后续可通过手机号登录)
userAuth, err := l.svcCtx.UserAuthModel.FindOneByUserIdAuthType(l.ctx, user.Id, claims.AuthType)
if err != nil && !errors.Is(err, model.ErrNotFound) {
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询用户认证失败, %v", err)
@@ -116,11 +122,6 @@ func (l *RegisterByInviteCodeLogic) RegisterByInviteCode(req *types.RegisterByIn
if userAuth != nil && userAuth.AuthKey != claims.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
@@ -263,7 +264,7 @@ func (l *RegisterByInviteCodeLogic) RegisterByInviteCode(req *types.RegisterByIn
}
// 5. 生成并返回token
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID, model.UserTypeNormal)
token, err := l.svcCtx.UserService.GeneralUserToken(l.ctx, userID)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成token失败: %v", err)
}