You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.8 KiB
145 lines
4.8 KiB
package serviceGame |
|
|
|
import ( |
|
"context" |
|
"errors" |
|
"github.com/gogf/gf/v2/frame/g" |
|
"github.com/gogf/gf/v2/os/gtime" |
|
"github.com/gogf/gf/v2/util/guid" |
|
"strings" |
|
"time" |
|
"tyj_admin/api/v1/game" |
|
"tyj_admin/internal/consts" |
|
"tyj_admin/internal/model/entity" |
|
"tyj_admin/internal/serviceGame/internal" |
|
) |
|
|
|
type IGameMail interface { |
|
GetMailList(ctx context.Context, req *game.MailsSearchReq) (res *game.MailsSearchRes, err error) |
|
SendMail(ctx context.Context, req *game.MailSendReq) (res *game.MailSendRes, err error) |
|
DelMail(ctx context.Context, req *game.MailDelReq) (res *game.MailDelRes, err error) |
|
UpdateMail(ctx context.Context, req *game.MailUpdateReq) (res *game.MailUpdateRes, err error) |
|
GetMailModel(ctx context.Context, req *game.GetMailDropModelReq) (res *game.GetMailDropModelRes, err error) |
|
UpdateMailModel(ctx context.Context, req *game.UpdateMailDropModelReq) (res *game.UpdateMailDropModelRes, err error) |
|
} |
|
|
|
type gameMailImpl struct { |
|
} |
|
|
|
var gameMailService = gameMailImpl{} |
|
|
|
func GameMail() IGameMail { |
|
return &gameMailService |
|
} |
|
|
|
func (m *gameMailImpl) GetMailList(ctx context.Context, req *game.MailsSearchReq) (res *game.MailsSearchRes, err error) { |
|
res = new(game.MailsSearchRes) |
|
g.Try(ctx, func(ctx context.Context) { |
|
res, err = internal.GetMails(ctx, req) |
|
}) |
|
return |
|
} |
|
|
|
func (m *gameMailImpl) SendMail(ctx context.Context, req *game.MailSendReq) (res *game.MailSendRes, err error) { |
|
res = new(game.MailSendRes) |
|
//mail := entity.Mail{} |
|
//mqttMail.Body.Mail.GmName = req.GmName |
|
//mqttMail.Body.Mail.RepeatedCollection = req.RepeatedCollection |
|
//mqttMail.Body.Mail.Remark = req.Remark |
|
//mqttMail.Body.Mail.To = req.To |
|
mqttMail := internal.MqttMail{} |
|
mqttMail.Body.Mail.C_date = time.Now().UnixMilli() |
|
mqttMail.Body.Mail.Id = guid.S() |
|
mqttMail.Body.Mail.ServerId = req.ServerId |
|
mqttMail.Body.Mail.Send = req.Send |
|
mqttMail.Body.Mail.Time = req.Time |
|
mqttMail.Body.Mail.From = req.From // "陶渊明" |
|
mqttMail.Body.Mail.Type = req.Type |
|
mqttMail.Body.Mail.Expired = req.Expired |
|
mqttMail.Body.Mail.ValidDay = req.ValidDay |
|
mqttMail.Body.Mail.NewGet = req.NewGet |
|
mqttMail.Body.Mail.Title = req.Title |
|
//mqttMail.Body.Mail.Greetings = req.Greetings |
|
mqttMail.Body.Mail.Content = req.Content |
|
for _, v := range req.Drops { |
|
if v.Id > 0 && v.Num == 0 { |
|
return nil, errors.New("奖励物品未配置数量") |
|
} |
|
} |
|
mqttMail.Body.Mail.Drops = req.Drops |
|
mqttMail.Body.Mail.OwnerId = req.OwnerId |
|
mqttMail.Body.Mail.UserName = req.UserName |
|
errdata := "" |
|
owners := strings.Split(req.OwnerId, ";") |
|
owner := "" |
|
if req.OwnerId != "" { |
|
for _, v := range owners { |
|
uid, _ := internal.GetStringIdToUid(ctx, v) |
|
if uid == "" { |
|
errdata += "uid:" + v + "不存在!" |
|
continue |
|
} |
|
if len(owner) > 0 { |
|
owner += ";" |
|
} |
|
owner += uid |
|
} |
|
if len(owner) == 0 { |
|
errdata += "uid不存在,发送失败!" |
|
return nil, errors.New(errdata) |
|
} |
|
} |
|
if req.Send == int32(consts.Mail_Send_Time) { |
|
g.Log().Debug(ctx, "SendMail -> Mail_Send_Time ", req) |
|
} else if req.Send == int32(consts.Mail_Send_Now) { |
|
date, _ := gtime.ParseDuration("1s") |
|
mqttMail.Body.Mail.Time = gtime.TimestampMilli() + date.Milliseconds() |
|
g.Log().Debug(ctx, "SendMail -> Mail_Send_Now", req, mqttMail.Body.Mail) |
|
} else { |
|
date, _ := gtime.ParseDuration("10m") |
|
req.Send = consts.Mail_Send_10M |
|
mqttMail.Body.Mail.Time = gtime.TimestampMilli() + date.Milliseconds() |
|
g.Log().Debug(ctx, "SendMail -> Mail_Send_10m", req, mqttMail.Body.Mail) |
|
} |
|
GameCron().AddMailCorn(mqttMail.Body.Mail) |
|
err = internal.AddMail(ctx, mqttMail.Body.Mail) |
|
return nil, err |
|
} |
|
|
|
func (m *gameMailImpl) DelMail(ctx context.Context, req *game.MailDelReq) (res *game.MailDelRes, err error) { |
|
res = new(game.MailDelRes) |
|
err = internal.DelMail(ctx, entity.Mail{Id: req.Id}) |
|
return |
|
} |
|
|
|
func (m *gameMailImpl) UpdateMail(ctx context.Context, req *game.MailUpdateReq) (res *game.MailUpdateRes, err error) { |
|
res = new(game.MailUpdateRes) |
|
//err = internal.DelMail(ctx, entity.Mail{ |
|
// Id: req.Id, |
|
// Send: req.Send, |
|
// Time: req.Time, |
|
// From: req.From, // "陶渊明" //To: req.To, |
|
// Type: req.Type, |
|
// Expired: req.Expired, |
|
// ValidDay: req.ValidDay, |
|
// NewGet: req.NewGet, |
|
// Title: req.Title, |
|
// Greetings: req.Greetings, |
|
// Content: req.Content, |
|
// Drops: req.Drops, |
|
//}) |
|
|
|
req1 := entity.Mail{Id: req.Id, Send: consts.Mail_Send_Cancel} |
|
err = internal.UpdateMail(ctx, req1, err.Error()) |
|
return |
|
} |
|
|
|
func (m *gameMailImpl) GetMailModel(ctx context.Context, req *game.GetMailDropModelReq) (res *game.GetMailDropModelRes, err error) { |
|
res, err = internal.GetMailModel(ctx, req) |
|
return |
|
} |
|
|
|
func (m *gameMailImpl) UpdateMailModel(ctx context.Context, req *game.UpdateMailDropModelReq) (res *game.UpdateMailDropModelRes, err error) { |
|
res, err = internal.UpdateMailModel(ctx, req) |
|
return |
|
}
|
|
|