85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
package svc
|
|
|
|
import (
|
|
"errors"
|
|
"net/rpc"
|
|
|
|
"github.com/globalsign/mgo"
|
|
"github.com/globalsign/mgo/bson"
|
|
"mongo.games.com/goserver/core/logger"
|
|
|
|
"mongo.games.com/game/dbproxy/mongo"
|
|
"mongo.games.com/game/model"
|
|
)
|
|
|
|
var (
|
|
MatchAwardDBErr = errors.New("log_matchawardlog db open failed")
|
|
)
|
|
|
|
type MatchAwardLog struct {
|
|
AwardNum map[string]map[int32]int32 // 奖励数量
|
|
Platform string
|
|
}
|
|
|
|
func MatchAwardCollection(plt string) *mongo.Collection {
|
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, model.MatchAwardLogDBName)
|
|
if s != nil {
|
|
c, _ := s.DB().C(model.MatchAwardLogCollName)
|
|
return c
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type MatchAwardSvc struct {
|
|
}
|
|
|
|
func (svc *MatchAwardSvc) UpsertMatchAward(req *model.MatchAward, ret *bool) (err error) {
|
|
c := MatchAwardCollection(req.Platform)
|
|
if c == nil {
|
|
return MatchAwardDBErr
|
|
}
|
|
|
|
_, err = c.Upsert(nil, req)
|
|
if err != nil {
|
|
logger.Logger.Errorf("UpsertMatchAward err:%v", err)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (svc *MatchAwardSvc) GetMatchAward(plt string, ret *model.MatchAward) (err error) {
|
|
c := MatchAwardCollection(plt)
|
|
if c == nil {
|
|
return MatchAwardDBErr
|
|
}
|
|
|
|
// 旧数据
|
|
old := &MatchAwardLog{}
|
|
err = c.Find(bson.M{"platform": "1"}).One(old)
|
|
if err == nil {
|
|
for k, v := range old.AwardNum {
|
|
d := &model.MatchAward{
|
|
Platform: k,
|
|
Award: make(map[int32]int32),
|
|
}
|
|
for kk, vv := range v {
|
|
d.Award[kk] = vv
|
|
}
|
|
var b bool
|
|
svc.UpsertMatchAward(d, &b)
|
|
}
|
|
c.Remove(bson.M{"platform": "1"})
|
|
}
|
|
// 旧数据
|
|
|
|
err = nil
|
|
err = c.Find(nil).One(ret)
|
|
if err != nil && err != mgo.ErrNotFound {
|
|
logger.Logger.Errorf("GetMatchAward err:%v", err)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func init() {
|
|
rpc.Register(new(MatchAwardSvc))
|
|
}
|