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.
102 lines
2.5 KiB
102 lines
2.5 KiB
3 years ago
|
package serviceGame
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||
|
"github.com/gogf/gf/v2/frame/g"
|
||
|
"github.com/gogf/gf/v2/util/guid"
|
||
|
"strings"
|
||
|
"time"
|
||
|
"tyj_admin/api/v1/game"
|
||
|
"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)
|
||
|
}
|
||
|
|
||
|
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.Mails, err = internal.GetMails(ctx, req.Uid, req.ServerId, req.LowTime, req.UpperTime)
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (m *gameMailImpl) SendMail(ctx context.Context, req *game.MailSendReq) (res *game.MailSendRes, err error) {
|
||
|
res = new(game.MailSendRes)
|
||
|
mqttMail := internal.MqttMail{}
|
||
|
//mail := entity.Mail{}
|
||
|
mqttMail.Body.Mail.C_date = time.Now().UnixMilli()
|
||
|
mqttMail.Body.Mail.Id = guid.S()
|
||
|
mqttMail.Body.Mail.ServerId = req.ServerId
|
||
|
mqttMail.Body.Mail.Time = req.Time
|
||
|
mqttMail.Body.Mail.To = req.To
|
||
|
mqttMail.Body.Mail.From = "陶渊明"
|
||
|
mqttMail.Body.Mail.GmName = req.GmName
|
||
|
mqttMail.Body.Mail.Type = req.Type
|
||
|
mqttMail.Body.Mail.Expired = req.Expired
|
||
|
mqttMail.Body.Mail.NewGet = req.NewGet
|
||
|
mqttMail.Body.Mail.RepeatedCollection = req.RepeatedCollection
|
||
|
mqttMail.Body.Mail.Title = req.Title
|
||
|
mqttMail.Body.Mail.Content = req.Content
|
||
|
mqttMail.Body.Mail.Drops = GetDrops(req.Drops)
|
||
|
mqttMail.Body.Mail.Remark = req.Remark
|
||
|
mqttMail.Body.ModuleType = "sendMail"
|
||
|
mqttMail.ModuleId = "webadmin"
|
||
|
mqttMail.ReqId = 1
|
||
|
js, err := json.Marshal(mqttMail)
|
||
|
connectCh := make(chan bool)
|
||
|
server := "192.168.2.100:3005"
|
||
|
defer close(connectCh)
|
||
|
internal.SendMqttMail(js, connectCh, server)
|
||
|
var result bool
|
||
|
for {
|
||
|
select {
|
||
|
case result = <-connectCh:
|
||
|
if result == false {
|
||
|
err = gerror.New("失败")
|
||
|
return
|
||
|
} else {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
internal.AddMail(ctx, mqttMail.Body.Mail)
|
||
|
return
|
||
|
|
||
|
}
|
||
|
|
||
|
func GetDrops(drop string) []entity.Drop {
|
||
|
var realDrops []entity.Drop
|
||
|
if len(drop) == 0 {
|
||
|
return realDrops
|
||
|
}
|
||
|
drops := strings.Split(drop, ",")
|
||
|
for _, v := range drops {
|
||
|
temp := strings.Split(v, ":")
|
||
|
if len(temp) != 2 {
|
||
|
continue
|
||
|
}
|
||
|
ss := entity.Drop{temp[0], temp[1]}
|
||
|
realDrops = append(realDrops, ss)
|
||
|
|
||
|
}
|
||
|
|
||
|
return realDrops
|
||
|
|
||
|
}
|