This commit is contained in:
aozhiwei 2024-04-13 11:06:53 +08:00
parent f857921035
commit 9a78606124
6 changed files with 13 additions and 169 deletions

View File

@ -4,6 +4,7 @@ import (
"f5"
"main/constant"
"mt"
"main/middleware"
)
type app struct {
@ -29,6 +30,12 @@ func (this *app) Init() {
f5.LoadMetaTable(mt.Table)
this.registerDataSources()
this.initCb()
f5.GetApp().GetGinEngine().Use(middleware.CaForward, middleware.CaAuth)
/*f5.GetApp().RegisterCaHandle("Mail", "getMailList", mail_getMailList)
f5.GetApp().RegisterCaHandle("Mail", "markMail", mail_markMail)
f5.GetApp().RegisterCaHandle("Mail", "getUnreadMailCnt", mail_getUnreadMailCnt)
f5.GetApp().RegisterCaHandle("Mail", "getAttachment", mail_getAttachment)
f5.GetApp().RegisterCaHandle("Mail", "deleteMails", mail_deleteMails)*/
}
func (this *app) UnInit() {

View File

@ -8,35 +8,16 @@ type Player interface {
Lock()
UnLock()
GetAccountId() string
GetSessionId() string
GetRegisterTime() int32
FillMailList(mailList *[]MailDto)
ReadMails(mailIds []int64)
GetUnreadMailCnt() int32
GetMailById(mailId int64) *MailDto
GetAttachments(mailIds []int64)
DeleteMails(mailIds []int64)
IsDeletedMail(mailId int64)
IsReadedMail(mailId int64)
}
type PlayerMgr interface{}
type AttachmentDto struct {
ItemId int32 `json:"itemid"`
ItemNum int32 `json:"itemnum"`
type PlayerMgr interface{
}
type MailDto struct {
MailId string `json:"mailid"`
Subject string `json:"subject"`
Content string `json:"content"`
Flags int32 `json:"flags"`
SendTime int32 `json:"sendtime"`
ExpireTime int32 `json:"expiretime""`
Attachments []AttachmentDto `json:"attachments""`
type MailMgr interface{
}
type MailMgr interface{}
type ControllerMgr interface{
type ControllerMgr interface{}
}

View File

@ -1,23 +0,0 @@
package controller
import (
"f5"
"main/middleware"
)
type ControllerMgr struct {
}
func (this* ControllerMgr) Init() {
f5.GetApp().GetGinEngine().Use(middleware.CaForward, middleware.CaAuth)
f5.GetApp().RegisterCaHandle("Mail", "getMailList", mail_getMailList)
f5.GetApp().RegisterCaHandle("Mail", "markMail", mail_markMail)
f5.GetApp().RegisterCaHandle("Mail", "getUnreadMailCnt", mail_getUnreadMailCnt)
f5.GetApp().RegisterCaHandle("Mail", "getAttachment", mail_getAttachment)
f5.GetApp().RegisterCaHandle("Mail", "deleteMails", mail_deleteMails)
}
func (this* ControllerMgr) UnInit() {
}

View File

@ -1,12 +1,5 @@
package controller
import (
"main/constant"
"main/global"
)
var _controllerMgr = new(ControllerMgr)
func init() {
global.RegModule(constant.CONTROLLER_MGR_MODULE_IDX, _controllerMgr)
}

View File

@ -1,108 +1,20 @@
package controller
import (
"net/http"
"github.com/gin-gonic/gin"
"q5"
"f5"
"main/common"
"mt"
)
func mail_getMailList(c *gin.Context) {
hum := c.MustGet("player").(common.Player)
var msg struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
MailList []common.MailDto `json:"maillist""`
}
q5.NewSlice(&msg.MailList, 0, 10)
hum.FillMailList(&msg.MailList)
c.JSON(http.StatusOK, msg)
}
func mail_markMail(c *gin.Context) {
hum := c.MustGet("player").(common.Player)
var msg struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
mailIdsStr := q5.StrSplit(c.DefaultQuery("mail_ids", ""), ",")
mailIds := []int64{}
for i := 0; i < len(mailIdsStr); i++ {
*q5.NewSliceElement(&mailIds) = q5.ToInt64(mailIdsStr[i])
}
hum.ReadMails(mailIds)
c.JSON(http.StatusOK, msg)
}
func mail_getUnreadMailCnt(c *gin.Context) {
hum := c.MustGet("player").(common.Player)
var msg struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
UnreadMailCnt int32 `json:"unread_mail_cnt"`
}
msg.UnreadMailCnt = hum.GetUnreadMailCnt()
c.JSON(http.StatusOK, msg)
}
func mail_getAttachment(c *gin.Context) {
hum := c.MustGet("player").(common.Player)
var msg struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
mailIdsStr := q5.StrSplit(c.DefaultQuery("mail_ids", ""), ",")
info := struct {
MailList []struct {
MailId string `json:"mailid"`
Attachments []struct {
ItemId int32 `json:"itemid"`
ItemNum int32 `json:"itemnum"`
} `json:"attachments"`
} `json:"mail_list"`
} {
}
mailIds := []int64{}
mails := []*common.MailDto{}
for i := 0; i < len(mailIdsStr); i++ {
mailId := q5.ToInt64(mailIdsStr[i])
mailDto := hum.GetMailById(mailId)
if mailDto != nil {
*q5.NewSliceElement(&mailIds) = mailId
*q5.NewSliceElement(&mails) = mailDto
}
}
apiUrl := mt.Table.Config.GetGameApiUrl()
params := make(map[string]string)
params["c"] = "Mail"
params["a"] = "getAttachment"
params["account_id"] = hum.GetAccountId()
params["session_id"] = hum.GetSessionId()
params["info"] = q5.EncodeJson(&info)
hum.UnLock()
f5.GetHttpCliMgr().SyncSendGoStyleRequest(
apiUrl,
params,
func (rsp f5.HttpCliResponse) {
hum.Lock()
c.JSON(http.StatusOK, msg)
})
}
func mail_deleteMails(c *gin.Context) {
hum := c.MustGet("player").(common.Player)
var msg struct {
ErrCode int32 `json:"errcode"`
ErrMsg string `json:"errmsg"`
}
mailIdsStr := q5.StrSplit(c.DefaultQuery("mail_ids", ""), ",")
mailIds := []int64{}
for i := 0; i < len(mailIdsStr); i++ {
*q5.NewSliceElement(&mailIds) = q5.ToInt64(mailIdsStr[i])
}
hum.DeleteMails(mailIds)
c.JSON(http.StatusOK, msg)
}

View File

@ -55,29 +55,3 @@ func NewMail() *Mail {
m.Init()
return m
}
/*
func (m *Mail) ParseAttachments(attachmentsStr string) {
if len(attachmentsStr) <= 0 {
m.ATT = make([]*Attachment, 0)
return
}
attachmentStrList := strings.Split(attachmentsStr, "|")
m.ATT = make([]*Attachment, 0, len(attachmentStrList))
for _, attachmentStr := range attachmentStrList {
if len(attachmentStr) <= 0 {
continue
}
itemParts := strings.Split(attachmentStr, ":")
if len(itemParts) != 2 {
continue
}
attachment := &Attachment{
ItemId: q5.ToInt(itemParts[0]),
ItemNum: q5.ToInt(itemParts[1]),
}
m.ATT = append(m.ATT, attachment)
}
}
*/