158 lines
3.9 KiB
Go
158 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 (
|
|
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
|
|
}
|