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) { 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 } _data, err := this.module.modelMail.MailGetMailAttachment(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.DispenseRes(session, res, true) // 领取附件 if code == pb.ErrorCode_Success { // 修改状态 this.module.modelMail.MailUpdateMailAttachmentState(req.ObjID) } } } 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 proto.Message) { 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) res := make([]*cfg.Game_atn, 0) for _, v := range mails { for _, v1 := range v.Items { d := &cfg.Game_atn{ A: v1.A, T: v1.T, N: v1.N, } fj = append(fj, v1) res = append(res, d) } code = this.module.api.module.DispenseRes(session, res, true) // 领取附件 if 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 }