条件开启功能自动解锁

This commit is contained in:
meixiongfeng 2023-05-05 19:28:06 +08:00
parent af5808a748
commit 852880bdc3
5 changed files with 169 additions and 6 deletions

View File

@ -28,6 +28,9 @@ type (
ISys interface {
IsAccess(funcName string, uid string) (code pb.ErrorCode)
ValidCond(uid string, conf *cfg.GameOpencondData) string
CheckLvUpCond(session IUserSession, lv int32)
CheckTaskCond(session IUserSession, id int32)
CheckMlineCond(session IUserSession, id int32)
}
//邮件业务模块对外接口定义 提供给其他模块使用的

View File

@ -4,7 +4,9 @@ import (
"fmt"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
@ -13,15 +15,61 @@ const (
type configureComp struct {
modules.MCompConfigure
module *ModuleSys
hlock sync.RWMutex
maplv map[int32][]string // 监听等级大于1 的配置
maptask map[int32][]string
mapmline map[int32][]string
}
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options)
this.LoadConfigure(gameOpencond, cfg.NewGameOpencond)
//this.LoadConfigure(gameOpencond, cfg.NewGameOpencond)
configure.RegisterConfigure(gameOpencond, cfg.NewGameOpencond, this.LoadCondConfig)
this.module = module.(*ModuleSys)
this.getFuncCfg("sign")
return
}
func (this *configureComp) LoadCondConfig() {
this.maplv = make(map[int32][]string, 0)
this.maptask = make(map[int32][]string, 0)
this.mapmline = make(map[int32][]string, 0)
if v, err := this.GetConfigure(gameOpencond); err == nil {
if data, ok := v.(*cfg.GameOpencond); ok {
for _, v := range data.GetDataList() {
for _, v1 := range v.Main {
if v.ActivateType == 2 {
if v1.Key == 1 && v1.Param > 1 {
this.maplv[v1.Param] = append(this.maplv[v1.Param], v.Id)
}
if v1.Key == 3 && v1.Param > 1 {
this.maptask[v1.Param] = append(this.maptask[v1.Param], v.Id)
}
if v1.Key == 2 && v1.Param > 1 {
this.mapmline[v1.Param] = append(this.mapmline[v1.Param], v.Id)
}
}
}
}
}
}
}
func (this *configureComp) GetOpencondLv(lv int32) []string {
return this.maplv[lv]
}
func (this *configureComp) getOpencondMline(id int32) []string {
return this.mapmline[id]
}
func (this *configureComp) getOpencondTask(id int32) []string {
return this.maptask[id]
}
func (this *configureComp) getOpencondCfg() (data *cfg.GameOpencond, err error) {
var (
v interface{}

View File

@ -45,3 +45,51 @@ func (this *ModuleSys) IsAccess(funcName string, userId string) (code pb.ErrorCo
func (this *ModuleSys) ValidCond(uid string, conf *cfg.GameOpencondData) string {
return this.modelSys.validCond(uid, conf)
}
func (this *ModuleSys) CheckLvUpCond(session comm.IUserSession, lv int32) {
if cond := this.configure.GetOpencondLv(lv); len(cond) > 0 {
this.AutoActivate(session, cond)
}
}
func (this *ModuleSys) CheckMlineCond(session comm.IUserSession, id int32) {
if cond := this.configure.getOpencondMline(id); len(cond) > 0 {
this.AutoActivate(session, cond)
}
}
func (this *ModuleSys) CheckTaskCond(session comm.IUserSession, id int32) {
if cond := this.configure.getOpencondTask(id); len(cond) > 0 {
this.AutoActivate(session, cond)
}
}
// 自动激活
func (this *ModuleSys) AutoActivate(session comm.IUserSession, cids []string) bool {
var (
szOpen []string
)
list, _ := this.modelSys.GetOpenCondList(session.GetUserId())
for _, cid := range cids {
opencfg := this.configure.getOpencondCfgByCid(cid)
if opencfg != nil {
if id := this.modelSys.validCond(session.GetUserId(), opencfg); id == "" { // 条件不满足
break
}
}
for k, v := range list.Cond {
if k == cid && v != 0 {
break
}
}
list.Cond[cid] = 1
szOpen = append(szOpen, cid)
}
this.modelSys.ChangeOpenCondData(session.GetUserId(), map[string]interface{}{
"cond": list.Cond,
})
// 推送变化
session.SendMsg(string(this.GetType()), "open", &pb.SysFuncOpnePush{
Cid: szOpen,
})
return true
}

View File

@ -289,6 +289,7 @@ func (this *ModelUser) ChangeLevel(event interface{}, next func(event interface{
}
et.TriggerEvent(comm.EventOpenCond, ul.session.GetUserId(), funcList)
isys.CheckLvUpCond(ul.session, curLv) // 校验新功能是否开启
}
}
if err := ul.session.SendMsg(string(this.module.GetType()), UserSubTypeLvChangedPush,

View File

@ -209,6 +209,53 @@ func (x *SysFuncActivateResp) GetCid() string {
return ""
}
type SysFuncOpnePush struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Cid []string `protobuf:"bytes,1,rep,name=cid,proto3" json:"cid"`
}
func (x *SysFuncOpnePush) Reset() {
*x = SysFuncOpnePush{}
if protoimpl.UnsafeEnabled {
mi := &file_sys_sys_msg_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SysFuncOpnePush) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SysFuncOpnePush) ProtoMessage() {}
func (x *SysFuncOpnePush) ProtoReflect() protoreflect.Message {
mi := &file_sys_sys_msg_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SysFuncOpnePush.ProtoReflect.Descriptor instead.
func (*SysFuncOpnePush) Descriptor() ([]byte, []int) {
return file_sys_sys_msg_proto_rawDescGZIP(), []int{4}
}
func (x *SysFuncOpnePush) GetCid() []string {
if x != nil {
return x.Cid
}
return nil
}
var File_sys_sys_msg_proto protoreflect.FileDescriptor
var file_sys_sys_msg_proto_rawDesc = []byte{
@ -229,7 +276,10 @@ var file_sys_sys_msg_proto_rawDesc = []byte{
0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x22, 0x27, 0x0a, 0x13, 0x53, 0x79, 0x73, 0x46, 0x75,
0x6e, 0x63, 0x41, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10,
0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64,
0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x22, 0x23, 0x0a, 0x0f, 0x53, 0x79, 0x73, 0x46, 0x75, 0x6e, 0x63, 0x4f, 0x70, 0x6e, 0x65, 0x50,
0x75, 0x73, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09,
0x52, 0x03, 0x63, 0x69, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -244,16 +294,17 @@ func file_sys_sys_msg_proto_rawDescGZIP() []byte {
return file_sys_sys_msg_proto_rawDescData
}
var file_sys_sys_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_sys_sys_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_sys_sys_msg_proto_goTypes = []interface{}{
(*SysFuncGetListReq)(nil), // 0: SysFuncGetListReq
(*SysFuncGetListResp)(nil), // 1: SysFuncGetListResp
(*SysFuncActivateReq)(nil), // 2: SysFuncActivateReq
(*SysFuncActivateResp)(nil), // 3: SysFuncActivateResp
nil, // 4: SysFuncGetListResp.CondEntry
(*SysFuncOpnePush)(nil), // 4: SysFuncOpnePush
nil, // 5: SysFuncGetListResp.CondEntry
}
var file_sys_sys_msg_proto_depIdxs = []int32{
4, // 0: SysFuncGetListResp.cond:type_name -> SysFuncGetListResp.CondEntry
5, // 0: SysFuncGetListResp.cond:type_name -> SysFuncGetListResp.CondEntry
1, // [1:1] is the sub-list for method output_type
1, // [1:1] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
@ -315,6 +366,18 @@ func file_sys_sys_msg_proto_init() {
return nil
}
}
file_sys_sys_msg_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SysFuncOpnePush); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -322,7 +385,7 @@ func file_sys_sys_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_sys_sys_msg_proto_rawDesc,
NumEnums: 0,
NumMessages: 5,
NumMessages: 6,
NumExtensions: 0,
NumServices: 0,
},