2023-07-14 10:16:58 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-07-28 11:15:44 +08:00
|
|
|
"go.uber.org/zap"
|
2023-07-14 10:16:58 +08:00
|
|
|
"joylink.club/bj-rtsts-server/db/dbquery"
|
|
|
|
"joylink.club/bj-rtsts-server/dto"
|
2023-07-28 11:15:44 +08:00
|
|
|
"time"
|
2023-07-14 10:16:58 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// 分页查询用户列表
|
|
|
|
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
|
|
|
|
}
|
2023-07-28 11:15:44 +08:00
|
|
|
|
2023-07-28 15:49:44 +08:00
|
|
|
func Register(user *dto.RegisterUser) {
|
2023-07-28 11:15:44 +08:00
|
|
|
defer func() {
|
|
|
|
err := recover()
|
|
|
|
if err != nil {
|
|
|
|
zap.S().Warn("用户注册失败", err)
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}()
|
2023-07-28 15:49:44 +08:00
|
|
|
/* if user.Mobile == "" || len([]rune(user.Mobile)) != 13 {
|
|
|
|
panic("asdfasdf")
|
|
|
|
}*/
|
2023-07-28 11:15:44 +08:00
|
|
|
u := dbquery.User
|
|
|
|
uq := u.Where()
|
|
|
|
uq = uq.Where(u.Mobile.Eq(user.Mobile))
|
2023-07-28 15:49:44 +08:00
|
|
|
findCounter, _ := uq.Count()
|
|
|
|
if findCounter > 0 {
|
2023-07-28 11:15:44 +08:00
|
|
|
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
|
|
|
|
}
|