package parkour import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" "go_dreamfactory/sys/db" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) ///竞速数据模块 坐骑 type ModelMountsComp struct { modules.MCompModel module *Parkour } //组件初始化接口 只是用redis 层 func (this *ModelMountsComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { this.TableName = comm.TableParkourMounts this.MCompModel.Init(service, module, comp, opt) this.module = module.(*Parkour) //创建uid索引 this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, }) return } ///查询用户背包数据 func (this *ModelMountsComp) QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) { var ( model *db.DBModel ) itmes = make([]*pb.DB_UserItemData, 0) if this.module.IsCross() { if model, err = this.module.GetDBModelByUid(uId, this.TableName); err != nil { this.module.Errorln(err) } else { if err = model.GetList(uId, &itmes); err != nil { this.module.Errorf("err:%v", err) } } } else { if err = this.GetList(uId, &itmes); err != nil { this.module.Errorf("err:%v", err) } } return }