package service import ( "fmt" "go.uber.org/zap" "joylink.club/bj-rtsts-server/db/dbquery" "joylink.club/bj-rtsts-server/dto" "time" ) // 分页查询用户列表 func PagingQueryUser(query *dto.PageUserReqDto) (*dto.PageDto, error) { u := dbquery.User uq := u.Where() if query.Name != "" { uq = uq.Where(u.Name.Like(fmt.Sprintf("%%%s%%", query.Name))) } if query.Mobile != "" { uq = uq.Where(u.Mobile.Like(fmt.Sprintf("%%%s%%", query.Mobile))) } records, total, err := uq.Debug().FindByPage(query.Offset(), query.Size) if err != nil { panic(err) } return &dto.PageDto{Total: int(total), PageQueryDto: query.PageQueryDto, Records: records}, err } func Register(user *dto.RegisterUser) { defer func() { err := recover() if err != nil { zap.S().Warn("用户注册失败", err) panic(err) } }() /* if user.Mobile == "" || len([]rune(user.Mobile)) != 13 { panic("asdfasdf") }*/ u := dbquery.User uq := u.Where() uq = uq.Where(u.Mobile.Eq(user.Mobile)) findCounter, _ := uq.Count() if findCounter > 0 { panic("重复的手机号") } user.RegisterTime = time.Now() u.Save(user) } func FindUserInfo(userId int32) *dto.RegisterUser { defer func() { err := recover() if err != nil { zap.S().Warn("用户详情查找错误 userId:"+string(userId), err) panic(err) } }() u := dbquery.User uq := u.Where() uq = uq.Where(u.ID.Eq(userId)) user, _ := uq.First() if user == nil { panic("没有获取到对应的用户信息") } return user }