From 9a0666f82857381c084ad5d43c315ad2f02a723b Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 1 Aug 2022 15:02:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B=E9=94=99=E8=AF=AF=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 +- modules/chat/api_chanagechannel.go | 2 +- modules/chat/api_crosschannel.go | 2 +- modules/comp_model.go | 50 +++++++++++++------------- modules/hero/api_drawCard.go | 36 ++++++++++++------- modules/hero/model_hero.go | 2 +- modules/{user => hero}/model_record.go | 23 +++++++++++- modules/hero/module.go | 8 +++-- modules/mail/api_readmail.go | 8 ++--- modules/notify/api_getlist.go | 2 +- modules/task/api_receive.go | 2 +- modules/task/module.go | 2 +- modules/user/api_create.go | 2 +- modules/user/api_figure.go | 2 +- modules/user/api_modifyname.go | 2 +- modules/user/api_modifysign.go | 2 +- modules/user/model_expand.go | 7 ++-- modules/user/model_user.go | 2 +- modules/user/module.go | 4 +-- 19 files changed, 98 insertions(+), 62 deletions(-) rename modules/{user => hero}/model_record.go (57%) diff --git a/comm/imodule.go b/comm/imodule.go index 07e5bafc6..ac7260dd6 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -67,7 +67,7 @@ type ( //获取用户expand GetUserExpand(uid string) (result *pb.DBUserExpand, err error) //更新用户expand - ChanageUserExpand(uid string, value map[string]interface{}) error + ChangeUserExpand(uid string, value map[string]interface{}) error } //武器模块 IEquipment interface { diff --git a/modules/chat/api_chanagechannel.go b/modules/chat/api_chanagechannel.go index fcedbec7c..fa90696c0 100644 --- a/modules/chat/api_chanagechannel.go +++ b/modules/chat/api_chanagechannel.go @@ -28,7 +28,7 @@ func (this *apiComp) ChanageChannel(session comm.IUserSession, req *pb.ChatChana code = pb.ErrorCode_DBError return } - this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ + this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ "chatchannel": req.ChannelId, }) } diff --git a/modules/chat/api_crosschannel.go b/modules/chat/api_crosschannel.go index a32ce3a47..02d78f264 100644 --- a/modules/chat/api_crosschannel.go +++ b/modules/chat/api_crosschannel.go @@ -23,7 +23,7 @@ func (this *apiComp) CrossChannel(session comm.IUserSession, req *pb.ChatCrossCh code = pb.ErrorCode_DBError return } - this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ + this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ "chatchannel": channel, }) session.SendMsg(string(this.module.GetType()), "crosschannel", &pb.ChatCrossChannelResp{ChannelId: channel}) diff --git a/modules/comp_model.go b/modules/comp_model.go index 31d3a9aad..2b02e7ff7 100644 --- a/modules/comp_model.go +++ b/modules/comp_model.go @@ -11,11 +11,9 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/lego/sys/redis" - "go_dreamfactory/pb" "go_dreamfactory/sys/cache" "go_dreamfactory/sys/db" "reflect" - "time" "unsafe" "github.com/modern-go/reflect2" @@ -671,31 +669,31 @@ func (this *MCompModel) logOpt(uid string, data interface{}, attrs ...*cache.Ope } //获取用户通过扩展表 -func (this *MCompModel) GetUserRecord(uid string) (result *pb.DBUserRecord, err error) { - result = &pb.DBUserRecord{} - key := fmt.Sprintf("userrecord:%s{userrecord}", uid) - if err = this.Redis.HGetAll(key, result); err != nil && err != redis.RedisNil { - return - } - if err == redis.RedisNil { - if err = this.DB.FindOne(core.SqlTable("userrecord"), bson.M{"uid": uid}).Decode(result); err != nil { - return - } - err = this.Redis.HMSet(key, result) - } - return -} +// func (this *MCompModel) GetUserRecord(uid string) (result *pb.DBUserRecord, err error) { +// result = &pb.DBUserRecord{} +// key := fmt.Sprintf("userrecord:%s{userrecord}", uid) +// if err = this.Redis.HGetAll(key, result); err != nil && err != redis.RedisNil { +// return +// } +// if err == redis.RedisNil { +// if err = this.DB.FindOne(core.SqlTable("userrecord"), bson.M{"uid": uid}).Decode(result); err != nil { +// return +// } +// err = this.Redis.HMSet(key, result) +// } +// return +// } -//修改用户扩展数据 -func (this *MCompModel) ChangeUserRecord(uid string, value map[string]interface{}) (err error) { - value["mtime"] = time.Now().Unix() // 更新时间 - key := fmt.Sprintf("userrecord:%s{userrecord}", uid) - if err = this.Redis.HMSet(key, value); err != nil && err != redis.RedisNil { - return - } - err = this.UpdateModelLogs("userrecord", uid, bson.M{"uid": uid}, value) - return -} +// //修改用户扩展数据 +// func (this *MCompModel) ChangeUserRecord(uid string, value map[string]interface{}) (err error) { +// value["mtime"] = time.Now().Unix() // 更新时间 +// key := fmt.Sprintf("userrecord:%s{userrecord}", uid) +// if err = this.Redis.HMSet(key, value); err != nil && err != redis.RedisNil { +// return +// } +// err = this.UpdateModelLogs("userrecord", uid, bson.M{"uid": uid}, value) +// return +// } // 删除玩家缓存信息 func (this *MCompModel) CleanUserRecord(uid string) (err error) { diff --git a/modules/hero/api_drawCard.go b/modules/hero/api_drawCard.go index f312d24f3..b30569312 100644 --- a/modules/hero/api_drawCard.go +++ b/modules/hero/api_drawCard.go @@ -53,27 +53,39 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq } } // =======活动数据记录完成 - rst, _ := this.module.modelHero.GetUserRecord(session.GetUserId()) + rst, _ := this.module.modelRecord.GetUserRecord(session.GetUserId()) if req.DrawType%2 == 0 { // 转成对应阵营信息 1~5 race = int32((int(req.DrawType)) / 2) } else { race = int32(int(req.DrawType+1) / 2) } + if race == comm.RacePt { // 普通卡池 - curStar4Count = rst.Race0.H4 - curStar5Count = rst.Race0.H5 + if rst.Race0 != nil { + curStar4Count = rst.Race0.H4 + curStar5Count = rst.Race0.H5 + } + } else if race == comm.RaceZr { // 灼热 - curStar4Count = rst.Race1.H4 - curStar5Count = rst.Race1.H5 + if rst.Race1 != nil { + curStar4Count = rst.Race1.H4 + curStar5Count = rst.Race1.H5 + } } else if race == comm.RaceYd { // 涌动 - curStar4Count = rst.Race2.H4 - curStar5Count = rst.Race2.H5 + if rst.Race2 != nil { + curStar4Count = rst.Race2.H4 + curStar5Count = rst.Race2.H5 + } } else if race == comm.RaceHx { // 呼啸 - curStar4Count = rst.Race3.H4 - curStar5Count = rst.Race3.H5 + if rst.Race3 != nil { + curStar4Count = rst.Race3.H4 + curStar5Count = rst.Race3.H5 + } } else if race == comm.RaceSy { // 闪耀 - curStar4Count = rst.Race4.H4 - curStar5Count = rst.Race4.H5 + if rst.Race4 != nil { + curStar4Count = rst.Race4.H4 + curStar5Count = rst.Race4.H5 + } } // 获取配置文件的权重信息 _conf, err := this.module.configure.GetHeroDrawConfig(race) @@ -185,7 +197,7 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq update := map[string]interface{}{} update["race"+strconv.Itoa(int(race)-1)] = raceData - this.module.modelHero.ChangeUserRecord(session.GetUserId(), update) + this.module.modelRecord.ChangeUserRecord(session.GetUserId(), update) // 消耗道具 code = this.module.ConsumeRes(session, sz, true) if code != pb.ErrorCode_Success { diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 8f04c01ed..65f2ac6fb 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -123,7 +123,7 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int "tujian": sz, } - this.moduleHero.ModuleUser.ChanageUserExpand(uid, initUpdate) + this.moduleHero.ModuleUser.ChangeUserExpand(uid, initUpdate) } } hero.SameCount = count diff --git a/modules/user/model_record.go b/modules/hero/model_record.go similarity index 57% rename from modules/user/model_record.go rename to modules/hero/model_record.go index 55cca24cb..d170379f9 100644 --- a/modules/user/model_record.go +++ b/modules/hero/model_record.go @@ -1,10 +1,12 @@ -package user +package hero import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/mongo" ) // 记录一些扩展数据 图鉴 改名次数等 @@ -27,3 +29,22 @@ func (this *ModelRecord) getUserSession(uid string) (cuser *pb.CacheUser) { } return } + +//获取用户通过扩展表 +func (this *ModelRecord) GetUserRecord(uid string) (result *pb.DBUserRecord, err error) { + result = &pb.DBUserRecord{} + if err = this.Get(uid, result); err != nil && err != mongo.ErrNoDocuments { + return + } + err = nil + return result, err +} + +//修改用户扩展数据 +func (this *ModelRecord) ChangeUserRecord(uid string, value map[string]interface{}) (err error) { + if len(value) == 0 { + return nil + } + return this.Change(uid, value) + +} diff --git a/modules/hero/module.go b/modules/hero/module.go index 96722aa73..c98b99455 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -16,9 +16,10 @@ func NewModule() core.IModule { type Hero struct { modules.ModuleBase - api *apiComp - configure *configureComp - modelHero *ModelHero + api *apiComp + configure *configureComp + modelHero *ModelHero + modelRecord *ModelRecord } //模块名 @@ -37,6 +38,7 @@ func (this *Hero) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelHero = this.RegisterComp(new(ModelHero)).(*ModelHero) + this.modelRecord = this.RegisterComp(new(ModelRecord)).(*ModelRecord) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } diff --git a/modules/mail/api_readmail.go b/modules/mail/api_readmail.go index 0e4c4be7b..0a1eacff5 100644 --- a/modules/mail/api_readmail.go +++ b/modules/mail/api_readmail.go @@ -21,9 +21,7 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq err error mail *pb.DBMailData ) - defer func() { - session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail}) - }() + code = this.ReadMailCheck(session, req) // check if code != pb.ErrorCode_Success { return @@ -31,7 +29,9 @@ func (this *apiComp) ReadMail(session comm.IUserSession, req *pb.MailReadMailReq mail, err = this.module.modelMail.Mail_ReadOneMail(req.ObjID) if err != nil { code = pb.ErrorCode_ReqParameterError + return } - + mail.Check = true + session.SendMsg(string(this.module.GetType()), "readmail", &pb.MailReadMailResp{Mail: mail}) return } diff --git a/modules/notify/api_getlist.go b/modules/notify/api_getlist.go index 2de69e2c2..40f3ded32 100644 --- a/modules/notify/api_getlist.go +++ b/modules/notify/api_getlist.go @@ -34,7 +34,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.NotifyGetListReq userexpand = &pb.DBUserExpand{} } //修改最后公告读取时间 - this.module.ModuleUser.ChanageUserExpand(session.GetUserId(), map[string]interface{}{ + this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ "lastreadnotiftime": time.Now().Unix(), }) session.SendMsg(string(this.module.GetType()), "getlist", &pb.NotifyGetListResp{LastReadTime: userexpand.Lastreadnotiftime, SysNotify: notify}) diff --git a/modules/task/api_receive.go b/modules/task/api_receive.go index 46a741dfb..6f99366a2 100644 --- a/modules/task/api_receive.go +++ b/modules/task/api_receive.go @@ -63,7 +63,7 @@ func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq) update["activeweek"] = ue.Activeweek + conf.Active } if len(update) > 0 { - if err = this.moduleTask.ModuleUser.ChanageUserExpand(session.GetUserId(), update); err != nil { + if err = this.moduleTask.ModuleUser.ChangeUserExpand(session.GetUserId(), update); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/task/module.go b/modules/task/module.go index 328c5971f..9d79f922b 100644 --- a/modules/task/module.go +++ b/modules/task/module.go @@ -72,7 +72,7 @@ func (this *ModuleTask) resetActive(uid string, taskTag comm.TaskTag) { update["activeweek"] = 0 } if len(update) > 0 { - this.ModuleUser.ChanageUserExpand(uid, update) + this.ModuleUser.ChangeUserExpand(uid, update) } } diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 8eeea05ab..cfcc651be 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -62,7 +62,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c initUpdate := map[string]interface{}{ "modifynameCount": 1, //修改名称1次 } - if err := this.module.modelExpand.ChanageUserExpand(session.GetUserId(), initUpdate); err != nil { + if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), initUpdate); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/user/api_figure.go b/modules/user/api_figure.go index 4f21c8b56..de3eefa38 100644 --- a/modules/user/api_figure.go +++ b/modules/user/api_figure.go @@ -82,7 +82,7 @@ func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (c update = utils.StructToMap(curFigure) - this.module.modelExpand.ChanageUserExpand(session.GetUserId(), update) + this.module.modelExpand.ChangeUserExpand(session.GetUserId(), update) } if err := session.SendMsg(string(this.module.GetType()), UserSubTypeFigure, rsp); err != nil { diff --git a/modules/user/api_modifyname.go b/modules/user/api_modifyname.go index fc85c6caa..d9e28ae43 100644 --- a/modules/user/api_modifyname.go +++ b/modules/user/api_modifyname.go @@ -56,7 +56,7 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam mc := map[string]interface{}{ "modifynameCount": left, } - if err := this.module.modelExpand.ChanageUserExpand(session.GetUserId(), mc); err != nil { + if err := this.module.modelExpand.ChangeUserExpand(session.GetUserId(), mc); err != nil { code = pb.ErrorCode_DBError return } diff --git a/modules/user/api_modifysign.go b/modules/user/api_modifysign.go index 971435216..fb3a79f0a 100644 --- a/modules/user/api_modifysign.go +++ b/modules/user/api_modifysign.go @@ -31,7 +31,7 @@ func (this *apiComp) Modifysign(session comm.IUserSession, req *pb.UserModifysig update := map[string]interface{}{ "sign": req.Sign, } - this.module.ChanageUserExpand(session.GetUserId(), update) + this.module.ChangeUserExpand(session.GetUserId(), update) } if err = session.SendMsg(string(this.module.GetType()), UserSubTypeModifySign, &pb.UserModifysignResp{ diff --git a/modules/user/model_expand.go b/modules/user/model_expand.go index f6b9d586a..faf618194 100644 --- a/modules/user/model_expand.go +++ b/modules/user/model_expand.go @@ -5,6 +5,8 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/mongo" ) // 记录一些扩展数据 @@ -33,14 +35,15 @@ func (this *ModelExpand) getUserSession(uid string) (cuser *pb.CacheUser) { //获取用户通过扩展表 func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) { result = &pb.DBUserExpand{} - if err = this.moduleUser.modelExpand.Get(uid, result); err != nil { + if err = this.moduleUser.modelExpand.Get(uid, result); err != nil && err != mongo.ErrNoDocuments { return } + err = nil return result, err } //修改用户扩展数据 -func (this *ModelExpand) ChanageUserExpand(uid string, value map[string]interface{}) (err error) { +func (this *ModelExpand) ChangeUserExpand(uid string, value map[string]interface{}) (err error) { if len(value) == 0 { return nil } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index ae23c592a..bdc8c23bc 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -152,7 +152,7 @@ func (this *ModelUser) InitFigure(uid string) { update := map[string]interface{}{ "preinstall": figureMap, } - this.moduleUser.modelExpand.ChanageUserExpand(uid, update) + this.moduleUser.modelExpand.ChangeUserExpand(uid, update) } // change exp diff --git a/modules/user/module.go b/modules/user/module.go index 78031ce79..3161f99f0 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -176,6 +176,6 @@ func (this *User) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) return this.modelExpand.GetUserExpand(uid) } -func (this *User) ChanageUserExpand(uid string, value map[string]interface{}) error { - return this.modelExpand.ChanageUserExpand(uid, value) +func (this *User) ChangeUserExpand(uid string, value map[string]interface{}) error { + return this.modelExpand.ChangeUserExpand(uid, value) }