diff --git a/comm/imodule.go b/comm/imodule.go index 2b9036861..51c90588b 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -50,9 +50,10 @@ type ( SendNewMail(mail *pb.DBMailData, uid ...string) bool // 批量发送邮件 支持跨服 SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Param []string) bool IGetReddot - // 所有邮件奖励统一调这个接口 SendRewardMailByCid(session IUserSession, cid string, res []*cfg.Gameatn) bool + // 批量发邮件结果: cid 邮件表ID, 没有附件 res 传空 + SendMailToUsers(uids []string, cid string, res []*cfg.Gameatn) bool // 批量发送邮件 支持跨服 } //道具背包接口 IItems interface { diff --git a/modules/mail/module.go b/modules/mail/module.go index 7596c9d34..2d13a2802 100644 --- a/modules/mail/module.go +++ b/modules/mail/module.go @@ -301,6 +301,7 @@ func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn, Para } return true } + func (this *Mail) SendRewardMailByCid(session comm.IUserSession, cid string, res []*cfg.Gameatn) bool { var ( resReward []*pb.UserAssets @@ -328,7 +329,7 @@ func (this *Mail) SendRewardMailByCid(session comm.IUserSession, cid string, res ObjId: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CreateTime: uint64(configure.Now().Unix()), - DueTime: uint64(configure.Now().Unix() + 30*24*3600), + DueTime: uint64(configure.Now().Unix() + int64(conf.Duration)*3600), Items: resReward, Cid: cid, Param: []string{}, @@ -363,3 +364,78 @@ func (this *Mail) SendRewardMailByCid(session comm.IUserSession, cid string, res return true } + +func (this *Mail) SendMailToUsers(uids []string, cid string, res []*cfg.Gameatn) bool { + var ( + resReward []*pb.UserAssets + ) + + // 获取额外配置 + conf := this.configure.GetMailConf(cid) + if conf == nil { + this.Errorf("can't found mail by cid: %s", cid) + return false + } + if len(conf.Reword) > 0 { + res = append(res, conf.Reword...) + + } + for _, v := range res { + resReward = append(resReward, &pb.UserAssets{ + A: v.A, + T: v.T, + N: v.N, + }) + } + + if db.IsCross() { + for _, id := range uids { + if tag, _, b := utils.UIdSplit(id); b { + if conn, err := db.ServerDBConn(tag); err == nil { + // 构建一个每日奖励邮件对象 + mail := &pb.DBMailData{ + ObjId: primitive.NewObjectID().Hex(), + Uid: id, + CreateTime: uint64(configure.Now().Unix()), + DueTime: uint64(configure.Now().Unix() + int64(conf.Duration)*3600), + Items: resReward, + Cid: cid, + Param: []string{}, + } + dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn) + mail.ObjId = primitive.NewObjectID().Hex() + mail.Check = false + mail.Reward = true + + if len(mail.GetItems()) > 0 { + mail.Reward = false + } + _, err = dbModel.DB.InsertOne(comm.TableMail, mail) + } + } + } + + } else { + for _, id := range uids { + mail := &pb.DBMailData{ + ObjId: primitive.NewObjectID().Hex(), + Uid: id, + CreateTime: uint64(configure.Now().Unix()), + DueTime: uint64(configure.Now().Unix() + int64(conf.Duration)*3600), + Items: resReward, + Cid: cid, + Param: []string{}, + } + mail.Uid = id + mail.ObjId = primitive.NewObjectID().Hex() + mail.Check = false + mail.Reward = true + + if len(mail.GetItems()) > 0 { + mail.Reward = false + } + this.modelMail.DB.InsertOne(comm.TableMail, mail) + } + } + return true +}