接口拆分 分类
This commit is contained in:
parent
b9672e0682
commit
5a94516649
42
modules/mail/api.go
Normal file
42
modules/mail/api.go
Normal file
@ -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
|
||||||
|
}
|
@ -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
|
|
||||||
}
|
|
35
modules/mail/api_delmail.go
Normal file
35
modules/mail/api_delmail.go
Normal file
@ -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
|
||||||
|
}
|
49
modules/mail/api_getAttachment.go
Normal file
49
modules/mail/api_getAttachment.go
Normal file
@ -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
|
||||||
|
}
|
30
modules/mail/api_getmail.go
Normal file
30
modules/mail/api_getmail.go
Normal file
@ -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
|
||||||
|
}
|
30
modules/mail/api_readmail.go
Normal file
30
modules/mail/api_readmail.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user