67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package mail
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
)
|
|
|
|
/*
|
|
模块名: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.ModuleMail
|
|
}
|
|
|
|
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.DBMailData) bool {
|
|
// mail := &pb.DBMailData{
|
|
// 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,
|
|
// }
|
|
if mail == nil {
|
|
return false
|
|
}
|
|
err := this.modelMail.Mail_InsertUserMail(mail)
|
|
if err != nil {
|
|
this.ModuleBase.Errorf("create mail failed")
|
|
}
|
|
// 通知玩家
|
|
var _cache = &pb.CacheUser{}
|
|
err = this.modelMail.MCompModel.Get(uId, _cache)
|
|
if err == nil {
|
|
return false
|
|
}
|
|
|
|
this.SendMsgToUser(string(this.GetType()), "newmail", mail, _cache)
|
|
return true
|
|
}
|