155 lines
3.9 KiB
Go
155 lines
3.9 KiB
Go
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 (
|
|
QueryUserMailReq = "mail.queryusermailreq"
|
|
QueryUserMailResp = "mail.queryusermailresp"
|
|
ReadUserMailReq = "mail.readusermailreq"
|
|
ReadUserMailResp = "mail.readusermailresp"
|
|
GetUserMailAttachmentReq = "mail.getusermailattachmentreq"
|
|
GetUserMailAttachmentResp = "mail.getusermailattachmentresp"
|
|
DelUserMailReq = "mail.delusermailreq"
|
|
DelUserMailResp = "mail.delusermailresp"
|
|
GetNewEMailResp = "mail.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("mail", "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.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.GetMailAttachmentState(req.ObjID)
|
|
if !_bGet {
|
|
code = pb.ErrorCode_StateInvalid
|
|
return
|
|
}
|
|
_data, err := db.Defsys.GetMailAttachment(req.ObjID)
|
|
if err != nil {
|
|
if len(_data) > 0 {
|
|
// todo 领取附件
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
// 修改状态
|
|
db.Defsys.UpdateMailAttachmentState(req.ObjID)
|
|
mail.Reward = true
|
|
|
|
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.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
|
|
}
|