go_dreamfactory/modules/mail/api_getAttachment.go
2023-04-14 14:18:05 +08:00

104 lines
2.7 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) (code pb.ErrorCode) {
if req.ObjID == "" {
return pb.ErrorCode_ReqParameterError
}
return
}
// 领取附件
func (this *apiComp) GetUserMailAttachment(session comm.IUserSession, req *pb.MailGetUserMailAttachmentReq) (code pb.ErrorCode, data *pb.ErrorData) {
code = this.GetUserMailAttachmentCheck(session, req) // check
if code != pb.ErrorCode_Success {
return
}
mail, err := this.module.modelMail.MailGetMailAttachmentState(req.ObjID)
if err != nil {
code = pb.ErrorCode_MailErr
return
}
if mail.Reward || len(mail.GetItems()) == 0 || mail.Uid != session.GetUserId() {
code = pb.ErrorCode_StateInvalid
return
}
if _data, err := this.module.modelMail.MailGetMailAttachment(req.ObjID); err == nil {
if len(_data) > 0 {
res := make([]*cfg.Gameatn, 0)
for _, v := range _data {
d := &cfg.Gameatn{
A: v.A,
T: v.T,
N: v.N,
}
res = append(res, d)
}
if code = this.module.DispenseRes(session, res, true); code == pb.ErrorCode_Success {
// 修改状态
this.module.modelMail.MailUpdateMailAttachmentState(req.ObjID)
mail.Reward = true
mail.Check = true
}
}
}
session.SendMsg(string(this.module.GetType()), "getusermailattachment", &pb.MailGetUserMailAttachmentResp{Mail: mail})
return
}
func (this *apiComp) GetAllMailAttachmentCheck(session comm.IUserSession, req *pb.MailGetAllMailAttachmentReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) GetAllMailAttachment(session comm.IUserSession, req *pb.MailGetAllMailAttachmentReq) (code pb.ErrorCode, data *pb.ErrorData) {
var (
mailIds []string
)
code = this.GetAllMailAttachmentCheck(session, req) // check
if code != pb.ErrorCode_Success {
return
}
mails, err := this.module.modelMail.MailQueryUserMailByReard(session.GetUserId())
if err != nil {
code = pb.ErrorCode_MailErr
return
}
if len(mails) == 0 {
code = pb.ErrorCode_MailErr
return
}
fj := make([]*pb.UserAssets, 0)
for _, v := range mails {
res := make([]*cfg.Gameatn, 0)
for _, v1 := range v.Items {
d := &cfg.Gameatn{
A: v1.A,
T: v1.T,
N: v1.N,
}
fj = append(fj, v1)
res = append(res, d)
}
if code = this.module.DispenseRes(session, res, true); code == pb.ErrorCode_Success {
this.module.modelMail.MailUpdateMailAttachmentState(v.ObjId)
v.Reward = true
v.Check = true
mailIds = append(mailIds, v.ObjId)
}
}
session.SendMsg(string(this.module.GetType()), "getallmailattachment", &pb.MailGetAllMailAttachmentResp{Res: fj,
Ids: mailIds})
return
}