go_dreamfactory/modules/mail/api_getAttachment.go

61 lines
1.5 KiB
Go

package mail
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
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 proto.Message) {
var (
mail *pb.DBMailData
)
defer func() {
session.SendMsg(string(this.module.GetType()), GetUserMailAttachmentResp, &pb.MailGetUserMailAttachmentResp{Mail: mail})
}()
code = this.GetUserMailAttachmentCheck(session, req) // check
if code != pb.ErrorCode_Success {
return
}
_bGet := this.module.modelMail.Mail_GetMailAttachmentState(req.ObjID)
if !_bGet {
code = pb.ErrorCode_StateInvalid
return
}
_data, err := this.module.modelMail.Mail_GetMailAttachment(req.ObjID)
if err == nil {
if len(_data) > 0 {
res := make([]*cfg.Game_atn, 0)
for _, v := range _data {
d := &cfg.Game_atn{
A: v.A,
T: v.T,
N: v.N,
}
res = append(res, d)
}
code = this.module.api.module.CheckConsumeRes(session.GetUserId(), res) // 领取附件
if code == pb.ErrorCode_Success {
// 修改状态
this.module.modelMail.Mail_UpdateMailAttachmentState(req.ObjID)
mail.Reward = true
return
}
}
}
code = pb.ErrorCode_SystemError
return
}