142 lines
3.6 KiB
Go
142 lines
3.6 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 (
|
|
FriendApplyDBName = "log"
|
|
FriendApplyCollName = "log_friendapply"
|
|
FriendApplyColError = errors.New("friendapply collection open failed")
|
|
)
|
|
|
|
var (
|
|
FriendApplyListDBName = "log"
|
|
FriendApplyListCollName = "log_friendapplylist"
|
|
FriendApplyListColError = errors.New("friendapplylist collection open failed")
|
|
)
|
|
|
|
func FriendApplyCollection(plt string) *mongo.Collection {
|
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, FriendApplyDBName)
|
|
if s != nil {
|
|
c, first := s.DB().C(FriendApplyCollName)
|
|
if first {
|
|
c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true})
|
|
}
|
|
return c
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func FriendApplyListCollection(plt string) *mongo.Collection {
|
|
s := mongo.MgoSessionMgrSington.GetPltMgoSession(plt, FriendApplyListDBName)
|
|
if s != nil {
|
|
c, first := s.DB().C(FriendApplyListCollName)
|
|
if first {
|
|
c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true})
|
|
}
|
|
return c
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type FriendApplySvc struct {
|
|
}
|
|
|
|
func (svc *FriendApplySvc) UpsertFriendApply(args *model.FriendApplyByKey, ret *model.FriendApplyRet) error {
|
|
cc := FriendApplyCollection(args.Platform)
|
|
if cc == nil {
|
|
return FriendApplyColError
|
|
}
|
|
_, err := cc.Upsert(bson.M{"snid": args.SnId}, args.FA)
|
|
if err != nil && err != mgo.ErrNotFound {
|
|
logger.Logger.Error("UpsertFriendApply is err: ", err)
|
|
return err
|
|
}
|
|
ret.FA = args.FA
|
|
return nil
|
|
}
|
|
|
|
func (svc *FriendApplySvc) QueryFriendApplyByKey(args *model.FriendApplyByKey, ret *model.FriendApplyRet) error {
|
|
fc := FriendApplyCollection(args.Platform)
|
|
if fc == nil {
|
|
return FriendApplyColError
|
|
}
|
|
err := fc.Find(bson.M{"snid": args.SnId}).One(&ret.FA)
|
|
if err != nil && !errors.Is(err, mgo.ErrNotFound) {
|
|
logger.Logger.Error("QueryFriendApplyByKey is err: ", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (svc *FriendApplySvc) DelFriendApply(args *model.FriendApplyByKey, ret *bool) error {
|
|
cc := FriendApplyCollection(args.Platform)
|
|
if cc == nil {
|
|
return FriendApplyColError
|
|
}
|
|
err := cc.Remove(bson.M{"snid": args.SnId})
|
|
if err != nil {
|
|
logger.Logger.Error("DelFriendApply is err: ", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (svc *FriendApplySvc) UpsertApplyList(args *model.ApplyListReq, ret *model.ApplyListRes) error {
|
|
cc := FriendApplyListCollection(args.Platform)
|
|
if cc == nil {
|
|
return FriendApplyListColError
|
|
}
|
|
if args.Data == nil || args.Data.SnId <= 0 {
|
|
return nil
|
|
}
|
|
_, err := cc.Upsert(bson.M{"snid": args.Data.SnId}, args.Data)
|
|
if err != nil && err != mgo.ErrNotFound {
|
|
logger.Logger.Error("UpsertApplyList is err: ", err)
|
|
return err
|
|
}
|
|
ret.Data = args.Data
|
|
return nil
|
|
}
|
|
|
|
func (svc *FriendApplySvc) QueryFriendApplyListBySnid(args *model.FriendApplyByKey, ret *model.ApplyListRes) error {
|
|
fc := FriendApplyListCollection(args.Platform)
|
|
if fc == nil {
|
|
return FriendApplyListColError
|
|
}
|
|
err := fc.Find(bson.M{"snid": args.SnId}).One(&ret.Data)
|
|
if err != nil && !errors.Is(err, mgo.ErrNotFound) {
|
|
logger.Logger.Error("QueryFriendApplyListBySnid is err: ", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (svc *FriendApplySvc) DelFriendApplyList(args *model.FriendApplyByKey, ret *bool) error {
|
|
cc := FriendApplyListCollection(args.Platform)
|
|
if cc == nil {
|
|
return FriendApplyListColError
|
|
}
|
|
err := cc.Remove(bson.M{"snid": args.SnId})
|
|
if err != nil {
|
|
logger.Logger.Error("DelFriendApplyList is err: ", err)
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var _FriendApplySvc = &FriendApplySvc{}
|
|
|
|
func init() {
|
|
rpc.Register(_FriendApplySvc)
|
|
}
|