From 0ad64739ddaa328daf39e59b8bd4d001c5b39a2d Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 17 Nov 2022 19:58:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E8=A3=85=E5=A4=87=E7=A9=BA?= =?UTF-8?q?=E5=80=BC=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/forum/api_watchhero.go | 4 +--- modules/forum/modelForum.go | 37 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 21 deletions(-) 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 }