46 lines
1004 B
Go
46 lines
1004 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/globalsign/mgo/bson"
|
|
"mongo.games.com/game/common"
|
|
)
|
|
|
|
var (
|
|
OnlineLogDBName = "log"
|
|
OnlineLogCollName = "log_online"
|
|
)
|
|
|
|
// OnlineLog 登录登出记录
|
|
type OnlineLog struct {
|
|
LogId bson.ObjectId `bson:"_id"`
|
|
Platform string //平台id
|
|
SnId int32
|
|
OnlineType int32 // 上线类型,登录,重连
|
|
OnlineTs int64 // 在线时间
|
|
OfflineType int32 // 离线类型,断线,登出
|
|
OfflineTs int64 // 离线时间
|
|
}
|
|
|
|
func NewOnlineLog(id bson.ObjectId, snId, logType int32, platform string) *OnlineLog {
|
|
now := time.Now()
|
|
cl := &OnlineLog{}
|
|
if id == "" {
|
|
cl.LogId = bson.NewObjectId()
|
|
} else {
|
|
cl.LogId = id
|
|
}
|
|
cl.Platform = platform
|
|
cl.SnId = snId
|
|
switch logType {
|
|
case common.LoginLogTypeLogin, common.LoginLogTypeRehold:
|
|
cl.OnlineType = logType
|
|
cl.OnlineTs = now.Unix()
|
|
case common.LoginLogTypeDrop, common.LoginLogTypeLogout:
|
|
cl.OfflineType = logType
|
|
cl.OfflineTs = now.Unix()
|
|
}
|
|
return cl
|
|
}
|