From 5a94516649e0f2e45cdcfca0de46f14d7e149ba6 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 9 Jun 2022 14:08:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=8B=86=E5=88=86=20?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/mail/api.go | 42 ++++++++ modules/mail/api_comp.go | 157 ------------------------------ modules/mail/api_delmail.go | 35 +++++++ modules/mail/api_getAttachment.go | 49 ++++++++++ modules/mail/api_getmail.go | 30 ++++++ modules/mail/api_readmail.go | 30 ++++++ 6 files changed, 186 insertions(+), 157 deletions(-) create mode 100644 modules/mail/api.go delete mode 100644 modules/mail/api_comp.go create mode 100644 modules/mail/api_delmail.go create mode 100644 modules/mail/api_getAttachment.go create mode 100644 modules/mail/api_getmail.go create mode 100644 modules/mail/api_readmail.go diff --git a/modules/mail/api.go b/modules/mail/api.go new file mode 100644 index 000000000..fc54b31de --- /dev/null +++ b/modules/mail/api.go @@ -0,0 +1,42 @@ +package mail + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/modules" + + "go_dreamfactory/lego/core" +) + +const ( + QueryUserMailResp = "queryusermailresp" + ReadUserMailResp = "readusermailresp" + GetUserMailAttachmentResp = "getusermailattachmentresp" + DelUserMailResp = "delusermailresp" + GetNewEMailResp = "getnewEmailresp" +) + +type Api_Comp struct { + modules.MComp_GateComp + service core.IService + module *Mail + pack comm.IPack +} + +func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + this.MComp_GateComp.Init(service, module, comp, options) + this.service = service + this.module = module.(*Mail) + return +} + +func (this *Api_Comp) Start() (err error) { + err = this.MComp_GateComp.Start() + var module core.IModule + + if module, err = this.service.GetModule(comm.SM_PackModule); err != nil { + return + } + this.pack = module.(comm.IPack) + + return +} diff --git a/modules/mail/api_comp.go b/modules/mail/api_comp.go deleted file mode 100644 index 27c70b7bb..000000000 --- a/modules/mail/api_comp.go +++ /dev/null @@ -1,157 +0,0 @@ -package mail - -import ( - "context" - "go_dreamfactory/comm" - "go_dreamfactory/modules" - "go_dreamfactory/pb" - "go_dreamfactory/sys/cache" - "go_dreamfactory/sys/db" - - "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/log" -) - -const ( - QueryUserMailResp = "queryusermailresp" - ReadUserMailResp = "readusermailresp" - GetUserMailAttachmentResp = "getusermailattachmentresp" - DelUserMailResp = "delusermailresp" - GetNewEMailResp = "getnewEmailresp" -) - -type Api_Comp struct { - modules.MComp_GateComp - service core.IService - module *Mail - pack comm.IPack -} - -func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.MComp_GateComp.Init(service, module, comp, options) - this.service = service - this.module = module.(*Mail) - return -} - -func (this *Api_Comp) Start() (err error) { - err = this.MComp_GateComp.Start() - var module core.IModule - - if module, err = this.service.GetModule(comm.SM_PackModule); err != nil { - return - } - this.pack = module.(comm.IPack) - - return -} - -// 查看所有邮件信息 -func (this *Api_Comp) QueryUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserMailReq) (err error) { - - code := pb.ErrorCode_Success - mailinfo := make([]*pb.DB_MailData, 0) - defer func() { - session.SendMsg(string(this.module.GetType()), QueryUserMailResp, code, &pb.QueryUserMailResp{Mails: mailinfo}) - }() - if session.GetUserId() == "" { - code = pb.ErrorCode_NoLogin - return - } - if mailinfo, err = cache.Defsys.QueryUserMail(session.GetUserId()); err != nil { - log.Errorf("QueryUserMailResp err:%v", err) - code = pb.ErrorCode_CacheReadError - return - } - - return -} - -// 查看某一封邮件 -func (this *Api_Comp) ReadUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.ReadUserMailReq) (err error) { - var ( - code pb.ErrorCode - mail *pb.DB_MailData - ) - defer func() { - session.SendMsg(string(this.module.GetType()), ReadUserMailResp, code, &pb.ReadUserMailResp{Mail: mail}) - }() - if session.GetUserId() == "" { - code = pb.ErrorCode_NoLogin - return - } - - mail, err = db.Defsys.Mail_ReadOneMail(req.ObjID) - if err != nil { - code = pb.ErrorCode_ReqParameterError - } - - return -} - -// 领取附件 -func (this *Api_Comp) GetUserMailAttachmentReq(ctx context.Context, session comm.IUserSession, req *pb.GetUserMailAttachmentReq) (err error) { - - var ( - code pb.ErrorCode - mail *pb.DB_MailData - ) - defer func() { - session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, code, &pb.GetUserMailAttachmentResp{Mail: mail}) - }() - if session.GetUserId() == "" { - code = pb.ErrorCode_NoLogin - return - } - _bGet := db.Defsys.Mail_GetMailAttachmentState(req.ObjID) - if !_bGet { - code = pb.ErrorCode_StateInvalid - return - } - _data, err := db.Defsys.Mail_GetMailAttachment(req.ObjID) - if err != nil { - if len(_data) > 0 { - // todo 领取附件 - _items := make(map[uint32]uint32, 0) - for _, v := range _data { - _items[v.ItemId] += v.ItemCount - } - // bRet := this.pack.GetRewaredItems(mail.UserId, _items) - // if bRet { - // // 修改状态 - // db.Defsys.Mail_UpdateMailAttachmentState(req.ObjID) - // mail.Reward = true - // return - // } - } - code = pb.ErrorCode_SystemError - } - - return -} - -// 删除邮件 -func (this *Api_Comp) DelUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.DelUserMailReq) (err error) { - - code := pb.ErrorCode_Success - mailinfo := make([]*pb.DB_MailData, 0) - defer func() { - session.SendMsg(string(this.module.GetType()), DelUserMailResp, code, &pb.DelUserMailResp{Mail: mailinfo}) - }() - if session.GetUserId() == "" { - code = pb.ErrorCode_NoLogin - return - } - bRet := db.Defsys.Mail_DelUserMail(req.ObjID) - if !bRet { - code = pb.ErrorCode_DBError - return - } - if mailinfo, err = cache.Defsys.QueryUserMail(session.GetUserId()); err != nil { - log.Errorf("QueryUserMailResp err:%v", err) - code = pb.ErrorCode_CacheReadError - return - } - - return -} diff --git a/modules/mail/api_delmail.go b/modules/mail/api_delmail.go new file mode 100644 index 000000000..98a47a96e --- /dev/null +++ b/modules/mail/api_delmail.go @@ -0,0 +1,35 @@ +package mail + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" +) + +// 删除邮件 +func (this *Api_Comp) DelUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.DelUserMailReq) (err error) { + + code := pb.ErrorCode_Success + mailinfo := make([]*pb.DB_MailData, 0) + defer func() { + session.SendMsg(string(this.module.GetType()), DelUserMailResp, code, &pb.DelUserMailResp{Mail: mailinfo}) + }() + if session.GetUserId() == "" { + code = pb.ErrorCode_NoLogin + return + } + bRet := db.Defsys.Mail_DelUserMail(req.ObjID) + if !bRet { + code = pb.ErrorCode_DBError + return + } + if mailinfo, err = db.Defsys.Mail_QueryUserMail(session.GetUserId()); err != nil { + log.Errorf("QueryUserMailResp err:%v", err) + code = pb.ErrorCode_CacheReadError + return + } + + return +} diff --git a/modules/mail/api_getAttachment.go b/modules/mail/api_getAttachment.go new file mode 100644 index 000000000..68d2ed57b --- /dev/null +++ b/modules/mail/api_getAttachment.go @@ -0,0 +1,49 @@ +package mail + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" +) + +// 领取附件 +func (this *Api_Comp) GetUserMailAttachmentReq(ctx context.Context, session comm.IUserSession, req *pb.GetUserMailAttachmentReq) (err error) { + + var ( + code pb.ErrorCode + mail *pb.DB_MailData + ) + defer func() { + session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, code, &pb.GetUserMailAttachmentResp{Mail: mail}) + }() + if session.GetUserId() == "" { + code = pb.ErrorCode_NoLogin + return + } + _bGet := db.Defsys.Mail_GetMailAttachmentState(req.ObjID) + if !_bGet { + code = pb.ErrorCode_StateInvalid + return + } + _data, err := db.Defsys.Mail_GetMailAttachment(req.ObjID) + if err != nil { + if len(_data) > 0 { + // todo 领取附件 + _items := make(map[int32]int32, 0) + for _, v := range _data { + _items[int32(v.ItemId)] += int32(v.ItemCount) + } + bRet := this.pack.AddItemsToUserPack(mail.UserId, _items) + if bRet != nil { + // 修改状态 + db.Defsys.Mail_UpdateMailAttachmentState(req.ObjID) + mail.Reward = true + return + } + } + code = pb.ErrorCode_SystemError + } + + return +} diff --git a/modules/mail/api_getmail.go b/modules/mail/api_getmail.go new file mode 100644 index 000000000..673682c37 --- /dev/null +++ b/modules/mail/api_getmail.go @@ -0,0 +1,30 @@ +package mail + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" +) + +// 查看所有邮件信息 +func (this *Api_Comp) QueryUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserMailReq) (err error) { + + code := pb.ErrorCode_Success + mailinfo := make([]*pb.DB_MailData, 0) + defer func() { + session.SendMsg(string(this.module.GetType()), QueryUserMailResp, code, &pb.QueryUserMailResp{Mails: mailinfo}) + }() + if session.GetUserId() == "" { + code = pb.ErrorCode_NoLogin + return + } + if mailinfo, err = db.Defsys.Mail_QueryUserMail(session.GetUserId()); err != nil { + log.Errorf("QueryUserMailResp err:%v", err) + code = pb.ErrorCode_CacheReadError + return + } + + return +} diff --git a/modules/mail/api_readmail.go b/modules/mail/api_readmail.go new file mode 100644 index 000000000..d83db2499 --- /dev/null +++ b/modules/mail/api_readmail.go @@ -0,0 +1,30 @@ +package mail + +import ( + "context" + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" +) + +// 查看某一封邮件 +func (this *Api_Comp) ReadUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.ReadUserMailReq) (err error) { + var ( + code pb.ErrorCode + mail *pb.DB_MailData + ) + defer func() { + session.SendMsg(string(this.module.GetType()), ReadUserMailResp, code, &pb.ReadUserMailResp{Mail: mail}) + }() + if session.GetUserId() == "" { + code = pb.ErrorCode_NoLogin + return + } + + mail, err = db.Defsys.Mail_ReadOneMail(req.ObjID) + if err != nil { + code = pb.ErrorCode_ReqParameterError + } + + return +}