From 559b96b2870ac3ef6d693816ff7cffe7a9d21336 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 6 Jun 2023 16:52:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=98=E6=96=97?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/battle/modelBattle.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/battle/modelBattle.go b/modules/battle/modelBattle.go index 5d5757681..a1e045091 100644 --- a/modules/battle/modelBattle.go +++ b/modules/battle/modelBattle.go @@ -804,11 +804,11 @@ func (this *modelBattleComp) createMasterRoles(comp, wheel int, fid int32) (capt captain = int32(i) } // if monst, err := this.module.configure.GetMonster(v.Monster); err != nil { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_ConfigNoFound, - Title: pb.ErrorCode_ConfigNoFound.ToString(), - Message: err.Error(), - } + // errdata = &pb.ErrorData{ + // Code: pb.ErrorCode_ConfigNoFound, + // Title: pb.ErrorCode_ConfigNoFound.ToString(), + // Message: err.Error(), + // } // } else { hero := &pb.DBHero{} if hero = this.module.ModuleHero.CreateMonster(fmt.Sprintf("%d", v.Heroid), v.Star, v.Lv); hero == nil { From 12315a53c77a5f545c009f8762168d27b8ee2bc7 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 6 Jun 2023 17:08:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9F=8B=E7=82=B9?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E8=B7=A8?= =?UTF-8?q?=E6=9C=8D=E4=BD=BF=E7=94=A8=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/buried/modelburied.go | 62 +++++++++++++++++++++++++---------- modules/buried/module.go | 9 +++-- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/modules/buried/modelburied.go b/modules/buried/modelburied.go index 858ef212c..f6deb26a7 100644 --- a/modules/buried/modelburied.go +++ b/modules/buried/modelburied.go @@ -8,6 +8,7 @@ import ( "go_dreamfactory/lego/sys/redis" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/db" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" @@ -62,21 +63,48 @@ func (this *modelBuried) userlock(uid string) (result *redis.RedisMutex, err err } //更新埋点数据到db中 -// func (this *modelBuried) getburiedModel(uid string) (model *buriedModel, err error) { -// var m *db.DBModel -// if db.IsCross() { -// if m, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil { -// return -// } -// model = &buriedModel{module: this.module, model: m} -// } else { -// model = &buriedModel{module: this.module, model: this.DBModel} -// } -// return -// } +func (this *modelBuried) getburiedModel(uid string) (model *buriedModel, err error) { + var m *db.DBModel + if db.IsCross() { + if m, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil { + return + } + model = &buriedModel{module: this.module, model: m} + } else { + model = &buriedModel{module: this.module, model: this.DBModel} + } + return +} -// //埋点专属模型 会封装特殊的数据转换接口 -// type buriedModel struct { -// module *Buried -// model *db.DBModel -// } +//埋点专属模型 会封装特殊的数据转换接口 +type buriedModel struct { + module *Buried + model *db.DBModel +} + +//获取用户全部的埋点数据 +func (this *buriedModel) getUserBurieds(uid string) (results *pb.DBBuried, err error) { + results = &pb.DBBuried{} + if err = this.model.Get(uid, results); err != nil && err != mgo.MongodbNil { + this.module.Errorln(err) + return + } + if err == mgo.MongodbNil { + err = nil + results = &pb.DBBuried{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Items: make(map[int32]*pb.DBBuriedItem), + } + err = this.model.Add(uid, results) + } + return +} + +//更新用户数据 +func (this *buriedModel) updateUserBurieds(uid string, data *pb.DBBuried) (err error) { + err = this.model.Change(uid, map[string]interface{}{ + "items": data.Items, + }) + return +} diff --git a/modules/buried/module.go b/modules/buried/module.go index f414691ff..397742ea8 100644 --- a/modules/buried/module.go +++ b/modules/buried/module.go @@ -72,10 +72,13 @@ func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) { var ( conf *cfg.GameBuriedCondiData bdatas *pb.DBBuried + model *buriedModel chanage bool ) - - if bdatas, err = this.modelBuried.getUserBurieds(uid); err != nil { + if model, err = this.modelBuried.getburiedModel(uid); err != nil { + return + } + if bdatas, err = model.getUserBurieds(uid); err != nil { return } for _, v := range condiIds { @@ -110,7 +113,7 @@ func (this *Buried) ActiveCondition(uid string, condiIds ...int32) (err error) { } } if chanage { - err = this.modelBuried.updateUserBurieds(uid, bdatas) + err = model.updateUserBurieds(uid, bdatas) } return }