From cca6e266260e1c6625041dad1da6d8791b1e2814 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 13 Dec 2022 19:50:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0vip=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 + modules/privilege/api.go | 1 + modules/privilege/api_viplist.go | 24 ++++++ modules/privilege/model_vip.go | 21 +++-- modules/privilege/module.go | 6 ++ modules/user/model_user.go | 4 + pb/privilege_msg.pb.go | 144 ++++++++++++++++++++++++++++--- 7 files changed, 183 insertions(+), 19 deletions(-) create mode 100644 modules/privilege/api_viplist.go diff --git a/comm/imodule.go b/comm/imodule.go index 9c401d3c2..ff7b8d225 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -283,6 +283,8 @@ type ( CheckPrivilege(session IUserSession, cId string) (privilege *pb.DBPrivilege) // 查询玩家当前所有特权 返回特权id QueryPrivilege(session IUserSession) (privilegeID []int32) + // 获得vip + AddVipData(session IUserSession) } //武馆 IMartialhall interface { diff --git a/modules/privilege/api.go b/modules/privilege/api.go index 3ab3224cf..91059909c 100644 --- a/modules/privilege/api.go +++ b/modules/privilege/api.go @@ -10,6 +10,7 @@ const ( PrivilegeGetListResp = "getlist" PrivilegeBuyYuekaResp = "buyyueka" PrivilegeBuyGiftResp = "buygift" + PrivilegeVipListResp = "viplist" ) type apiComp struct { diff --git a/modules/privilege/api_viplist.go b/modules/privilege/api_viplist.go new file mode 100644 index 000000000..0a287b548 --- /dev/null +++ b/modules/privilege/api_viplist.go @@ -0,0 +1,24 @@ +package privilege + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) VipListCheck(session comm.IUserSession, req *pb.PrivilegeVipListReq) (code pb.ErrorCode) { + + return +} + +///获取特权列表 +func (this *apiComp) VipList(session comm.IUserSession, req *pb.PrivilegeVipListReq) (code pb.ErrorCode, data proto.Message) { + list, err := this.module.modelVip.getVipList(session.GetUserId()) + if err != nil { + this.module.Errorf("can't get privilege list :%v", err) + } + session.SendMsg(string(this.module.GetType()), PrivilegeGetListResp, &pb.PrivilegeVipListResp{Data: list}) + return +} diff --git a/modules/privilege/model_vip.go b/modules/privilege/model_vip.go index c3a2fcff1..44d2a5e5f 100644 --- a/modules/privilege/model_vip.go +++ b/modules/privilege/model_vip.go @@ -6,7 +6,9 @@ import ( "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -44,11 +46,20 @@ func (this *ModelVip) modifyVipData(uid string, data map[string]interface{}) err } // 增加vip信息 -func (this *ModelVip) addVipData(uId string, vip *pb.DBVip) (err error) { +func (this *ModelVip) addVipData(uId string) (vip *pb.DBVip, err error) { - if err = this.Add(uId, vip); err != nil { - this.module.Errorf("err:%v", err) - return err + vip, err = this.getVipList(uId) + if err != nil { + return vip, err } - return nil + if vip.Id == "" { + vip.Id = primitive.NewObjectID().Hex() + vip.CTime = configure.Now().Unix() + if err = this.Add(uId, vip); err != nil { + this.module.Errorf("err:%v", err) + return + } + } + + return } diff --git a/modules/privilege/module.go b/modules/privilege/module.go index 519ec0e79..abd9e8cae 100644 --- a/modules/privilege/module.go +++ b/modules/privilege/module.go @@ -261,3 +261,9 @@ func (this *Privilege) SendDailyMail(session comm.IUserSession, cId string, coun } } +func (this *Privilege) AddVipData(session comm.IUserSession) { + vip, err := this.modelVip.addVipData(session.GetUserId()) + if err != nil { // 推送 + session.SendMsg(string(this.GetType()), PrivilegeGetListResp, &pb.PrivilegeVipListResp{Data: vip}) + } +} diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 7de2c02ab..d8df34b7b 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -205,6 +205,10 @@ func (this *ModelUser) ChangeVipExp(event interface{}, next func(event interface return } } + // + if ul.viplv == 0 && vipLv > 0 { // 新获得了vip + this.module.ModulePrivilege.AddVipData(ul.session) + } // 推送玩家vip 经验变化 ul.session.SendMsg(string(this.module.GetType()), UserSubTypeVipChangedPush, &pb.UserVipChangedPush{ diff --git a/pb/privilege_msg.pb.go b/pb/privilege_msg.pb.go index 5be9c600c..59f8d93ec 100644 --- a/pb/privilege_msg.pb.go +++ b/pb/privilege_msg.pb.go @@ -296,6 +296,91 @@ func (x *PrivilegeBuyGiftResp) GetData() *DBVip { return nil } +type PrivilegeVipListReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *PrivilegeVipListReq) Reset() { + *x = PrivilegeVipListReq{} + if protoimpl.UnsafeEnabled { + mi := &file_privilege_privilege_msg_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrivilegeVipListReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrivilegeVipListReq) ProtoMessage() {} + +func (x *PrivilegeVipListReq) ProtoReflect() protoreflect.Message { + mi := &file_privilege_privilege_msg_proto_msgTypes[6] + 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 PrivilegeVipListReq.ProtoReflect.Descriptor instead. +func (*PrivilegeVipListReq) Descriptor() ([]byte, []int) { + return file_privilege_privilege_msg_proto_rawDescGZIP(), []int{6} +} + +type PrivilegeVipListResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Data *DBVip `protobuf:"bytes,1,opt,name=data,proto3" json:"data"` +} + +func (x *PrivilegeVipListResp) Reset() { + *x = PrivilegeVipListResp{} + if protoimpl.UnsafeEnabled { + mi := &file_privilege_privilege_msg_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PrivilegeVipListResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrivilegeVipListResp) ProtoMessage() {} + +func (x *PrivilegeVipListResp) ProtoReflect() protoreflect.Message { + mi := &file_privilege_privilege_msg_proto_msgTypes[7] + 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 PrivilegeVipListResp.ProtoReflect.Descriptor instead. +func (*PrivilegeVipListResp) Descriptor() ([]byte, []int) { + return file_privilege_privilege_msg_proto_rawDescGZIP(), []int{7} +} + +func (x *PrivilegeVipListResp) GetData() *DBVip { + if x != nil { + return x.Data + } + return nil +} + var File_privilege_privilege_msg_proto protoreflect.FileDescriptor var file_privilege_privilege_msg_proto_rawDesc = []byte{ @@ -320,8 +405,12 @@ var file_privilege_privilege_msg_proto_rawDesc = []byte{ 0x22, 0x32, 0x0a, 0x14, 0x50, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, 0x65, 0x42, 0x75, 0x79, 0x47, 0x69, 0x66, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x44, 0x42, 0x56, 0x69, 0x70, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x61, 0x74, 0x61, 0x22, 0x15, 0x0a, 0x13, 0x50, 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, + 0x65, 0x56, 0x69, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x22, 0x32, 0x0a, 0x14, 0x50, + 0x72, 0x69, 0x76, 0x69, 0x6c, 0x65, 0x67, 0x65, 0x56, 0x69, 0x70, 0x4c, 0x69, 0x73, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x06, 0x2e, 0x44, 0x42, 0x56, 0x69, 0x70, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, + 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -336,7 +425,7 @@ func file_privilege_privilege_msg_proto_rawDescGZIP() []byte { return file_privilege_privilege_msg_proto_rawDescData } -var file_privilege_privilege_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_privilege_privilege_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_privilege_privilege_msg_proto_goTypes = []interface{}{ (*PrivilegeGetListReq)(nil), // 0: PrivilegeGetListReq (*PrivilegeGetListResp)(nil), // 1: PrivilegeGetListResp @@ -344,18 +433,21 @@ var file_privilege_privilege_msg_proto_goTypes = []interface{}{ (*PrivilegeBuyYuekaResp)(nil), // 3: PrivilegeBuyYuekaResp (*PrivilegeBuyGiftReq)(nil), // 4: PrivilegeBuyGiftReq (*PrivilegeBuyGiftResp)(nil), // 5: PrivilegeBuyGiftResp - (*DBPrivilege)(nil), // 6: DBPrivilege - (*DBVip)(nil), // 7: DBVip + (*PrivilegeVipListReq)(nil), // 6: PrivilegeVipListReq + (*PrivilegeVipListResp)(nil), // 7: PrivilegeVipListResp + (*DBPrivilege)(nil), // 8: DBPrivilege + (*DBVip)(nil), // 9: DBVip } var file_privilege_privilege_msg_proto_depIdxs = []int32{ - 6, // 0: PrivilegeGetListResp.data:type_name -> DBPrivilege - 6, // 1: PrivilegeBuyYuekaResp.data:type_name -> DBPrivilege - 7, // 2: PrivilegeBuyGiftResp.data:type_name -> DBVip - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 8, // 0: PrivilegeGetListResp.data:type_name -> DBPrivilege + 8, // 1: PrivilegeBuyYuekaResp.data:type_name -> DBPrivilege + 9, // 2: PrivilegeBuyGiftResp.data:type_name -> DBVip + 9, // 3: PrivilegeVipListResp.data:type_name -> DBVip + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_privilege_privilege_msg_proto_init() } @@ -437,6 +529,30 @@ func file_privilege_privilege_msg_proto_init() { return nil } } + file_privilege_privilege_msg_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PrivilegeVipListReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_privilege_privilege_msg_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PrivilegeVipListResp); 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{ @@ -444,7 +560,7 @@ func file_privilege_privilege_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_privilege_privilege_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 8, NumExtensions: 0, NumServices: 0, },