When login, peer doesn't exist, it should create

This commit is contained in:
Tao Chen
2024-11-02 08:19:44 +08:00
parent 6a7ef29089
commit d38117107d
2 changed files with 10 additions and 2 deletions
+9 -1
View File
@@ -34,11 +34,19 @@ func (ps *PeerService) FindByUserIdAndUuid(uuid string,userId uint) *model.Peer
}
// UuidBindUserId 绑定用户id
func (ps *PeerService) UuidBindUserId(uuid string, userId uint) {
func (ps *PeerService) UuidBindUserId(deviceId string, uuid string, userId uint) {
peer := ps.FindByUuid(uuid)
// 如果存在则更新
if peer.RowId > 0 {
peer.UserId = userId
ps.Update(peer)
} else {
// 不存在则创建
global.DB.Create(&model.Peer{
Id: deviceId,
Uuid: uuid,
UserId: userId,
})
}
}