68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package svc
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/globalsign/mgo/bson"
|
|
"mongo.games.com/game/dbproxy/mongo"
|
|
"mongo.games.com/game/model"
|
|
"net/rpc"
|
|
)
|
|
|
|
var (
|
|
MatchAwardLogDBErr = errors.New("log_matchawardlog db open failed.")
|
|
)
|
|
|
|
func MatchAwardLogCollection(plt string) *mongo.Collection {
|
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, model.MatchAwardLogDBName)
|
|
if s != nil {
|
|
c, _ := s.DB().C(model.MatchAwardLogCollName)
|
|
return c
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func InsertOrUpdateMatchAwardLog(logs ...*model.MatchAwardLog) (err error) {
|
|
for _, log := range logs {
|
|
clog := MatchAwardLogCollection(log.Platform)
|
|
if clog == nil {
|
|
return
|
|
}
|
|
_, err = clog.Upsert(nil, log)
|
|
if err != nil {
|
|
// 处理错误
|
|
return err
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
type MatchAwardLogSvc struct {
|
|
}
|
|
|
|
func (svc *MatchAwardLogSvc) InsertOrUpdateMatchAwardLog(args []*model.MatchAwardLog, ret *bool) (err error) {
|
|
err = InsertOrUpdateMatchAwardLog(args...)
|
|
if err == nil {
|
|
*ret = true
|
|
}
|
|
return
|
|
}
|
|
func GetMatchAward(plt string, ret *model.MatchAwardLog) (err error) {
|
|
clog := MatchAwardLogCollection(plt)
|
|
if clog == nil {
|
|
return nil
|
|
}
|
|
selecter := bson.M{"platform": plt}
|
|
err = clog.Find(selecter).One(&ret)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return
|
|
}
|
|
func (svc *MatchAwardLogSvc) GetMatchAward(Plt string, ret *model.MatchAwardLog) (err error) {
|
|
err = GetMatchAward(Plt, ret)
|
|
return err
|
|
}
|
|
func init() {
|
|
rpc.Register(new(MatchAwardLogSvc))
|
|
}
|