67 lines
1.5 KiB
Go
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_comp *Api_Comp
|
|
db_comp *DB_Comp
|
|
configure_comp *Configure_Comp
|
|
}
|
|
|
|
func (this *Mail) GetType() core.M_Modules {
|
|
return comm.SM_MailModule
|
|
}
|
|
|
|
func (this *Mail) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
|
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
|
this.configure_comp = this.RegisterComp(new(Configure_Comp)).(*Configure_Comp)
|
|
}
|
|
|
|
func (this *Mail) CreateNewMail(uId string) {
|
|
mail := &pb.DB_MailData{
|
|
ObjId: primitive.NewObjectID().Hex(),
|
|
UserId: uId,
|
|
Title: "系统邮件",
|
|
Contex: "恭喜获得专属礼包一份",
|
|
CreateTime: uint64(time.Now().Unix()),
|
|
DueTime: uint64(time.Now().Unix()) + 30*24*3600, // 30天需要走配置文件
|
|
Check: false,
|
|
Reward: false,
|
|
}
|
|
err := this.db_comp.Mail_InsertUserMail(mail)
|
|
if err != nil {
|
|
log.Error("create mail failed")
|
|
}
|
|
// 通知玩家
|
|
var _cache = &pb.Cache_UserData{}
|
|
err = this.db_comp.Model_Comp.Get(uId, _cache)
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
this.SendMsgToUser(string(this.GetType()), GetNewEMailResp, mail, _cache)
|
|
}
|