game_sync/dbproxy/svc/l_lotteryuser.go

48 lines
1.2 KiB
Go

package svc
import (
"errors"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
"mongo.games.com/game/dbproxy/mongo"
)
var (
LotteryUserLogDBErr = errors.New("log_lotteryuser db open failed.")
)
type LotteryUserLog struct {
Platform string `bson:"-"`
CId int64
SnId int32
StartTs int64
CostCard int64
}
func LotteryUserLogsCollection(plt string) *mongo.Collection {
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, "log")
if s != nil {
c, first := s.DB().C("log_lotteryuser")
if first {
c.EnsureIndex(mgo.Index{Key: []string{"cid"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"startts"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"cid", "startts", "snid"}, Background: true, Sparse: true})
}
return c
}
return nil
}
func UpsertLotteryUserLog(log *LotteryUserLog) error {
c := LotteryUserLogsCollection(log.Platform)
if c == nil {
return LotteryUserLogDBErr
}
_, err := c.Upsert(bson.M{"cid": log.CId, "snid": log.SnId, "startts": log.StartTs}, log)
if err != nil {
return err
}
return nil
}