diff --git a/dbproxy/svc/l_lotteryuser.go b/dbproxy/svc/l_lotteryuser.go new file mode 100644 index 0000000..a948fae --- /dev/null +++ b/dbproxy/svc/l_lotteryuser.go @@ -0,0 +1,47 @@ +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 +} diff --git a/dbproxy/svc/u_lottery.go b/dbproxy/svc/u_lottery.go index baac3d0..c977e15 100644 --- a/dbproxy/svc/u_lottery.go +++ b/dbproxy/svc/u_lottery.go @@ -2,6 +2,7 @@ package svc import ( "errors" + "mongo.games.com/goserver/core/logger" "net/rpc" "github.com/globalsign/mgo" @@ -59,6 +60,16 @@ func UpsertLottery(plt string, item []*model.Lottery) (err error) { if err != nil { return } + err = UpsertLotteryUserLog(&LotteryUserLog{ + Platform: plt, + CId: v.CId, + SnId: v.SnId, + StartTs: v.StartTs, + CostCard: v.CostCard, + }) + if err != nil { + logger.Logger.Warnf("UpsertLotteryUserLog error: %v", err) + } } return }