save
This commit is contained in:
parent
c029301901
commit
2e3f7b8c7e
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"main/common"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@ -41,11 +42,11 @@ func (api *MailApi) GetMailList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// accountObj
|
||||
mails := mailMgr.GetMails(req.AccountId)
|
||||
commonPlayer := (common.Player)(accountObj)
|
||||
mails := mailMgr.GetMails(commonPlayer)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errcode": 0,
|
||||
"errmsg": "success",
|
||||
"errmsg": "",
|
||||
"maillist": mails,
|
||||
})
|
||||
}
|
||||
|
@ -7,7 +7,10 @@ type App interface {
|
||||
RemoveSession(accountId string)
|
||||
}
|
||||
|
||||
type Player interface{}
|
||||
type Player interface {
|
||||
GetAccountId() string
|
||||
}
|
||||
|
||||
type PlayerMgr interface{}
|
||||
type Mail interface{}
|
||||
type MailMgr interface{}
|
||||
|
@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
GAMEID = "2006"
|
||||
GAMEID = 2006
|
||||
EMAIL_URL_DEV = "gamemail-test.kingsome.cn"
|
||||
EMAIL_KEY = "520d8eeb8cf1d833a42c820432c020b2fd60f4b7|" + EMAIL_URL_DEV
|
||||
)
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
)
|
||||
|
||||
type MailMgr struct {
|
||||
Player common.Player
|
||||
allMailHash map[int64]*Mail
|
||||
gameMailHash map[int]map[int64]*Mail
|
||||
playerMailHash map[string]map[int64]*Mail
|
||||
|
@ -1,6 +1,9 @@
|
||||
package mail
|
||||
|
||||
import "main/constant"
|
||||
import (
|
||||
"main/common"
|
||||
"main/constant"
|
||||
)
|
||||
|
||||
func (mm *MailMgr) AddMail(m *Mail) {
|
||||
//unixSec := int(time.Now().Unix())
|
||||
@ -30,16 +33,28 @@ func (mm *MailMgr) AddMail(m *Mail) {
|
||||
}
|
||||
}
|
||||
|
||||
func (mm *MailMgr) GetMails(accountId string) []*Mail {
|
||||
gameId := 2006
|
||||
mails, exists := mm.gameMailHash[gameId]
|
||||
if !exists {
|
||||
func (mm *MailMgr) GetMails(player common.Player) []*Mail {
|
||||
gameMails := mm.gameMailHash[constant.GAMEID]
|
||||
playerMails := mm.playerMailHash[player.GetAccountId()]
|
||||
playerMailSize := len(playerMails)
|
||||
if len(gameMails)+playerMailSize == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
mailList := make([]*Mail, 0, len(mails))
|
||||
for _, mailData := range mails {
|
||||
mailList = append(mailList, mailData)
|
||||
resMailsSize := len(gameMails)
|
||||
if playerMailSize > 0 {
|
||||
resMailsSize += playerMailSize
|
||||
}
|
||||
return mailList
|
||||
|
||||
resMailList := make([]*Mail, 0, resMailsSize)
|
||||
for _, gMail := range gameMails {
|
||||
resMailList = append(resMailList, gMail)
|
||||
}
|
||||
if playerMailSize > 0 {
|
||||
for _, pMail := range playerMails {
|
||||
resMailList = append(resMailList, pMail)
|
||||
}
|
||||
}
|
||||
|
||||
return resMailList
|
||||
}
|
||||
|
@ -10,15 +10,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
sync.Mutex
|
||||
AccountId string
|
||||
SessionId string
|
||||
RegisterTime int
|
||||
ReadMailHash map[int64]*ReadMail
|
||||
DeletedMailHash map[int64]*DeletedMail
|
||||
}
|
||||
|
||||
type ReadMail struct {
|
||||
mailId int64
|
||||
readTime int32
|
||||
@ -31,11 +22,24 @@ type DeletedMail struct {
|
||||
expireTime int32
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
sync.Mutex
|
||||
AccountId string
|
||||
SessionId string
|
||||
RegisterTime int
|
||||
ReadMailHash map[int64]*ReadMail
|
||||
DeletedMailHash map[int64]*DeletedMail
|
||||
}
|
||||
|
||||
func (p *Player) Init() {
|
||||
p.ReadMailHash = make(map[int64]*ReadMail)
|
||||
p.DeletedMailHash = make(map[int64]*DeletedMail)
|
||||
}
|
||||
|
||||
func (p *Player) GetAccountId() string {
|
||||
return p.AccountId
|
||||
}
|
||||
|
||||
func (p *Player) IsUnreadMail(mailId int64) bool {
|
||||
m := p.ReadMailHash[mailId]
|
||||
return m == nil
|
||||
|
@ -35,7 +35,7 @@ func (pm *PlayerMgr) LoadPlayer(accountId string, cb func(err error, p *Player))
|
||||
|
||||
cb(nil, profile)
|
||||
} else {
|
||||
|
||||
cb(fmt.Errorf("player nil"), nil)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -1,6 +1,8 @@
|
||||
package player
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type PlayerMgr struct {
|
||||
accountIdHash map[string]*Player
|
||||
|
Loading…
x
Reference in New Issue
Block a user