package gameinvite import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) type modelComp struct { modules.MCompModel module *GameInvite } func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompModel.Init(service, module, comp, options) this.TableName = comm.TableGameInvite this.module = module.(*GameInvite) this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } // 切磋请求处理 func (this *modelComp) queryQiecuo(uid string) (result *pb.GameInviteQiecuoRecord, err error) { result = &pb.GameInviteQiecuoRecord{} if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) } if err == mgo.MongodbNil { result = &pb.GameInviteQiecuoRecord{ Id: primitive.NewObjectID().Hex(), Uid: uid, Invite: make(map[int32]*pb.GameInviteData), } if err = this.Add(uid, result); err != nil { this.module.Errorln(err) return } } err = nil return } func (this *modelComp) endQiecuo(gtype int32, uid string) (result *pb.GameInviteQiecuoRecord, err error) { result = &pb.GameInviteQiecuoRecord{} if err = this.Get(uid, result); err != nil { this.module.Errorln(err) return } this.Change(uid, map[string]interface{}{ "status": 0, "battid": "", "invite": make(map[int32]*pb.GameInviteData), }) if _, ok := result.Invite[gtype]; ok { for _, v := range result.Invite[gtype].Member { if v != uid { this.Change(v, map[string]interface{}{ "status": 0, "battid": "", "invite": make(map[int32]*pb.GameInviteData), }) } } } return }