From 94ea61f862962e47623762cf3be6d739d8ece9ef Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Fri, 4 Nov 2022 14:42:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=AC=E4=BC=9A?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/v2/lib/common/list.go | 13 +- cmd/v2/ui/app_testcase.go | 2 +- cmd/v2/ui/protocol.go | 3 +- cmd/v2/ui/toy_userinfo.go | 14 ++- cmd/v2/ui/views/baseformview.go | 4 +- cmd/v2/ui/views/sociaty_list.go | 83 +++++++++++- cmd/v2/ui/views/sociaty_mine.go | 1 - comm/imodule.go | 6 +- modules/chat/module.go | 2 +- modules/sociaty/api.go | 1 + modules/sociaty/api_cross_agree.go | 8 +- modules/sociaty/api_cross_create.go | 2 +- modules/sociaty/model_sociaty.go | 15 ++- modules/sociaty/model_sociatylog.go | 2 +- modules/sociaty/module.go | 10 +- pb/sociaty_msg.pb.go | 187 ++++++++++++++++++++++++---- 16 files changed, 302 insertions(+), 51 deletions(-) diff --git a/cmd/v2/lib/common/list.go b/cmd/v2/lib/common/list.go index 2d983d8ba..0c7b4324d 100644 --- a/cmd/v2/lib/common/list.go +++ b/cmd/v2/lib/common/list.go @@ -57,12 +57,13 @@ func (l List) Less(i, j int) bool { } type Item struct { - Id string `json:"id"` - Title string `json:"title"` - Text string `json:"text"` - Quantity int `json:"quantity"` - Checked bool `json:"checked"` - Size int64 `json:"size"` + Id string `json:"id"` + Title string `json:"title"` + Text string `json:"text"` + Quantity int `json:"quantity"` + Checked bool `json:"checked"` + Size int64 `json:"size"` + Data interface{} `json:"data"` } func NewList(name string) List { diff --git a/cmd/v2/ui/app_testcase.go b/cmd/v2/ui/app_testcase.go index 6c1432f34..ccf722f8c 100644 --- a/cmd/v2/ui/app_testcase.go +++ b/cmd/v2/ui/app_testcase.go @@ -52,8 +52,8 @@ func (a *appTester) LazyInit(service service.PttService, obs observer.Observer) if view, ok := viewRegister[viewKey]; ok { timeLbl := widget.NewLabel("time") - view.Init(service, obs, globalWin.w) resLog := widget.NewMultiLineEntry() + view.Init(service, obs, globalWin.w, resLog) obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ OnNotify: func(data interface{}, args ...interface{}) { diff --git a/cmd/v2/ui/protocol.go b/cmd/v2/ui/protocol.go index 91de0f2f3..86506bfa7 100644 --- a/cmd/v2/ui/protocol.go +++ b/cmd/v2/ui/protocol.go @@ -22,13 +22,14 @@ import ( "strings" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/widget" "github.com/sirupsen/logrus" "github.com/spf13/cast" "google.golang.org/protobuf/proto" ) type MyCaseView interface { - Init(service service.PttService, obs observer.Observer, w fyne.Window) + Init(service service.PttService, obs observer.Observer, w fyne.Window, res *widget.Entry) CreateView(t *model.TestCase) fyne.CanvasObject Load() } diff --git a/cmd/v2/ui/toy_userinfo.go b/cmd/v2/ui/toy_userinfo.go index 0635650b9..3f24a4292 100644 --- a/cmd/v2/ui/toy_userinfo.go +++ b/cmd/v2/ui/toy_userinfo.go @@ -34,6 +34,7 @@ type toyUserInfo struct { obs observer.Observer copyBtn *widget.Button refreshBtn *widget.Button + logoutBtn *widget.Button } func (this *toyUserInfo) Init(obs observer.Observer) error { @@ -62,6 +63,17 @@ func (this *toyUserInfo) Init(obs observer.Observer) error { }) this.refreshBtn.Disable() + // 注销用户 + this.logoutBtn = widget.NewButtonWithIcon("", theme.AccountIcon(), func() { + if err := service.GetPttService().SendToClient( + string(comm.ModuleUser), + user.UserSubTypeInfo, + &pb.UserInfoReq{}); err != nil { + logrus.Error(err) + return + } + }) + // list this.dataList = widget.NewListWithData(this.data, func() fyne.CanvasObject { @@ -76,7 +88,7 @@ func (this *toyUserInfo) Init(obs observer.Observer) error { // sign := widget.NewRichTextFromMarkdown(``) // layout this.widget = widget.NewCard("", "", - container.NewBorder(container.NewHBox(this.titleLabel, layout.NewSpacer(), this.refreshBtn, this.copyBtn), + container.NewBorder(container.NewHBox(this.titleLabel, layout.NewSpacer(), this.logoutBtn, this.refreshBtn, this.copyBtn), nil, nil, nil, container.NewVScroll(this.dataList))) this.widget.Resize(fyne.NewSize(ToyWidth, 650)) diff --git a/cmd/v2/ui/views/baseformview.go b/cmd/v2/ui/views/baseformview.go index 587e3ffb7..1f3479b2f 100644 --- a/cmd/v2/ui/views/baseformview.go +++ b/cmd/v2/ui/views/baseformview.go @@ -13,13 +13,15 @@ type BaseformView struct { form *widget.Form obs observer.Observer w fyne.Window + res *widget.Entry service service.PttService } -func (this *BaseformView) Init(service service.PttService, obs observer.Observer, w fyne.Window) { +func (this *BaseformView) Init(service service.PttService, obs observer.Observer, w fyne.Window, res *widget.Entry) { this.service = service this.obs = obs this.w = w + this.res = res this.form = widget.NewForm() this.form.SubmitText = common.BUTTON_OK } diff --git a/cmd/v2/ui/views/sociaty_list.go b/cmd/v2/ui/views/sociaty_list.go index 727f1617b..008b10ae4 100644 --- a/cmd/v2/ui/views/sociaty_list.go +++ b/cmd/v2/ui/views/sociaty_list.go @@ -10,8 +10,11 @@ import ( "go_dreamfactory/modules/sociaty" "go_dreamfactory/pb" + jsoniter "github.com/json-iterator/go" + "fyne.io/fyne/v2" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "github.com/sirupsen/logrus" @@ -20,8 +23,9 @@ import ( type SociatyListView struct { sociatyList func() BaseformView - itemList *common.ItemList - flag bool + itemList *common.ItemList + flag bool + detailFlag bool } func (this *SociatyListView) CreateView(t *model.TestCase) fyne.CanvasObject { @@ -29,6 +33,14 @@ func (this *SociatyListView) CreateView(t *model.TestCase) fyne.CanvasObject { this.itemList.ItemList = this.itemList.CreateList() + this.itemList.ItemList.OnSelected = func(id widget.ListItemID) { + item := this.itemList.CachedList.Items[id] + logrus.Debug(item) + if s, ok := item.Data.(*pb.DBSociaty); ok { + this.res.Text, _ = jsoniter.MarshalToString(s) + } + } + this.sociatyList = func() { this.itemList.Reset() if err := service.GetPttService().SendToClient( @@ -82,7 +94,31 @@ func (this *SociatyListView) CreateView(t *model.TestCase) fyne.CanvasObject { }) // 明细 - detailBtn := widget.NewButton("明细", nil) + // item := &entryItem{ + // sociatyName: widget.NewEntry(), + // notice: widget.NewMultiLineEntry(), + // icon: widget.NewEntry(), + // isApplyCheck: widget.NewCheck("审批", nil), + // applyLv: widget.NewEntry(), + // } + + // this.form.AppendItem(widget.NewFormItem("公会名称", item.sociatyName)) + // this.form.AppendItem(widget.NewFormItem("公告", item.notice)) + // this.form.AppendItem(widget.NewFormItem("图标", item.icon)) + // this.form.AppendItem(widget.NewFormItem("审批", item.isApplyCheck)) + // this.form.AppendItem(widget.NewFormItem("入会等级", item.applyLv)) + // this.formdataListen(item) + + // detailBtn := widget.NewButton("明细", func() { + // if err := service.GetPttService().SendToClient( + // string(comm.ModuleSociaty), + // sociaty.SociatySubTypeMine, + // &pb.SociatyMineReq{}); err != nil { + // logrus.Error(err) + // } + + // defer this.showSociatyDetailWin() + // }) //过滤 filter := widget.NewSelect([]string{"全部", "满足条件", "无需审批", "申请中"}, func(s string) { @@ -127,7 +163,7 @@ func (this *SociatyListView) CreateView(t *model.TestCase) fyne.CanvasObject { } }) - buttonBar := container.NewHBox(refreshBtn, applyBtn, cancalApplyBtn, detailBtn, filter) + buttonBar := container.NewHBox(refreshBtn, applyBtn, cancalApplyBtn, filter) cBar := container.NewBorder(nil, nil, buttonBar, searchBtn, searchEntry) // layout c := container.NewBorder(cBar, nil, nil, nil, this.itemList.ItemList) @@ -161,10 +197,12 @@ func (this *SociatyListView) dataListener() { } else { isApplyCheckLbl = "无需审核" } - lbl := fmt.Sprintf("%d - %-15s 等级:%-5d 等级限制:%-5d (%d) %10v", i+1, v.Name, v.Lv, v.ApplyLv, memberCount, isApplyCheckLbl) + lbl := fmt.Sprintf("%d - %-15s 等级:%-5d 等级限制:%-5d (%d) %10v", + i+1, v.Name, v.Lv, v.ApplyLv, memberCount, isApplyCheckLbl) item := common.Item{ Id: v.Id, Text: lbl, + Data: v, } this.itemList.AddItem(item) } @@ -192,3 +230,38 @@ func (this *SociatyListView) dataListener() { }) this.flag = true } + +// 显示公会明细 +func (this *SociatyListView) showSociatyDetailWin() { + c := container.NewBorder(nil, nil, nil, nil, this.form) + dconf := dialog.NewCustom("公会详情", "关闭", c, this.w) + dconf.Resize(fyne.NewSize(800, 500)) + dconf.Show() + this.form.Refresh() +} + +func (this *SociatyListView) formdataListen(item *entryItem) { + if this.detailFlag { + return + } + this.obs.AddListener(observer.EVENT_REQ_RSP, observer.Listener{ + OnNotify: func(d interface{}, args ...interface{}) { + data := d.(*pb.UserMessage) + if !(data.MainType == string(comm.ModuleSociaty) && + data.SubType == sociaty.SociatySubTypeMine) { + return + } + rsp := &pb.SociatyMineResp{} + + if rsp.Sociaty == nil { + return + } + logrus.Debug(rsp.Sociaty) + item.sociatyName.Text = rsp.Sociaty.Name + item.notice.Text = rsp.Sociaty.Notice + + this.form.Refresh() + }, + }) + this.detailFlag = true +} diff --git a/cmd/v2/ui/views/sociaty_mine.go b/cmd/v2/ui/views/sociaty_mine.go index f46914e46..88a245b4e 100644 --- a/cmd/v2/ui/views/sociaty_mine.go +++ b/cmd/v2/ui/views/sociaty_mine.go @@ -207,7 +207,6 @@ func (this *SociatyMineView) CreateView(t *model.TestCase) fyne.CanvasObject { t.MainType, sociaty.SociatySubTypeSetting, &pb.SociatySettingReq{ - SociatyId: this.sociaty.Id, Icon: item.icon.Text, Notice: item.notice.Text, ApplyLv: cast.ToInt32(item.applyLv.Text), diff --git a/comm/imodule.go b/comm/imodule.go index be8c0deca..15efa4745 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -214,8 +214,10 @@ type ( ISociaty interface { //会长弹劾处理 ProcessAccuse(uid, sociatyId string) - // 公会成员 - Members(uid string) (list []*pb.SociatyMemberInfo) + // 获取我的公会成员 + MembersByUid(uid string) (list []*pb.SociatyMemberInfo) + // 获取公会成员 + MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo) } //星座图 IHoroscope interface { diff --git a/modules/chat/module.go b/modules/chat/module.go index 059bb8893..62ae2525f 100644 --- a/modules/chat/module.go +++ b/modules/chat/module.go @@ -298,7 +298,7 @@ func (this *Chat) pushChatToWorld(msg *pb.DBChat) (err error) { //推送消息到工会 func (this *Chat) pushChatToUnion(msg *pb.DBChat) (err error) { - if members := this.sociaty.Members(msg.Suid); members != nil { + if members := this.sociaty.MembersBySociatyId(msg.UnionId); members != nil { users := make([]string, 0, len(members)) for _, v := range members { if v.OfflineTime == 0 { //离线时间为0 表示在线 diff --git a/modules/sociaty/api.go b/modules/sociaty/api.go index 17c9a9942..f98c43043 100644 --- a/modules/sociaty/api.go +++ b/modules/sociaty/api.go @@ -32,6 +32,7 @@ const ( SociatySubTypeRank = "rank" SociatySubTypeTasklist = "tasklist" SociatySubTypeLog = "log" + SociatySubTypeAgreePush = "agree" ) type apiComp struct { diff --git a/modules/sociaty/api_cross_agree.go b/modules/sociaty/api_cross_agree.go index ad2cda954..3b239abe8 100644 --- a/modules/sociaty/api_cross_agree.go +++ b/modules/sociaty/api_cross_agree.go @@ -35,13 +35,19 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.SociatyAgreeReq) ( code = pb.ErrorCode_SociatyNoRight return } - + if err := this.module.modelSociaty.agree(req.Uid, sociaty); err != nil { code = pb.ErrorCode_SociatyAgree this.module.Errorf("申请同意失败:%v", err) return } + //审核通过推送 + this.module.SendMsgToUser(string(this.module.GetType()), "pagree", &pb.SociatyPAgreePush{ + Uid: uid, + SociatyId: sociaty.Id, + }, req.Uid) + rsp := &pb.SociatyAgreeResp{ Uid: req.Uid, SociatyId: sociaty.Id, diff --git a/modules/sociaty/api_cross_create.go b/modules/sociaty/api_cross_create.go index 8fe46afa7..62293ec27 100644 --- a/modules/sociaty/api_cross_create.go +++ b/modules/sociaty/api_cross_create.go @@ -13,7 +13,7 @@ import ( // 公会创建 func (this *apiComp) CreateCheck(session comm.IUserSession, req *pb.SociatyCreateReq) (code pb.ErrorCode) { - if len(req.Notice) > 150 { + if len(req.Notice) > 150 || req.Name == ""{ code = pb.ErrorCode_ReqParameterError } return diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index 104f4b320..30f827d55 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -311,8 +311,19 @@ func (this *ModelSociaty) dismiss(sociaty *pb.DBSociaty) error { if err := this.memberClear(sociaty); err != nil { return err } - err := this.DelListlds("", sociaty.Id) - return err + if err := this.DelListlds("", sociaty.Id); err != nil { + return err + } + //推送 + if err := this.moduleSociaty.SendMsgToUsers( + string(this.moduleSociaty.GetType()), + "pdismiss", + &pb.SociatyPDismissPush{SociatyId: sociaty.Id}, + this.getMemberIds(sociaty)...); err != nil { + log.Errorf("公会解散推送 err:%v", err) + } + + return nil } //删除请求记录 diff --git a/modules/sociaty/model_sociatylog.go b/modules/sociaty/model_sociatylog.go index 084409381..6bdea6312 100644 --- a/modules/sociaty/model_sociatylog.go +++ b/modules/sociaty/model_sociatylog.go @@ -144,7 +144,7 @@ func (this *ModelSociatyLog) addLog(tag Tag, sociatyId string, params ...string) } // 发消息到公会聊天 - if module, err := this.moduleSociaty.service.GetModule(comm.ModuleChat); err == nil { + if module, err := this.service.GetModule(comm.ModuleChat); err == nil { if chat, ok := module.(comm.IChat); ok { chat.SendUnionChat(&pb.DBChat{ Channel: pb.ChatChannel_Union, diff --git a/modules/sociaty/module.go b/modules/sociaty/module.go index 08e5158ce..e4b0e4c65 100644 --- a/modules/sociaty/module.go +++ b/modules/sociaty/module.go @@ -75,8 +75,14 @@ func (this *Sociaty) ProcessAccuse(uid, sociatyId string) { } } -// 公会成员 -func (this *Sociaty) Members(uid string) (list []*pb.SociatyMemberInfo) { +// 获取我的公会成员 +func (this *Sociaty) MembersByUid(uid string) (list []*pb.SociatyMemberInfo) { sociaty := this.modelSociaty.getUserSociaty(uid) return this.modelSociaty.members(sociaty) } + +// 获取公会成员 +func (this *Sociaty) MembersBySociatyId(sociatyId string) (list []*pb.SociatyMemberInfo) { + sociaty := this.modelSociaty.getSociaty(sociatyId) + return this.modelSociaty.members(sociaty) +} diff --git a/pb/sociaty_msg.pb.go b/pb/sociaty_msg.pb.go index f5397ef1c..fcfcd9ab6 100644 --- a/pb/sociaty_msg.pb.go +++ b/pb/sociaty_msg.pb.go @@ -2621,6 +2621,110 @@ func (x *SociatyRankResp) GetRank() []*DBSociatyRank { return nil } +// 公会解散推送 +type SociatyPDismissPush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + SociatyId string `protobuf:"bytes,1,opt,name=sociatyId,proto3" json:"sociatyId"` +} + +func (x *SociatyPDismissPush) Reset() { + *x = SociatyPDismissPush{} + if protoimpl.UnsafeEnabled { + mi := &file_sociaty_sociaty_msg_proto_msgTypes[51] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SociatyPDismissPush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SociatyPDismissPush) ProtoMessage() {} + +func (x *SociatyPDismissPush) ProtoReflect() protoreflect.Message { + mi := &file_sociaty_sociaty_msg_proto_msgTypes[51] + 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 SociatyPDismissPush.ProtoReflect.Descriptor instead. +func (*SociatyPDismissPush) Descriptor() ([]byte, []int) { + return file_sociaty_sociaty_msg_proto_rawDescGZIP(), []int{51} +} + +func (x *SociatyPDismissPush) GetSociatyId() string { + if x != nil { + return x.SociatyId + } + return "" +} + +// 审核通过推送 +type SociatyPAgreePush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid"` + SociatyId string `protobuf:"bytes,2,opt,name=sociatyId,proto3" json:"sociatyId"` +} + +func (x *SociatyPAgreePush) Reset() { + *x = SociatyPAgreePush{} + if protoimpl.UnsafeEnabled { + mi := &file_sociaty_sociaty_msg_proto_msgTypes[52] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SociatyPAgreePush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SociatyPAgreePush) ProtoMessage() {} + +func (x *SociatyPAgreePush) ProtoReflect() protoreflect.Message { + mi := &file_sociaty_sociaty_msg_proto_msgTypes[52] + 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 SociatyPAgreePush.ProtoReflect.Descriptor instead. +func (*SociatyPAgreePush) Descriptor() ([]byte, []int) { + return file_sociaty_sociaty_msg_proto_rawDescGZIP(), []int{52} +} + +func (x *SociatyPAgreePush) GetUid() string { + if x != nil { + return x.Uid + } + return "" +} + +func (x *SociatyPAgreePush) GetSociatyId() string { + if x != nil { + return x.SociatyId + } + return "" +} + var File_sociaty_sociaty_msg_proto protoreflect.FileDescriptor var file_sociaty_sociaty_msg_proto_rawDesc = []byte{ @@ -2810,13 +2914,20 @@ var file_sociaty_sociaty_msg_proto_rawDesc = []byte{ 0x79, 0x52, 0x61, 0x6e, 0x6b, 0x52, 0x65, 0x71, 0x22, 0x35, 0x0a, 0x0f, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x52, 0x61, 0x6e, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x53, 0x6f, - 0x63, 0x69, 0x61, 0x74, 0x79, 0x52, 0x61, 0x6e, 0x6b, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x2a, - 0x42, 0x0a, 0x11, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x69, - 0x6c, 0x74, 0x65, 0x72, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x4c, 0x4c, 0x10, 0x00, 0x12, 0x09, 0x0a, - 0x05, 0x43, 0x4f, 0x4e, 0x44, 0x49, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x4f, 0x41, 0x50, - 0x50, 0x4c, 0x59, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x50, 0x50, 0x4c, 0x59, 0x49, 0x4e, - 0x47, 0x10, 0x03, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x63, 0x69, 0x61, 0x74, 0x79, 0x52, 0x61, 0x6e, 0x6b, 0x52, 0x04, 0x72, 0x61, 0x6e, 0x6b, 0x22, + 0x33, 0x0a, 0x13, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x50, 0x44, 0x69, 0x73, 0x6d, 0x69, + 0x73, 0x73, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, + 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x6f, 0x63, 0x69, 0x61, + 0x74, 0x79, 0x49, 0x64, 0x22, 0x43, 0x0a, 0x11, 0x53, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x50, + 0x41, 0x67, 0x72, 0x65, 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x73, + 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x79, 0x49, 0x64, 0x2a, 0x42, 0x0a, 0x11, 0x53, 0x6f, 0x63, + 0x69, 0x61, 0x74, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x12, 0x07, + 0x0a, 0x03, 0x41, 0x4c, 0x4c, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x43, 0x4f, 0x4e, 0x44, 0x49, + 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x4f, 0x41, 0x50, 0x50, 0x4c, 0x59, 0x10, 0x02, 0x12, + 0x0c, 0x0a, 0x08, 0x41, 0x50, 0x50, 0x4c, 0x59, 0x49, 0x4e, 0x47, 0x10, 0x03, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2832,7 +2943,7 @@ func file_sociaty_sociaty_msg_proto_rawDescGZIP() []byte { } var file_sociaty_sociaty_msg_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_sociaty_sociaty_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 51) +var file_sociaty_sociaty_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 53) var file_sociaty_sociaty_msg_proto_goTypes = []interface{}{ (SociatyListFilter)(0), // 0: SociatyListFilter (*SociatyCreateReq)(nil), // 1: SociatyCreateReq @@ -2886,28 +2997,30 @@ var file_sociaty_sociaty_msg_proto_goTypes = []interface{}{ (*SociatyActivityReceiveResp)(nil), // 49: SociatyActivityReceiveResp (*SociatyRankReq)(nil), // 50: SociatyRankReq (*SociatyRankResp)(nil), // 51: SociatyRankResp - (*DBSociaty)(nil), // 52: DBSociaty - (SociatyJob)(0), // 53: SociatyJob - (*DBSociatyLog)(nil), // 54: DBSociatyLog - (*SociatyTask)(nil), // 55: SociatyTask - (*SociatyActivity)(nil), // 56: SociatyActivity - (*DBSociatyRank)(nil), // 57: DBSociatyRank + (*SociatyPDismissPush)(nil), // 52: SociatyPDismissPush + (*SociatyPAgreePush)(nil), // 53: SociatyPAgreePush + (*DBSociaty)(nil), // 54: DBSociaty + (SociatyJob)(0), // 55: SociatyJob + (*DBSociatyLog)(nil), // 56: DBSociatyLog + (*SociatyTask)(nil), // 57: SociatyTask + (*SociatyActivity)(nil), // 58: SociatyActivity + (*DBSociatyRank)(nil), // 59: DBSociatyRank } var file_sociaty_sociaty_msg_proto_depIdxs = []int32{ 0, // 0: SociatyListReq.filter:type_name -> SociatyListFilter - 52, // 1: SociatyListResp.list:type_name -> DBSociaty - 52, // 2: SociatySearchResp.list:type_name -> DBSociaty - 52, // 3: SociatyMineResp.sociaty:type_name -> DBSociaty + 54, // 1: SociatyListResp.list:type_name -> DBSociaty + 54, // 2: SociatySearchResp.list:type_name -> DBSociaty + 54, // 3: SociatyMineResp.sociaty:type_name -> DBSociaty 11, // 4: SociatyMineResp.master:type_name -> SociatyMemberInfo - 53, // 5: SociatyMemberInfo.job:type_name -> SociatyJob + 55, // 5: SociatyMemberInfo.job:type_name -> SociatyJob 11, // 6: SociatyApplyListResp.list:type_name -> SociatyMemberInfo 11, // 7: SociatyMembersResp.list:type_name -> SociatyMemberInfo - 53, // 8: SociatySettingJobReq.job:type_name -> SociatyJob - 53, // 9: SociatySettingJobResp.job:type_name -> SociatyJob - 54, // 10: SociatyLogResp.log:type_name -> DBSociatyLog - 55, // 11: SociatyTaskListResp.list:type_name -> SociatyTask - 56, // 12: SociatyActivityListResp.list:type_name -> SociatyActivity - 57, // 13: SociatyRankResp.rank:type_name -> DBSociatyRank + 55, // 8: SociatySettingJobReq.job:type_name -> SociatyJob + 55, // 9: SociatySettingJobResp.job:type_name -> SociatyJob + 56, // 10: SociatyLogResp.log:type_name -> DBSociatyLog + 57, // 11: SociatyTaskListResp.list:type_name -> SociatyTask + 58, // 12: SociatyActivityListResp.list:type_name -> SociatyActivity + 59, // 13: SociatyRankResp.rank:type_name -> DBSociatyRank 14, // [14:14] is the sub-list for method output_type 14, // [14:14] is the sub-list for method input_type 14, // [14:14] is the sub-list for extension type_name @@ -3534,6 +3647,30 @@ func file_sociaty_sociaty_msg_proto_init() { return nil } } + file_sociaty_sociaty_msg_proto_msgTypes[51].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SociatyPDismissPush); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_sociaty_sociaty_msg_proto_msgTypes[52].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SociatyPAgreePush); 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{ @@ -3541,7 +3678,7 @@ func file_sociaty_sociaty_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_sociaty_sociaty_msg_proto_rawDesc, NumEnums: 1, - NumMessages: 51, + NumMessages: 53, NumExtensions: 0, NumServices: 0, }, From 8a234acafe7025c6a6338e7a7960422206640430 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 4 Nov 2022 15:12:38 +0800 Subject: [PATCH 2/3] PushHeroProperty --- bin/json/game_trolltrain.json | 6 +++--- comm/imodule.go | 2 ++ modules/hero/module.go | 6 ++++++ modules/troll/api_buyorsell.go | 3 ++- modules/troll/api_getlist.go | 4 ++-- modules/troll/module.go | 4 +++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bin/json/game_trolltrain.json b/bin/json/game_trolltrain.json index d776fd32f..f0b1873b5 100644 --- a/bin/json/game_trolltrain.json +++ b/bin/json/game_trolltrain.json @@ -4,20 +4,20 @@ "name": "右屏商人", "information": "这是一位熊猫商人", "ico": "action_11001", - "time": 10 + "time": 300 }, { "id": 2, "name": "上屏商人", "information": "这是一位波比商人再此", "ico": "action_11003", - "time": 10 + "time": 300 }, { "id": 3, "name": "左屏商人", "information": "这是一位滑板鞋王子", "ico": "ytx_js_14007", - "time": 10 + "time": 300 } ] \ No newline at end of file diff --git a/comm/imodule.go b/comm/imodule.go index ab3b6ca78..9d3fcbaa3 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -61,6 +61,8 @@ type ( QueryCrossHeroinfo(oid string) (hero *pb.DBHero, err error) GetHeroListByUse(uid string) []*pb.DBHero // 非初始状态的英雄列表 + // 推送属性变化 + PushHeroProperty(session IUserSession, heros []*pb.DBHero) (err error) } //玩家 diff --git a/modules/hero/module.go b/modules/hero/module.go index 00dbaa26d..7585ae760 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -380,3 +380,9 @@ func (this *Hero) GetHeroListByUse(uid string) []*pb.DBHero { } return tmp } + +func (this *Hero) PushHeroProperty(session comm.IUserSession, heros []*pb.DBHero) (err error) { + + err = session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: heros}) + return +} diff --git a/modules/troll/api_buyorsell.go b/modules/troll/api_buyorsell.go index e365b7952..269796638 100644 --- a/modules/troll/api_buyorsell.go +++ b/modules/troll/api_buyorsell.go @@ -35,6 +35,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell return } dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) + aiMaxCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) for k, v := range req.Items { if v == 0 { // 过滤数量为0 的消息 @@ -48,7 +49,7 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.TrollBuyOrSell if !bSell { bSell = true trolltrain.SellCount += 1 // 交易次数+1 - if trolltrain.SellCount > dayMaxCount { + if trolltrain.SellCount > aiMaxCount-dayMaxCount { code = pb.ErrorCode_TrollMaxSellCount // 达到最大交易次数 直接返回 return } diff --git a/modules/troll/api_getlist.go b/modules/troll/api_getlist.go index 7841ed68f..366ac92cc 100644 --- a/modules/troll/api_getlist.go +++ b/modules/troll/api_getlist.go @@ -32,9 +32,9 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) code = pb.ErrorCode_DBError return } - + dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) aiCount := this.configure.GetTrollRule(comm.TrollAIBuyCount) - if trolltrain.AiCount <= aiCount { // 小于离线挂机次数可执行 + if trolltrain.AiCount <= aiCount-dayMaxCount { // 小于离线挂机次数可执行 this.module.TrollAI(session, trolltrain, aiCount) } diff --git a/modules/troll/module.go b/modules/troll/module.go index 68b447ad4..1b0731213 100644 --- a/modules/troll/module.go +++ b/modules/troll/module.go @@ -71,6 +71,7 @@ func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain, ai sellPrice = make(map[int32]int32) now := time.Now().Unix() trainNum := this.configure.GetTrollMaxTraintNum() + dayMaxCount := this.configure.GetTrollRule(comm.TrollBuyCount) maxCoefficient := this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 if maxCoefficient == 0 { code = pb.ErrorCode_ConfigNoFound @@ -121,7 +122,8 @@ func (this *Troll) TrollAI(session comm.IUserSession, troll *pb.DBTrollTrain, ai this.SeTrollRankList(troll.TotalEarn, session.GetUserId()) // 设置排行数据 troll.AiCount++ - if troll.AiCount > aiCount { //达到最大交易次数 + + if troll.AiCount > aiCount-dayMaxCount { //达到最大交易次数 break } } From e17afe00ecedfd91c1595b47247d47974194a996 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 4 Nov 2022 15:22:13 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9C=88=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_privilege.json | 44 +++++++ bin/json/game_privilegecard.json | 50 ++++++++ modules/privilege/api.go | 26 ++++ modules/privilege/api_getlist.go | 20 +++ modules/privilege/configure.go | 116 ++++++++++++++++++ modules/privilege/model_privilege.go | 28 +++++ modules/privilege/module.go | 44 +++++++ modules/privilege/module_test.go | 93 ++++++++++++++ sys/configure/structs/Game.Privilege.go | 42 +++++++ sys/configure/structs/Game.PrivilegeCard.go | 42 +++++++ .../structs/Game.PrivilegeCardData.go | 75 +++++++++++ sys/configure/structs/Game.PrivilegeData.go | 37 ++++++ sys/configure/structs/Tables.go | 14 +++ 13 files changed, 631 insertions(+) create mode 100644 bin/json/game_privilege.json create mode 100644 bin/json/game_privilegecard.json create mode 100644 modules/privilege/api.go create mode 100644 modules/privilege/api_getlist.go create mode 100644 modules/privilege/configure.go create mode 100644 modules/privilege/model_privilege.go create mode 100644 modules/privilege/module.go create mode 100644 modules/privilege/module_test.go create mode 100644 sys/configure/structs/Game.Privilege.go create mode 100644 sys/configure/structs/Game.PrivilegeCard.go create mode 100644 sys/configure/structs/Game.PrivilegeCardData.go create mode 100644 sys/configure/structs/Game.PrivilegeData.go diff --git a/bin/json/game_privilege.json b/bin/json/game_privilege.json new file mode 100644 index 000000000..9c3a63eeb --- /dev/null +++ b/bin/json/game_privilege.json @@ -0,0 +1,44 @@ +[ + { + "privilege_id": 10001, + "privilege_describe": { + "key": "privilegecard_10001", + "text": "特权描述1" + } + }, + { + "privilege_id": 10002, + "privilege_describe": { + "key": "privilegecard_10002", + "text": "特权描述2" + } + }, + { + "privilege_id": 10003, + "privilege_describe": { + "key": "privilegecard_10003", + "text": "特权描述3" + } + }, + { + "privilege_id": 10004, + "privilege_describe": { + "key": "privilegecard_10004", + "text": "特权描述4" + } + }, + { + "privilege_id": 10005, + "privilege_describe": { + "key": "privilegecard_10005", + "text": "特权描述5" + } + }, + { + "privilege_id": 10006, + "privilege_describe": { + "key": "privilegecard_10006", + "text": "特权描述6" + } + } +] \ No newline at end of file diff --git a/bin/json/game_privilegecard.json b/bin/json/game_privilegecard.json new file mode 100644 index 000000000..326f34822 --- /dev/null +++ b/bin/json/game_privilegecard.json @@ -0,0 +1,50 @@ +[ + { + "id": 1, + "name": "经典月卡", + "proid": "yueka_lv1", + "assert_day": 30, + "renew_day": 3, + "day_reward": [ + { + "a": "attr", + "t": "diamond", + "n": 60 + } + ], + "disposable_reward": { + "a": "attr", + "t": "diamond", + "n": 300 + }, + "privilege_id": [ + 10001, + 10002, + 10003 + ] + }, + { + "id": 2, + "name": "典藏月卡", + "proid": "yueka_lv2", + "assert_day": 30, + "renew_day": 3, + "day_reward": [ + { + "a": "attr", + "t": "diamond", + "n": 90 + } + ], + "disposable_reward": { + "a": "attr", + "t": "diamond", + "n": 980 + }, + "privilege_id": [ + 10004, + 10005, + 10006 + ] + } +] \ No newline at end of file diff --git a/modules/privilege/api.go b/modules/privilege/api.go new file mode 100644 index 000000000..35949af67 --- /dev/null +++ b/modules/privilege/api.go @@ -0,0 +1,26 @@ +package privilege + +import ( + "go_dreamfactory/modules" + + "go_dreamfactory/lego/core" +) + +type apiComp struct { + modules.MCompGate + service core.IService + module *Privilege +} + +//组件初始化接口 +func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MCompGate.Init(service, module, comp, options) + this.module = module.(*Privilege) + this.service = service + return +} + +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() + return +} diff --git a/modules/privilege/api_getlist.go b/modules/privilege/api_getlist.go new file mode 100644 index 000000000..ed54c70fa --- /dev/null +++ b/modules/privilege/api_getlist.go @@ -0,0 +1,20 @@ +package privilege + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) GetlistCheck(session comm.IUserSession, req *pb.ShopGetListReq) (code pb.ErrorCode) { + + return +} + +///获取特权列表 +func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ShopGetListReq) (code pb.ErrorCode, data proto.Message) { + + return +} diff --git a/modules/privilege/configure.go b/modules/privilege/configure.go new file mode 100644 index 000000000..bed2b3097 --- /dev/null +++ b/modules/privilege/configure.go @@ -0,0 +1,116 @@ +package privilege + +import ( + "fmt" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" +) + +const ( + game_shop = "game_shop.json" + game_shopitem = "game_shopitem.json" +) + +///背包配置管理组件 +type configureComp struct { + modules.MCompConfigure + module *Privilege +} + +//组件初始化接口 +func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MCompConfigure.Init(service, module, comp, options) + this.module = module.(*Privilege) + this.LoadConfigure(game_shop, cfg.NewGameShop) + this.LoadConfigure(game_shopitem, cfg.NewGameShopitem) + return +} + +//获取装备配置数据 +func (this *configureComp) GetShopConfigure(id int32) (configure *cfg.GameShopData, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_shop); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + if configure, ok = v.(*cfg.GameShop).GetDataMap()[id]; !ok { + err = fmt.Errorf("ShopConfigure not found:%d ", id) + this.module.Errorf("err:%v", err) + return + } + } + return +} + +//读取商品 +func (this *configureComp) GetShopItemsConfigure(key int32) (result *cfg.GameShopitemData, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_shopitem); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + if result, ok = v.(*cfg.GameShopitem).GetDataMap()[key]; !ok { + err = fmt.Errorf("ShopConfigure not found:%d ", key) + this.module.Errorf("err:%v", err) + return + } + } + return +} + +//读取商品组 +func (this *configureComp) GetShopItemsConfigureByGroups(groupid int32, user *pb.DBUser) (result []*cfg.GameShopitemData, err error) { + result = make([]*cfg.GameShopitemData, 0, 10) + var ( + v interface{} + table *cfg.GameShopitem + ) + if v, err = this.GetConfigure(game_shopitem); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + table = v.(*cfg.GameShopitem) + for _, v := range table.GetDataMap() { + if v.Id == groupid && + user.Lv >= v.Lvmin && + user.Lv <= v.Lvmax && + user.Vip >= v.Vip { + result = append(result, v) + } + } + } + return +} + +//读取商品 +func (this *configureComp) GetShopItemsConfigureByIds(keys ...int32) (result []*cfg.GameShopitemData, err error) { + result = make([]*cfg.GameShopitemData, 0, len(keys)) + var ( + v interface{} + table *cfg.GameShopitem + item *cfg.GameShopitemData + ok bool + ) + if v, err = this.GetConfigure(game_shopitem); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + table = v.(*cfg.GameShopitem) + for _, v := range keys { + if item, ok = table.GetDataMap()[v]; ok { + result = append(result, item) + } else { + this.module.Errorf("no found GetShopItemsConfigureByIds:%d", v) + } + } + } + return +} diff --git a/modules/privilege/model_privilege.go b/modules/privilege/model_privilege.go new file mode 100644 index 000000000..747b8322e --- /dev/null +++ b/modules/privilege/model_privilege.go @@ -0,0 +1,28 @@ +package privilege + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" +) + +///论坛 数据组件 +type modelShopComp struct { + modules.MCompModel + module *Privilege +} + +//组件初始化接口 +func (this *modelShopComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) { + this.MCompModel.Init(service, module, comp, opt) + this.module = module.(*Privilege) + this.TableName = comm.TableShop + //创建uid索引 + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return +} diff --git a/modules/privilege/module.go b/modules/privilege/module.go new file mode 100644 index 000000000..a431ef16a --- /dev/null +++ b/modules/privilege/module.go @@ -0,0 +1,44 @@ +package privilege + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/modules" + "go_dreamfactory/sys/db" +) + +func NewModule() core.IModule { + m := new(Privilege) + return m +} + +type Privilege struct { + modules.ModuleBase + api_comp *apiComp + configure *configureComp + modelShop *modelShopComp +} + +//模块名 +func (this *Privilege) GetType() core.M_Modules { + return comm.ModuleShop +} + +//模块初始化接口 注册用户创建角色事件 +func (this *Privilege) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { + err = this.ModuleBase.Init(service, module, options) + return +} + +//装备组件 +func (this *Privilege) OnInstallComp() { + this.ModuleBase.OnInstallComp() + this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp) + this.modelShop = this.RegisterComp(new(modelShopComp)).(*modelShopComp) + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) +} + +//Event------------------------------------------------------------------------------------------------------------ +func (this *Privilege) EventUserOffline(session comm.IUserSession) { + this.modelShop.DelByUId(session.GetUserId(), db.SetDBMgoLog(false)) +} diff --git a/modules/privilege/module_test.go b/modules/privilege/module_test.go new file mode 100644 index 000000000..25243d3cf --- /dev/null +++ b/modules/privilege/module_test.go @@ -0,0 +1,93 @@ +package privilege_test + +import ( + "context" + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/lego" + "go_dreamfactory/lego/base/rpcx" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules/equipment" + "go_dreamfactory/modules/hero" + "go_dreamfactory/modules/items" + "go_dreamfactory/modules/shop" + "go_dreamfactory/modules/user" + "go_dreamfactory/pb" + "go_dreamfactory/services" + "go_dreamfactory/sys/configure" + "go_dreamfactory/sys/db" + "os" + "testing" + "time" + + "github.com/golang/protobuf/ptypes" +) + +func newService(ops ...rpcx.Option) core.IService { + s := new(TestService) + s.Configure(ops...) + return s +} + +//梦工厂基础服务对象 +type TestService struct { + rpcx.RPCXService +} + +//初始化相关系统 +func (this *TestService) InitSys() { + this.RPCXService.InitSys() + if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil { + panic(fmt.Sprintf("init sys.db err: %s", err.Error())) + } else { + log.Infof("init sys.db success!") + } + if err := configure.OnInit(this.GetSettings().Sys["configure"], configure.SetConfigPath("F:/work/go/go_dreamfactory/bin/json")); err != nil { + panic(fmt.Sprintf("init sys.configure err: %s", err.Error())) + } else { + log.Infof("init sys.configure success!") + } +} + +var service core.IService +var s_gateComp comm.ISC_GateRouteComp = services.NewGateRouteComp() +var module = new(shop.Shop) + +//测试环境下初始化db和cache 系统 +func TestMain(m *testing.M) { + service = newService( + rpcx.SetConfPath("../../bin/conf/worker_1.yaml"), + rpcx.SetVersion("1.0.0.0"), + ) + service.OnInstallComp( //装备组件 + s_gateComp, //此服务需要接受用户的消息 需要装备网关组件 + ) + go func() { + lego.Run(service, //运行模块 + module, + hero.NewModule(), + user.NewModule(), + items.NewModule(), + equipment.NewModule(), + ) + }() + time.Sleep(time.Second * 3) + defer os.Exit(m.Run()) +} + +//测试api_getlist +func Test_Module_APIGetList(t *testing.T) { + data, _ := ptypes.MarshalAny(&pb.ShopGetListReq{SType: pb.ShopType_GoldShop, IsManualRefresh: false}) + reply := &pb.RPCMessageReply{} + s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62b16dda909b2f8faeff788d", MainType: "shop", SubType: "getlist", Message: data}, reply) + log.Debugf("reply:%v", reply) +} + +//测试api_buy +func Test_Module_APIBuy(t *testing.T) { + data, _ := ptypes.MarshalAny(&pb.ShopBuyReq{GoodsId: 7}) + reply := &pb.RPCMessageReply{} + s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62b16dda909b2f8faeff788d", MainType: "shop", SubType: "buy", Message: data}, reply) + log.Debugf("reply:%v", reply) +} diff --git a/sys/configure/structs/Game.Privilege.go b/sys/configure/structs/Game.Privilege.go new file mode 100644 index 000000000..a1826b03c --- /dev/null +++ b/sys/configure/structs/Game.Privilege.go @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +type GamePrivilege struct { + _dataMap map[int32]*GamePrivilegeData + _dataList []*GamePrivilegeData +} + +func NewGamePrivilege(_buf []map[string]interface{}) (*GamePrivilege, error) { + _dataList := make([]*GamePrivilegeData, 0, len(_buf)) + dataMap := make(map[int32]*GamePrivilegeData) + for _, _ele_ := range _buf { + if _v, err2 := DeserializeGamePrivilegeData(_ele_); err2 != nil { + return nil, err2 + } else { + _dataList = append(_dataList, _v) + dataMap[_v.PrivilegeId] = _v + } + } + return &GamePrivilege{_dataList:_dataList, _dataMap:dataMap}, nil +} + +func (table *GamePrivilege) GetDataMap() map[int32]*GamePrivilegeData { + return table._dataMap +} + +func (table *GamePrivilege) GetDataList() []*GamePrivilegeData { + return table._dataList +} + +func (table *GamePrivilege) Get(key int32) *GamePrivilegeData { + return table._dataMap[key] +} + + diff --git a/sys/configure/structs/Game.PrivilegeCard.go b/sys/configure/structs/Game.PrivilegeCard.go new file mode 100644 index 000000000..e90f6b648 --- /dev/null +++ b/sys/configure/structs/Game.PrivilegeCard.go @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +type GamePrivilegeCard struct { + _dataMap map[int32]*GamePrivilegeCardData + _dataList []*GamePrivilegeCardData +} + +func NewGamePrivilegeCard(_buf []map[string]interface{}) (*GamePrivilegeCard, error) { + _dataList := make([]*GamePrivilegeCardData, 0, len(_buf)) + dataMap := make(map[int32]*GamePrivilegeCardData) + for _, _ele_ := range _buf { + if _v, err2 := DeserializeGamePrivilegeCardData(_ele_); err2 != nil { + return nil, err2 + } else { + _dataList = append(_dataList, _v) + dataMap[_v.Id] = _v + } + } + return &GamePrivilegeCard{_dataList:_dataList, _dataMap:dataMap}, nil +} + +func (table *GamePrivilegeCard) GetDataMap() map[int32]*GamePrivilegeCardData { + return table._dataMap +} + +func (table *GamePrivilegeCard) GetDataList() []*GamePrivilegeCardData { + return table._dataList +} + +func (table *GamePrivilegeCard) Get(key int32) *GamePrivilegeCardData { + return table._dataMap[key] +} + + diff --git a/sys/configure/structs/Game.PrivilegeCardData.go b/sys/configure/structs/Game.PrivilegeCardData.go new file mode 100644 index 000000000..e6d96ca5d --- /dev/null +++ b/sys/configure/structs/Game.PrivilegeCardData.go @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +import "errors" + +type GamePrivilegeCardData struct { + Id int32 + Name string + Proid string + AssertDay int32 + RenewDay int32 + DayReward []*Gameatn + DisposableReward *Gameatn + PrivilegeId []int32 +} + +const TypeId_GamePrivilegeCardData = 1735553455 + +func (*GamePrivilegeCardData) GetTypeId() int32 { + return 1735553455 +} + +func (_v *GamePrivilegeCardData)Deserialize(_buf map[string]interface{}) (err error) { + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["id"].(float64); !_ok_ { err = errors.New("id error"); return }; _v.Id = int32(_tempNum_) } + { var _ok_ bool; if _v.Name, _ok_ = _buf["name"].(string); !_ok_ { err = errors.New("name error"); return } } + { var _ok_ bool; if _v.Proid, _ok_ = _buf["proid"].(string); !_ok_ { err = errors.New("proid error"); return } } + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["assert_day"].(float64); !_ok_ { err = errors.New("assert_day error"); return }; _v.AssertDay = int32(_tempNum_) } + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["renew_day"].(float64); !_ok_ { err = errors.New("renew_day error"); return }; _v.RenewDay = int32(_tempNum_) } + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["day_reward"].([]interface{}); !_ok_ { err = errors.New("day_reward error"); return } + + _v.DayReward = make([]*Gameatn, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ *Gameatn + { var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = DeserializeGameatn(_x_); err != nil { return } } + _v.DayReward = append(_v.DayReward, _list_v_) + } + } + + { var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _buf["disposable_reward"].(map[string]interface{}); !_ok_ { err = errors.New("disposable_reward error"); return }; if _v.DisposableReward, err = DeserializeGameatn(_x_); err != nil { return } } + { + var _arr_ []interface{} + var _ok_ bool + if _arr_, _ok_ = _buf["privilege_id"].([]interface{}); !_ok_ { err = errors.New("privilege_id error"); return } + + _v.PrivilegeId = make([]int32, 0, len(_arr_)) + + for _, _e_ := range _arr_ { + var _list_v_ int32 + { var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) } + _v.PrivilegeId = append(_v.PrivilegeId, _list_v_) + } + } + + return +} + +func DeserializeGamePrivilegeCardData(_buf map[string]interface{}) (*GamePrivilegeCardData, error) { + v := &GamePrivilegeCardData{} + if err := v.Deserialize(_buf); err == nil { + return v, nil + } else { + return nil, err + } +} diff --git a/sys/configure/structs/Game.PrivilegeData.go b/sys/configure/structs/Game.PrivilegeData.go new file mode 100644 index 000000000..cfbc9f5a4 --- /dev/null +++ b/sys/configure/structs/Game.PrivilegeData.go @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +package cfg + +import "errors" + +type GamePrivilegeData struct { + PrivilegeId int32 + PrivilegeDescribe string +} + +const TypeId_GamePrivilegeData = 40320255 + +func (*GamePrivilegeData) GetTypeId() int32 { + return 40320255 +} + +func (_v *GamePrivilegeData)Deserialize(_buf map[string]interface{}) (err error) { + { var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["privilege_id"].(float64); !_ok_ { err = errors.New("privilege_id error"); return }; _v.PrivilegeId = int32(_tempNum_) } + {var _ok_ bool; var __json_text__ map[string]interface{}; if __json_text__, _ok_ = _buf["privilege_describe"].(map[string]interface{}) ; !_ok_ { err = errors.New("_v.PrivilegeDescribe error"); return }; { var _ok_ bool; if _, _ok_ = __json_text__["key"].(string); !_ok_ { err = errors.New("key error"); return } }; { var _ok_ bool; if _v.PrivilegeDescribe, _ok_ = __json_text__["text"].(string); !_ok_ { err = errors.New("text error"); return } } } + return +} + +func DeserializeGamePrivilegeData(_buf map[string]interface{}) (*GamePrivilegeData, error) { + v := &GamePrivilegeData{} + if err := v.Deserialize(_buf); err == nil { + return v, nil + } else { + return nil, err + } +} diff --git a/sys/configure/structs/Tables.go b/sys/configure/structs/Tables.go index 0e98b2430..869ecc258 100644 --- a/sys/configure/structs/Tables.go +++ b/sys/configure/structs/Tables.go @@ -120,6 +120,8 @@ type Tables struct { TrollTrain *GameTrollTrain TrollLv *GameTrollLv TrollCoefficient *GameTrollCoefficient + PrivilegeCard *GamePrivilegeCard + Privilege *GamePrivilege } func NewTables(loader JsonLoader) (*Tables, error) { @@ -781,5 +783,17 @@ func NewTables(loader JsonLoader) (*Tables, error) { if tables.TrollCoefficient, err = NewGameTrollCoefficient(buf); err != nil { return nil, err } + if buf, err = loader("game_privilegecard"); err != nil { + return nil, err + } + if tables.PrivilegeCard, err = NewGamePrivilegeCard(buf); err != nil { + return nil, err + } + if buf, err = loader("game_privilege"); err != nil { + return nil, err + } + if tables.Privilege, err = NewGamePrivilege(buf); err != nil { + return nil, err + } return tables, nil }