This commit is contained in:
Mrx
2026-03-02 16:34:47 +08:00
parent 7e2dda986f
commit be6d3e5f2c
8 changed files with 47 additions and 23 deletions

View File

@@ -221,13 +221,16 @@ func (l *BindMobileLogic) BindMobile(req *types.BindMobileReq) (resp *types.Bind
return err
}
// 3) 源用户软删除
// 软删源用户(通常为临时用户),防止遗留无效账号;软删可保留历史痕迹,满足审计需求
// 3) 源用户软删除(若存在)
// 源用户可能不存在(孤儿 authuser 已删或从未写入),此时跳过软删即可
currentUser, err := l.svcCtx.UserModel.FindOne(ctx, currentUserID)
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查找当前用户失败: %v", err)
}
if err := l.svcCtx.UserModel.Delete(ctx, session, currentUser.Id); err != nil {
if errors.Is(err, model.ErrNotFound) {
l.Infof("[BindMobile] 源用户在 user 表中不存在,跳过软删 | sourceUserId: %s", currentUserID)
} else {
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查找当前用户失败: %v", err)
}
} else if err := l.svcCtx.UserModel.Delete(ctx, session, currentUser.Id); err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "删除当前用户失败: %v", err)
}
}