抽奖房卡消耗数量
This commit is contained in:
parent
9e85b4a1a7
commit
49a8c41908
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue