From 77030e561d68aca75d4d6d2c7e863319189c12ae Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 26 Oct 2022 17:45:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=8F=91=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 1 + modules/mail/module.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/comm/imodule.go b/comm/imodule.go index eaa5d9e86..26683d285 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -16,6 +16,7 @@ type ( //邮件业务模块对外接口定义 提供给其他模块使用的 Imail interface { CreateNewMail(session IUserSession, mail *pb.DBMailData) bool + SendNewMail(mail *pb.DBMailData, uid ...string) bool // 批量发送邮件 支持跨服 } //道具背包接口 IItems interface { diff --git a/modules/mail/module.go b/modules/mail/module.go index 6bc778c8f..2eb3bd4c1 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -83,3 +83,40 @@ func (this *Mail) AddNewMailPush(session comm.IUserSession, mail *pb.DBMailData) session.SendMsg(string(this.GetType()), "getnewmail", &pb.MailGetNewMailPush{Mail: mail}) return } + +// 给多个用户发邮件 +func (this *Mail) SendNewMail(mail *pb.DBMailData, uid ...string) bool { + if db.IsCross() { + for _, id := range uid { + tag, _, b := utils.UIdSplit(id) + if b { + if conn, err := db.ServerDBConn(tag); err == nil { + dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + mail.ObjId = primitive.NewObjectID().Hex() + mail.Check = false + mail.Reward = false + + if len(mail.GetItems()) > 0 { + mail.Reward = false + } + _, err = dbModel.DB.InsertOne(comm.TableMail, mail) + } + } + } + } else { + for _, id := range uid { + mail.Uid = id + mail.ObjId = primitive.NewObjectID().Hex() + mail.Check = false + mail.Reward = false + + if len(mail.GetItems()) > 0 { + mail.Reward = false + } + this.modelMail.DB.InsertOne(comm.TableMail, mail) + } + } + mail.Uid = "" + this.SendMsgToUsers(string(this.GetType()), "getnewmail", &pb.MailGetNewMailPush{Mail: mail}, uid...) + return true +}