fix group peers

This commit is contained in:
ljw
2024-09-24 19:35:20 +08:00
parent 95a1bd6c21
commit 0a81b5b5f8
11 changed files with 133 additions and 109 deletions

View File

@@ -15,24 +15,38 @@ func (ps *PeerService) FindById(id string) *model.Peer {
global.DB.Where("id = ?", id).First(p)
return p
}
func (ps *PeerService) FindByUuid(uuid string) *model.Peer {
p := &model.Peer{}
global.DB.Where("uuid = ?", uuid).First(p)
return p
}
func (ps *PeerService) InfoByRowId(id uint) *model.Peer {
p := &model.Peer{}
global.DB.Where("row_id = ?", id).First(p)
return p
}
//// ListByUserIds 根据用户id取列表
//func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) {
// res = &model.PeerList{}
// res.Page = int64(page)
// res.PageSize = int64(pageSize)
// tx := global.DB.Model(&model.Peer{}).Preload("User")
// tx.Where("user_id in (?)", userIds)
// tx.Count(&res.Total)
// tx.Scopes(Paginate(page, pageSize))
// tx.Find(&res.Peers)
// return
//}
// UuidBindUserId 绑定用户id
func (ps *PeerService) UuidBindUserId(uuid string, userId uint) {
peer := ps.FindByUuid(uuid)
if peer.RowId > 0 {
peer.UserId = userId
ps.Update(peer)
}
}
// ListByUserIds 根据用户id取列表
func (ps *PeerService) ListByUserIds(userIds []uint, page, pageSize uint) (res *model.PeerList) {
res = &model.PeerList{}
res.Page = int64(page)
res.PageSize = int64(pageSize)
tx := global.DB.Model(&model.Peer{})
tx.Where("user_id in (?)", userIds)
tx.Count(&res.Total)
tx.Scopes(Paginate(page, pageSize))
tx.Find(&res.Peers)
return
}
func (ps *PeerService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.PeerList) {
res = &model.PeerList{}

View File

@@ -66,6 +66,9 @@ func (us *UserService) Login(u *model.User, llog *model.LoginLog) *model.UserTok
}
global.DB.Create(ut)
global.DB.Create(llog)
if llog.Uuid != "" {
AllService.PeerService.UuidBindUserId(llog.Uuid, u.Id)
}
return ut
}