From b39cef8fa0724f452d3c17dbcf22e18b5890c27c Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 21 Dec 2022 16:47:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=A1=A5=E5=85=85=EF=BC=8C?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=89=B9=E6=9D=83=E7=B1=BB=E5=9E=8B=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=89=B9=E6=9D=83=E5=AF=B9=E5=BA=94=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9A=84=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 ++ modules/privilege/configure.go | 34 +++++++++++++++++++++++++++++++++- modules/privilege/module.go | 15 +++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/comm/imodule.go b/comm/imodule.go index 63d636a6e..fabdb5fcb 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -290,6 +290,8 @@ type ( AddVipData(session IUserSession, oldVip, newVip int32) // 查询所有特权 key 对应comm.PrivilegeType1类型 CheckAllPrivilege(session IUserSession) map[int32]*pb.PrivilegeList + // 通过特权类型获取特权对应的增加数量 + GetCountByPrivilegeId(uid string, pId int32) (count int32) } //武馆 IMartialhall interface { diff --git a/modules/privilege/configure.go b/modules/privilege/configure.go index 1c3925791..9ffd4d210 100644 --- a/modules/privilege/configure.go +++ b/modules/privilege/configure.go @@ -3,8 +3,11 @@ package privilege import ( "fmt" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" + "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "sync" ) const ( @@ -15,7 +18,9 @@ const ( ///背包配置管理组件 type configureComp struct { modules.MCompConfigure - module *Privilege + module *Privilege + hlock sync.RWMutex + _privilegeMap map[int32]map[int32]int32 } //组件初始化接口 @@ -24,6 +29,25 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp this.module = module.(*Privilege) this.LoadConfigure(game_privilegecard, cfg.NewGamePrivilegeCard) this.LoadConfigure(game_privilege, cfg.NewGamePrivilege) + this._privilegeMap = make(map[int32]map[int32]int32, 0) + configure.RegisterConfigure(game_privilege, cfg.NewGamePrivilege, func() { + if v, err := this.GetConfigure(game_privilege); err == nil { + if configure, ok := v.(*cfg.GamePrivilege); ok { + this.hlock.Lock() + defer this.hlock.Unlock() + for k, v := range configure.GetDataMap() { + if v1, ok := this._privilegeMap[v.PrivilegeType]; ok { + v1[k] = v.PrivilegeParameter + } else { + this._privilegeMap[v.PrivilegeType] = make(map[int32]int32) + } + } + return + } + } + log.Errorf("get game_pagoda conf err:%v", err) + return + }) return } @@ -59,3 +83,11 @@ func (this *configureComp) GetPrivilegeData(id int32) (result *cfg.GamePrivilege this.module.Errorf("GetPrivilegeData err, id:%d", id) return nil } + +func (this *configureComp) GetPrivilegeByType(iType int32) (result map[int32]int32) { + result = make(map[int32]int32) + if v, ok := this._privilegeMap[iType]; ok { + result = v + } + return result +} diff --git a/modules/privilege/module.go b/modules/privilege/module.go index 41152e5a3..3e66edb1d 100644 --- a/modules/privilege/module.go +++ b/modules/privilege/module.go @@ -401,3 +401,18 @@ func (this *Privilege) SendDailyPrivilegeMail(session comm.IUserSession, cId []i this.mail.SendMailByCid(session, comm.VipDaily, res) } } +func (this *Privilege) GetCountByPrivilegeId(uid string, pId int32) (count int32) { + vip, err := this.modelVip.getVipList(uid) + if err != nil { + return + } + if v, ok := vip.Privilege[pId]; ok { + data := this.configure.GetPrivilegeByType(pId) + for _, v1 := range v.PrivilegeID { + if c, ok1 := data[v1]; ok1 { + count += c + } + } + } + return +}