提供接口给其他模块调用

This commit is contained in:
meixiongfeng 2022-06-08 17:54:24 +08:00
parent d74fdd9f6f
commit a9b31d063e
4 changed files with 71 additions and 3 deletions

View File

@ -42,6 +42,14 @@ type ISC_GateRouteComp interface {
RegisterRoute(methodName string, comp reflect.Value, msg reflect.Type, fn reflect.Method)
}
type Imail interface {
CreateNewMail(uId string)
}
type IPack interface {
//GetRewaredItems(uId string, itmes map[uint32]uint32)
}
//用户会话
type IUserSession interface {
GetSessionId() string

View File

@ -21,19 +21,35 @@ const (
GetUserMailAttachmentResp = "mail.getusermailattachmentresp"
DelUserMailReq = "mail.delusermailreq"
DelUserMailResp = "mail.delusermailresp"
GetNewEMailResp = "mail.getnewEmailresp"
)
type Api_Comp struct {
modules.MComp_GateComp
module *Mail
service core.IService
module *Mail
pack comm.IPack
}
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options)
this.service = service
this.module = module.(*Mail)
return
}
func (this *Api_Comp) Start() (err error) {
err = this.MComp_GateComp.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.SM_PackModule); err != nil {
return
}
this.pack = module.(comm.IPack)
return
}
func (this *Api_Comp) QueryUserMailReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserMailReq) (err error) {
code := pb.ErrorCode_Success
@ -129,5 +145,6 @@ func (this *Api_Comp) DelUserMailReq(ctx context.Context, session comm.IUserSess
code = pb.ErrorCode_CacheReadError
return
}
return
}

View File

@ -3,8 +3,15 @@ package mail
import (
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"time"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/sys/cache"
"go_dreamfactory/sys/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
/*
@ -32,3 +39,26 @@ func (this *Mail) OnInstallComp() {
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_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,
Check: false,
Reward: false,
}
err := db.Defsys.InsertUserMail(mail)
if err != nil {
log.Error("create mail failed")
}
// 通知玩家
_cache := cache.Defsys.Get(uId)
if _cache == nil {
return
}
this.SendMsgToUser("mail", "getnewEmailresp", mail, _cache)
}

View File

@ -22,15 +22,29 @@ const (
type Api_Comp struct {
modules.MComp_GateComp
module *Pack
service core.IService
module *Pack
mail comm.Imail
}
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MComp_GateComp.Init(service, module, comp, options)
this.service = service
this.module = module.(*Pack)
return
}
func (this *Api_Comp) Start() (err error) {
err = this.MComp_GateComp.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.SM_MailModule); err != nil {
return
}
this.mail = module.(comm.Imail)
return
}
///查询用户背包数据
func (this *Api_Comp) QueryUserPackReq(ctx context.Context, session comm.IUserSession, req *pb.QueryUserPackReq) (err error) {
var (
@ -82,6 +96,5 @@ func (this *Api_Comp) SellItemReq(ctx context.Context, session comm.IUserSession
code = pb.ErrorCode_NoLogin
return
}
return
}