ljw 1 год назад
Родитель
Сommit
991fc86fa6
3 измененных файлов с 5 добавлено и 5 удалено
  1. 1 1
      cmd/apimain.go
  2. 3 4
      http/controller/api/index.go
  3. 1 0
      model/peer.go

+ 1 - 1
cmd/apimain.go

@@ -101,7 +101,7 @@ func main() {
101 101
 }
102 102
 
103 103
 func DatabaseAutoUpdate() {
104
-	version := 240
104
+	version := 241
105 105
 
106 106
 	db := global.DB
107 107
 

+ 3 - 4
http/controller/api/index.go

@@ -54,10 +54,9 @@ func (i *Index) Heartbeat(c *gin.Context) {
54 54
 		c.JSON(http.StatusOK, gin.H{})
55 55
 		return
56 56
 	}
57
-	//如果在一分钟以内则不更新
58
-	if time.Now().Unix()-peer.LastOnlineTime > 60 {
59
-		peer.LastOnlineTime = time.Now().Unix()
60
-		upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: peer.LastOnlineTime}
57
+	//如果在40s以内则不更新
58
+	if time.Now().Unix()-peer.LastOnlineTime > 40 {
59
+		upp := &model.Peer{RowId: peer.RowId, LastOnlineTime: time.Now().Unix(), LastOnlineIp: c.ClientIP()}
61 60
 		service.AllService.PeerService.Update(upp)
62 61
 	}
63 62
 	c.JSON(http.StatusOK, gin.H{})

+ 1 - 0
model/peer.go

@@ -13,6 +13,7 @@ type Peer struct {
13 13
 	UserId         uint   `json:"user_id"  gorm:"default:0;not null;index"`
14 14
 	User           *User  `json:"user,omitempty"`
15 15
 	LastOnlineTime int64  `json:"last_online_time"  gorm:"default:0;not null;"`
16
+	LastOnlineIp   string `json:"last_online_ip"  gorm:"default:'';not null;"`
16 17
 	TimeModel
17 18
 }
18 19