152 lines
3.6 KiB
Go
152 lines
3.6 KiB
Go
package main
|
|
|
|
import (
|
|
"mongo.games.com/game/protocol/webapi"
|
|
"time"
|
|
|
|
"github.com/globalsign/mgo/bson"
|
|
"mongo.games.com/goserver/core/basic"
|
|
"mongo.games.com/goserver/core/i18n"
|
|
"mongo.games.com/goserver/core/logger"
|
|
"mongo.games.com/goserver/core/task"
|
|
|
|
"mongo.games.com/game/model"
|
|
)
|
|
|
|
type AddMailParam struct {
|
|
Platform string // 平台
|
|
Tp int32 // 邮件类型
|
|
SrcId int32 // 发送人
|
|
SrcName string // 发送人名字
|
|
SnId int32 // 收件人玩家id
|
|
Title string // 标题
|
|
Content string // 内容
|
|
Items []*model.Item // 道具
|
|
ShowId int64 // 显示位置
|
|
Channel []string // 包渠道
|
|
}
|
|
|
|
func AddMail(param *AddMailParam) {
|
|
logger.Logger.Tracef("AddMail %+v", *param)
|
|
if param.SnId <= 0 || param.Title == "" || param.Content == "" {
|
|
return
|
|
}
|
|
|
|
p := PlayerMgrSington.GetPlayerBySnId(param.SnId)
|
|
if p != nil {
|
|
param.Platform = p.Platform
|
|
}
|
|
|
|
if param.Platform == "" {
|
|
return
|
|
}
|
|
|
|
opener := int32(1)
|
|
if param.SrcId <= 0 {
|
|
opener = 0
|
|
}
|
|
|
|
var params []int64
|
|
for _, v := range param.Items {
|
|
params = append(params, int64(v.ItemId))
|
|
params = append(params, v.ItemNum)
|
|
}
|
|
|
|
var msg *model.Message
|
|
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
|
|
msg = &model.Message{
|
|
Id: bson.NewObjectId(),
|
|
MType: param.Tp,
|
|
Title: param.Title,
|
|
Content: param.Content,
|
|
Oper: opener,
|
|
SrcId: param.SrcId,
|
|
SrcName: param.SrcName,
|
|
SnId: param.SnId,
|
|
State: model.MSGSTATE_UNREAD,
|
|
CreatTs: time.Now().Unix(),
|
|
AttachState: model.MSGATTACHSTATE_DEFAULT,
|
|
Params: params,
|
|
Platform: param.Platform,
|
|
ShowId: param.ShowId,
|
|
Channel: param.Channel,
|
|
}
|
|
if msg.Pid == "" {
|
|
msg.Pid = msg.Id.Hex()
|
|
}
|
|
return model.InsertMessage(param.Platform, msg)
|
|
}), task.CompleteNotifyWrapper(func(data interface{}, t task.Task) {
|
|
if data == nil {
|
|
if p := PlayerMgrSington.GetPlayerBySnId(param.SnId); p != nil {
|
|
p.AddMessage(msg)
|
|
}
|
|
} else {
|
|
logger.Logger.Errorf("AddMail Error %v", data)
|
|
}
|
|
}), "AddMail").Start()
|
|
}
|
|
|
|
// AddMailByItem 赠送道具到邮件
|
|
// srcId 发送人 srcName发送人名字
|
|
// showId 显示位置
|
|
func AddMailByItem(platform string, srcId int32, srcName string, snid int32, showId int64, items []*model.Item) {
|
|
content := i18n.Tr("languages", "GiftMail", srcName, srcName, srcName, srcName)
|
|
title := i18n.Tr("languages", "GiftMailTitle")
|
|
AddMail(&AddMailParam{
|
|
Platform: platform,
|
|
Tp: model.MSGTYPE_ITEM,
|
|
SrcId: srcId,
|
|
SrcName: srcName,
|
|
SnId: snid,
|
|
Title: title,
|
|
Content: content,
|
|
Items: items,
|
|
ShowId: showId,
|
|
})
|
|
}
|
|
|
|
func AddMailClientUpgrade(snid int32, items []*webapi.ItemInfo) {
|
|
var arr []*model.Item
|
|
for _, v := range items {
|
|
arr = append(arr, &model.Item{
|
|
ItemId: v.ItemId,
|
|
ItemNum: v.ItemNum,
|
|
})
|
|
}
|
|
|
|
title := i18n.Tr("languages", "UpgradeTitle")
|
|
content := i18n.Tr("languages", "Upgrade")
|
|
|
|
AddMail(&AddMailParam{
|
|
Tp: model.MSGTYPE_ClientUpgrade,
|
|
SnId: snid,
|
|
Title: title,
|
|
Content: content,
|
|
Items: arr,
|
|
ShowId: model.HallAll,
|
|
})
|
|
}
|
|
|
|
func AddMailLottery(plt string, snid int32, items []*model.ItemInfo) {
|
|
var arr []*model.Item
|
|
for _, v := range items {
|
|
arr = append(arr, &model.Item{
|
|
ItemId: v.ItemId,
|
|
ItemNum: v.ItemNum,
|
|
})
|
|
}
|
|
|
|
title := i18n.Tr("languages", "LotteryTitle")
|
|
content := i18n.Tr("languages", "Lottery")
|
|
|
|
AddMail(&AddMailParam{
|
|
Platform: plt,
|
|
Tp: model.MSGTYPE_Lottery,
|
|
SnId: snid,
|
|
Title: title,
|
|
Content: content,
|
|
Items: arr,
|
|
ShowId: model.HallAll,
|
|
})
|
|
}
|