From 49a8c4190809e0be2d430c0dbcfa48b65594549d Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Tue, 5 Nov 2024 15:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=BD=E5=A5=96=E6=88=BF=E5=8D=A1=E6=B6=88?= =?UTF-8?q?=E8=80=97=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/l_lotteryuser.go | 47 ++++++++++++++++++++++++++++++++++++ dbproxy/svc/u_lottery.go | 11 +++++++++ 2 files changed, 58 insertions(+) create mode 100644 dbproxy/svc/l_lotteryuser.go 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 }