feat: minilogin改造

This commit is contained in:
Blizzard
2026-05-24 23:04:09 +08:00
parent 076ed1509b
commit da02247794
36 changed files with 3523 additions and 11653 deletions
@@ -23,18 +23,6 @@ func NewCreateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
}
func (l *CreateUserLogic) CreateUser(in *system.CreateUserReq) (*system.CreateUserResp, error) {
// 如果有 OpenId,先查是否已存在(社交登录场景:已有用户直接返回)
if in.OpenId != "" {
var existing sysModel.SundynixUser
if err := l.svcCtx.DB.Where("open_id = ?", in.OpenId).First(&existing).Error; err == nil {
// 用户已存在,更新 session_key 后直接返回
if in.SessionKey != "" {
l.svcCtx.DB.Model(&existing).Update("session_key", in.SessionKey)
}
return &system.CreateUserResp{User: convertUserToProto(&existing)}, nil
}
}
// 如果有 Account,检查是否重复(后台创建用户场景:禁止重复)
if in.Account != "" {
var count int64
@@ -45,12 +33,11 @@ func (l *CreateUserLogic) CreateUser(in *system.CreateUserReq) (*system.CreateUs
}
u := sysModel.SundynixUser{
Name: in.Name,
Account: in.Account,
Phone: in.Phone,
OpenID: in.OpenId,
SessionKey: in.SessionKey,
ClientID: in.ClientId,
Name: in.Name,
Account: in.Account,
Phone: in.Phone,
NickName: in.NickName,
ClientID: in.ClientId,
}
if in.Password != "" {
u.Password = hash.BcryptHash(in.Password)
@@ -1,36 +0,0 @@
package logic
import (
"context"
"errors"
sysModel "sundynix-micro-go/app/system/model"
"sundynix-micro-go/app/system/rpc/internal/svc"
"sundynix-micro-go/app/system/rpc/system"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gorm.io/gorm"
)
type GetUserByOpenIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserByOpenIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserByOpenIdLogic {
return &GetUserByOpenIdLogic{ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx)}
}
func (l *GetUserByOpenIdLogic) GetUserByOpenId(in *system.GetUserByOpenIdReq) (*system.GetUserByOpenIdResp, error) {
var u sysModel.SundynixUser
if err := l.svcCtx.DB.Where("open_id = ?", in.OpenId).First(&u).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, "用户不存在")
}
return nil, status.Error(codes.Internal, "查询失败")
}
return &system.GetUserByOpenIdResp{User: convertUserToProto(&u)}, nil
}
+11 -15
View File
@@ -8,21 +8,17 @@ import (
// convertUserToProto 将 model 转为 proto UserInfo
func convertUserToProto(u *sysModel.SundynixUser) *system.UserInfo {
info := &system.UserInfo{
Id: u.ID,
TenantId: u.TenantID,
ClientId: u.ClientID,
Name: u.Name,
Account: u.Account,
NickName: u.NickName,
Phone: u.Phone,
SessionKey: u.SessionKey,
UnionId: u.UnionID,
OpenId: u.OpenID,
SaOpenId: u.SaOpenID,
AvatarId: u.AvatarID,
Gender: int32(u.Gender),
CreatedAt: u.CreatedAt.Unix(),
UpdatedAt: u.UpdatedAt.Unix(),
Id: u.ID,
TenantId: u.TenantID,
ClientId: u.ClientID,
Name: u.Name,
Account: u.Account,
NickName: u.NickName,
Phone: u.Phone,
AvatarId: u.AvatarID,
Gender: int32(u.Gender),
CreatedAt: u.CreatedAt.Unix(),
UpdatedAt: u.UpdatedAt.Unix(),
}
if u.LastLoginAt != nil {
info.LastLoginAt = u.LastLoginAt.Unix()
@@ -29,11 +29,6 @@ func (s *SystemServiceServer) GetUserById(ctx context.Context, in *system.GetUse
return l.GetUserById(in)
}
func (s *SystemServiceServer) GetUserByOpenId(ctx context.Context, in *system.GetUserByOpenIdReq) (*system.GetUserByOpenIdResp, error) {
l := logic.NewGetUserByOpenIdLogic(ctx, s.svcCtx)
return l.GetUserByOpenId(in)
}
func (s *SystemServiceServer) LoginByAccount(ctx context.Context, in *system.LoginByAccountReq) (*system.LoginByAccountResp, error) {
l := logic.NewLoginByAccountLogic(ctx, s.svcCtx)
return l.LoginByAccount(in)