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.
94 lines
2.6 KiB
94 lines
2.6 KiB
1 month ago
|
package serviceGame
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/gogf/gf/v2/frame/g"
|
||
|
"tyj_admin/api/v1/game"
|
||
|
"tyj_admin/internal/dao"
|
||
|
"tyj_admin/internal/model/do"
|
||
|
"tyj_admin/internal/model/entity"
|
||
|
"tyj_admin/internal/serviceGame/internal"
|
||
|
"tyj_admin/library/liberr"
|
||
|
)
|
||
|
|
||
|
type IChannel interface {
|
||
|
GetChannel(ctx context.Context, req *game.GetChannelReq) (res *game.GetChannelRes, err error)
|
||
|
AddChannel(ctx context.Context, req *game.AddChannelReq) (res *game.AddChannelRes, err error)
|
||
|
DelChannel(ctx context.Context, req *game.DelChannelReq) (res *game.DelChannelRes, err error)
|
||
|
GetAllChannel(ctx context.Context, req *game.GetAllChannelReq) (res *game.GetAllChannelRes, err error)
|
||
|
}
|
||
|
|
||
|
type channelImpl struct {
|
||
|
}
|
||
|
|
||
|
var channelService = channelImpl{}
|
||
|
|
||
|
func Channel() IChannel {
|
||
|
return &channelService
|
||
|
}
|
||
|
|
||
|
func (c *channelImpl) GetChannel(ctx context.Context, req *game.GetChannelReq) (res *game.GetChannelRes, err error) {
|
||
|
g.Try(ctx, func(ctx context.Context) {
|
||
|
res = new(game.GetChannelRes)
|
||
|
model := dao.GameChannelList.Ctx(ctx)
|
||
|
res.Total, err = model.Count()
|
||
|
liberr.ErrIsNil(ctx, err, "mysql err")
|
||
|
model = model.OrderAsc("sort").Page(req.PageNum, req.PageSize)
|
||
|
err = model.Scan(&res.List)
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (c *channelImpl) AddChannel(ctx context.Context, req *game.AddChannelReq) (res *game.AddChannelRes, err error) {
|
||
|
res = new(game.AddChannelRes)
|
||
|
err = g.Try(ctx, func(ctx context.Context) {
|
||
|
server := []entity.GameChannelList{}
|
||
|
model := dao.GameChannelList.Ctx(ctx)
|
||
|
model.WherePri(req.Id).Scan(&server)
|
||
|
if len(server) > 0 {
|
||
|
data := g.Map{
|
||
|
dao.GameLoginUrl.Columns().Id: req.Id,
|
||
|
}
|
||
|
if req.Channel != "" {
|
||
|
data[dao.GameChannelList.Columns().Value] = req.Channel
|
||
|
}
|
||
|
if req.Name != "" {
|
||
|
data[dao.GameChannelList.Columns().Label] = req.Name
|
||
|
}
|
||
|
if req.Sort != "" {
|
||
|
data[dao.GameChannelList.Columns().Sort] = req.Sort
|
||
|
}
|
||
|
_, err = model.WherePri(req.Id).Update(data)
|
||
|
} else {
|
||
|
_, err = model.Insert(do.GameChannelList{
|
||
|
Label: req.Name,
|
||
|
Value: req.Channel,
|
||
|
Sort: req.Sort,
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (c *channelImpl) DelChannel(ctx context.Context, req *game.DelChannelReq) (res *game.DelChannelRes, err error) {
|
||
|
err = g.Try(ctx, func(ctx context.Context) {
|
||
|
if req.Id == 0 {
|
||
|
liberr.ErrIsNil(ctx, err, "错误的id")
|
||
|
}
|
||
|
_, e := dao.GameChannelList.Ctx(ctx).Where("id=", req.Id).Delete()
|
||
|
if e != nil {
|
||
|
liberr.ErrIsNil(ctx, e, "删除失败")
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (c *channelImpl) GetAllChannel(ctx context.Context, req *game.GetAllChannelReq) (res *game.GetAllChannelRes, err error) {
|
||
|
g.Try(ctx, func(ctx context.Context) {
|
||
|
res = new(game.GetAllChannelRes)
|
||
|
res.List = internal.ChannelList
|
||
|
})
|
||
|
return
|
||
|
}
|