go_dreamfactory/modules/mail/module.go
2022-06-28 17:18:48 +08:00

67 lines
1.5 KiB
Go

package mail
import (
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"time"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go.mongodb.org/mongo-driver/bson/primitive"
)
/*
模块名:Mail
描述:邮件系统模块
开发:梅雄风
*/
func NewModule() core.IModule {
m := new(Mail)
return m
}
type Mail struct {
modules.ModuleBase
api *apiComp
modelMail *modelMail
configure_comp *Configure_Comp
}
func (this *Mail) GetType() core.M_Modules {
return comm.SM_MailModule
}
func (this *Mail) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelMail = this.RegisterComp(new(modelMail)).(*modelMail)
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
}
func (this *Mail) CreateNewMail(uId string) {
mail := &pb.DB_MailData{
ObjId: primitive.NewObjectID().Hex(),
Uid: uId,
Title: "系统邮件",
Contex: "恭喜获得专属礼包一份",
CreateTime: uint64(time.Now().Unix()),
DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件
Check: false,
Reward: false,
}
err := this.modelMail.Mail_InsertUserMail(mail)
if err != nil {
log.Error("create mail failed")
}
// 通知玩家
var _cache = &pb.Cache_UserData{}
err = this.modelMail.MCompModel.Get(uId, _cache)
if err == nil {
return
}
this.SendMsgToUser(string(this.GetType()), GetNewEMailResp, mail, _cache)
}