diff --git a/modules/forum/api_watchhero.go b/modules/forum/api_watchhero.go index e5e9bd5cc..b39021438 100644 --- a/modules/forum/api_watchhero.go +++ b/modules/forum/api_watchhero.go @@ -28,9 +28,7 @@ func (this *apiComp) WatchHero(session comm.IUserSession, req *pb.ForumWatchHero if hero, err = this.module.modelForum.watchHero(req.Stag, req.Uid, req.HerocId); err != nil { code = pb.ErrorCode_HeroNoExist } - if equip, err = this.module.modelForum.watchHeroEquip(req.Stag, req.Uid, hero.EquipID...); err != nil { - code = pb.ErrorCode_EquipmentOnFoundEquipment - } + equip = this.module.modelForum.watchHeroEquip(req.Stag, req.Uid, hero.EquipID...) session.SendMsg(string(this.module.GetType()), "watchhero", &pb.ForumWatchHeroResp{ Hero: hero, EquipID: equip, diff --git a/modules/forum/modelForum.go b/modules/forum/modelForum.go index 995bba7a6..3a34421db 100644 --- a/modules/forum/modelForum.go +++ b/modules/forum/modelForum.go @@ -156,26 +156,27 @@ func (this *modelForumComp) watchHero(stage string, uid string, herocid string) return } -func (this *modelForumComp) watchHeroEquip(stage string, uid string, equipIds ...string) (equips []*pb.DB_Equipment, err error) { +func (this *modelForumComp) watchHeroEquip(stage string, uid string, equipIds ...string) (equips []*pb.DB_Equipment) { - var ( - tcoon *db.DBConn - ) - if tcoon, err = db.ServerDBConn(stage); err != nil { - this.module.Errorf("stage:%s err:%v", stage, err) - return - } - for id := range equipIds { - sr := tcoon.Mgo.FindOne(comm.TableEquipment, bson.M{ - "_id": id, - }) - equip := &pb.DB_Equipment{} - if err = sr.Decode(equip); err == nil { - equips = append(equips, equip) - } else { - this.module.Errorf("find hero equip error: %v", err) + if tcoon, err := db.ServerDBConn(stage); err == nil { + for _, id := range equipIds { + + if id == "" { + equips = append(equips, nil) + continue + } + sr := tcoon.Mgo.FindOne(comm.TableEquipment, bson.M{ + "_id": id, + }) + equip := &pb.DB_Equipment{} + if err = sr.Decode(equip); err == nil { + equips = append(equips, equip) + } else { + this.module.Errorf("find hero equip error: %v", err) + } } + } else { + this.module.Errorf("stage:%s err:%v", stage, err) } - return }