go_dreamfactory/modules/mail/api_getAttachment.go

131 lines
3.5 KiB
Go

package mail
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
)
func (this *apiComp) GetUserMailAttachmentCheck(session comm.IUserSession, req *pb.MailGetUserMailAttachmentReq) (errdata *pb.ErrorData) {
if req.ObjID == "" {
errdata = &pb.ErrorData{ // 邮件不存在
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
}
return
}
// 领取附件
func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.MailGetUserMailAttachmentReq) (errdata *pb.ErrorData) {
res := make([]*cfg.Gameatn, 0)
if errdata = this.GetUserMailAttachmentCheck(session, req); errdata != nil {
return
}
mail, err := this.module.modelMail.MailGetMailAttachmentState(req.ObjID)
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_MailErr,
Title: pb.ErrorCode_MailErr.ToString(),
Message: err.Error(),
}
return
}
if mail.Reward || len(mail.GetItems()) == 0 || mail.Uid != session.GetUserId() {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_StateInvalid,
Title: pb.ErrorCode_StateInvalid.ToString(),
}
return
}
if _data, err := this.module.modelMail.MailGetMailAttachment(req.ObjID); err == nil {
if len(_data) > 0 {
for _, v := range _data {
d := &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N,
}
res = append(res, d)
}
if errdata = this.module.DispenseRes(session, res, true); errdata == nil {
// 修改状态
this.module.modelMail.MailUpdateMailAttachmentState(req.ObjID)
mail.Reward = true
mail.Check = true
}
}
}
session.SendMsg(string(this.module.GetType()), "getusermailattachment", &pb.MailGetUserMailAttachmentResp{Mail: mail})
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "MailGetUserMailAttachmentReq", res)
})
return
}
func (this *apiComp) GetAllMailAttachmentCheck(session comm.IUserSession, req *pb.MailGetAllMailAttachmentReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) GetAllMailAttachment(session comm.IUserSession, req *pb.MailGetAllMailAttachmentReq) (errdata *pb.ErrorData) {
var (
mailIds []string
atno []*pb.UserAtno
res []*cfg.Gameatn
)
if errdata = this.GetAllMailAttachmentCheck(session, req); errdata != nil {
return
}
mails, err := this.module.modelMail.MailQueryUserMailByReard(session.GetUserId())
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_MailErr,
Title: pb.ErrorCode_MailErr.ToString(),
Message: err.Error(),
}
return
}
if len(mails) == 0 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_MailErr,
Title: pb.ErrorCode_MailErr.ToString(),
}
return
}
for _, v := range mails {
bok := false
for _, v1 := range v.Items {
d := &cfg.Gameatn{
A: v1.A,
T: v1.T,
N: v1.N,
}
res = append(res, d)
bok = true
}
if bok {
v.Reward = true
v.Check = true
mailIds = append(mailIds, v.ObjId)
}
}
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
return
}
this.module.modelMail.MailGetAttachmentMail(mailIds)
session.SendMsg(string(this.module.GetType()), "getallmailattachment", &pb.MailGetAllMailAttachmentResp{
Reward: atno,
Ids: mailIds,
})
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "MailGetAllMailAttachmentReq", atno)
})
return
}