diff --git a/comm/const.go b/comm/const.go index bc24d46b0..9488ad007 100644 --- a/comm/const.go +++ b/comm/const.go @@ -590,7 +590,8 @@ const ( ) const ( - MaxRankList = 50 // 赛季塔 排行榜人数 + MaxRankList = 50 // 赛季塔 排行榜人数 + MaxMailCount = 50 // 当前邮件最大数量 ) const ( diff --git a/modules/mail/model_mail.go b/modules/mail/model_mail.go index 6a057f216..5a655e2f4 100644 --- a/modules/mail/model_mail.go +++ b/modules/mail/model_mail.go @@ -31,11 +31,16 @@ func (this *modelMail) Init(service core.IService, module core.IModule, comp cor } func (this *modelMail) MailQueryUserMail(uId string) (mail []*pb.DBMailData, err error) { - - if _data, err := this.DB.Find(comm.TableMail, bson.M{"uid": uId}, options.Find().SetSort(bson.M{"createtime": -1})); err == nil { + var index int32 + if _data, err := this.DB.Find(comm.TableMail, bson.M{"uid": uId}); err == nil { for _data.Next(context.TODO()) { + index++ temp := &pb.DBMailData{} if err = _data.Decode(temp); err == nil { + if index > comm.MaxMailCount { // 删除超标的邮件 + this.DB.DeleteOne(comm.TableMail, bson.M{"_id": temp.ObjId}, options.Delete()) + continue + } mail = append(mail, temp) } } @@ -90,6 +95,29 @@ func (this *modelMail) MailGetMailAttachmentState(objId string) (*pb.DBMailData, return nd, err } +func (this *modelMail) GetMailCountByUid(uid string) (int32, error) { + var count int64 + count, err := this.DB.CountDocuments(comm.TableMail, bson.M{"uid": uid}) + + return int32(count), err +} + +// 删除超过最大邮件数量的邮件 +func (this *modelMail) DelOtherMail(uid string) { + if _data, err := this.DB.Find(comm.TableMail, bson.M{"uid": uid}); err == nil { + var index int32 + for _data.Next(context.TODO()) { + index++ + temp := &pb.DBMailData{} + if err = _data.Decode(temp); err == nil { + if index >= comm.MaxMailCount { // 删除超标的邮件 + this.DB.DeleteOne(comm.TableMail, bson.M{"_id": temp.ObjId}, options.Delete()) + continue + } + } + } + } +} // 更新领取附件状态 func (this *modelMail) MailUpdateMailAttachmentState(objId string) bool { diff --git a/modules/mail/module.go b/modules/mail/module.go index 341e59978..dd8d8a9d0 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -187,3 +187,12 @@ func (this *Mail) SendMailByCid(session comm.IUserSession, cid string, res []*pb return true } + +// 创建邮件之前检测邮件是否达到上限 +func (this *Mail) CheckMaxMail(session comm.IUserSession) bool { + count, err := this.modelMail.GetMailCountByUid(session.GetUserId()) + if err == nil && count >= comm.MaxMailCount { + this.modelMail.DelOtherMail(session.GetUserId()) + } + return true +} diff --git a/modules/sociaty/api_cross_recommend.go b/modules/sociaty/api_cross_recommend.go index 2dc382594..92b5785ed 100644 --- a/modules/sociaty/api_cross_recommend.go +++ b/modules/sociaty/api_cross_recommend.go @@ -9,7 +9,7 @@ import ( // 公会BOSS 推荐 func (this *apiComp) RecommendCheck(session comm.IUserSession, req *pb.SociatyRecommendReq) (code pb.ErrorCode) { - if req.Cate != 1 || req.Cate != 2 { + if req.Cate != 1 && req.Cate != 2 { code = pb.ErrorCode_ReqParameterError } return