Просмотр исходного кода

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

Tao Chen 1 год назад
Родитель
Сommit
4f616ffff1
2 измененных файлов с 10 добавлено и 2 удалено
  1. 9 1
      service/peer.go
  2. 1 1
      service/user.go

+ 9 - 1
service/peer.go

@@ -34,11 +34,19 @@ func (ps *PeerService) FindByUserIdAndUuid(uuid string,userId uint) *model.Peer
34
 }
34
 }
35
 
35
 
36
 // UuidBindUserId 绑定用户id
36
 // UuidBindUserId 绑定用户id
37
-func (ps *PeerService) UuidBindUserId(uuid string, userId uint) {
37
+func (ps *PeerService) UuidBindUserId(deviceId string, uuid string, userId uint) {
38
 	peer := ps.FindByUuid(uuid)
38
 	peer := ps.FindByUuid(uuid)
39
+	// 如果存在则更新
39
 	if peer.RowId > 0 {
40
 	if peer.RowId > 0 {
40
 		peer.UserId = userId
41
 		peer.UserId = userId
41
 		ps.Update(peer)
42
 		ps.Update(peer)
43
+	} else {
44
+		// 不存在则创建
45
+		global.DB.Create(&model.Peer{
46
+			Id: 		deviceId,
47
+			Uuid:     	uuid,
48
+			UserId:   	userId,
49
+		})
42
 	}
50
 	}
43
 }
51
 }
44
 
52
 

+ 1 - 1
service/user.go

@@ -83,7 +83,7 @@ func (us *UserService) Login(u *model.User, llog *model.LoginLog) *model.UserTok
83
 	llog.UserTokenId = ut.UserId
83
 	llog.UserTokenId = ut.UserId
84
 	global.DB.Create(llog)
84
 	global.DB.Create(llog)
85
 	if llog.Uuid != "" {
85
 	if llog.Uuid != "" {
86
-		AllService.PeerService.UuidBindUserId(llog.Uuid, u.Id)
86
+		AllService.PeerService.UuidBindUserId(llog.DeviceId, llog.Uuid, u.Id)
87
 	}
87
 	}
88
 	return ut
88
 	return ut
89
 }
89
 }