查询接口调整

This commit is contained in:
meixiongfeng 2022-10-19 19:43:39 +08:00
parent 232a0fc1e5
commit c247137d7e

View File

@ -344,19 +344,33 @@ func (this *Hero) CreateMonster(heroCid string, star, lv int32) (hero *pb.DBHero
// 只通过唯一id 查询英雄信息
func (this *Hero) QueryCrossHeroinfo(oid string) (hero *pb.DBHero, err error) {
for _, tag := range db.GetServerTags() {
conn, err1 := db.ServerDBConn(tag) // 遍历连接对象
if err1 != nil {
continue
if this.modelHero.moduleHero.IsCross() {
for _, tag := range db.GetServerTags() {
conn, err1 := db.ServerDBConn(tag) // 遍历连接对象
if err1 != nil {
continue
}
sr := conn.Mgo.FindOne(comm.TableHero, bson.M{
"_id": oid,
})
hero = &pb.DBHero{}
if err = sr.Decode(hero); err != nil {
if err != mongo.ErrNoDocuments {
return
}
}
}
filter := bson.M{
} else { // 不是跨服就查本服
if res := this.modelHero.DB.FindOne(comm.TableHero, bson.M{
"_id": oid,
}
sr := conn.Mgo.FindOne(comm.TableHero, filter)
hero = &pb.DBHero{}
if err = sr.Decode(hero); err != nil {
if err != mongo.ErrNoDocuments {
return
}); res == nil {
hero = &pb.DBHero{}
if err = res.Decode(hero); err != nil {
if err != mongo.ErrNoDocuments {
return
}
}
}
}