package library import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) type modelLibrary struct { modules.MCompModel module *Library } func (this *modelLibrary) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.TableName = string(comm.TableLibrary) err = this.MCompModel.Init(service, module, comp, options) this.module = module.(*Library) // uid 创建索引 this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } func (this *modelLibrary) modifyLibraryDataByObjId(uid string, obj string, data map[string]interface{}) error { return this.ChangeList(uid, obj, data) } // 获取列表信息 func (this *modelLibrary) getLibraryList(uid string) []*pb.DBLibrary { libs := make([]*pb.DBLibrary, 0) err := this.GetList(uid, &libs) if err != nil { return nil } return libs } //创建一条信息 func (this *modelLibrary) createLibrary(uid string, fetter *pb.DBLibrary) (err error) { if err = this.AddList(uid, fetter.Id, fetter); err != nil { this.module.Errorf("%v", err) return } return } // 通过objid 找对应的数据 func (this *modelLibrary) getOneLibrary(uid, oid string) *pb.DBLibrary { fetter := &pb.DBLibrary{} err := this.GetListObj(uid, oid, fetter) if err != nil { return nil } return fetter } func (this *modelLibrary) checkReddot19105(uid string) bool { listLabriary := this.getLibraryList(uid) for _, v := range listLabriary { var ( minlv int32 // 获取最小等级 ) for _, v1 := range v.Herofetter { if fet := this.module.modelFetter.getOneHeroFetter(uid, v1); fet != nil { if minlv == 0 || minlv > fet.Favorlv { minlv = fet.Favorlv } } } for i := 1; i <= int(minlv); i++ { if _, ok := v.Prize[int32(i)]; !ok { // 找到了没有领奖的数据 return true } } } return false }