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