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.7 KiB
94 lines
2.7 KiB
package serviceGame |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
"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/library/liberr" |
|
) |
|
|
|
type IGameVersion interface { |
|
Get(ctx context.Context, req *game.GetVersionReq) (res *game.GetVersionRes, err error) |
|
Update(ctx context.Context, req *game.UpdateVersionReq) (res *game.UpdateVersionRes, err error) |
|
Del(ctx context.Context, req *game.DelVersionReq) (res *game.DelVersionRes, err error) |
|
GetVersion(ctx context.Context, channel string) (res string) |
|
} |
|
|
|
type gameVersionImpl struct { |
|
} |
|
|
|
var gameVersionService = gameVersionImpl{} |
|
|
|
func GameVersion() IGameVersion { |
|
return &gameVersionService |
|
} |
|
func (c *gameVersionImpl) Get(ctx context.Context, req *game.GetVersionReq) (res *game.GetVersionRes, err error) { |
|
fmt.Println("GetVersionReq: ", req) |
|
res = new(game.GetVersionRes) |
|
g.Try(ctx, func(ctx context.Context) { |
|
model := dao.GameVersion.Ctx(ctx) |
|
res.Total, err = model.Count() |
|
model = model.Page(req.PageNum, req.PageSize) |
|
err = model.Scan(&res.Version) |
|
|
|
fmt.Printf("GetVersionReq: %j", res) |
|
}) |
|
return |
|
} |
|
|
|
func (c *gameVersionImpl) Update(ctx context.Context, req *game.UpdateVersionReq) (res *game.UpdateVersionRes, err error) { |
|
g.Try(ctx, func(ctx context.Context) { |
|
model := dao.GameVersion.Ctx(ctx) |
|
model = model.Where("channel=? ", req.Channel) |
|
var noticeList []*entity.GameVersion |
|
err = model.Scan(¬iceList) |
|
if err != nil { |
|
return |
|
} |
|
if len(noticeList) > 0 { |
|
model = dao.GameVersion.Ctx(ctx) |
|
_, err = model.Where("id=", noticeList[0].Id).Data(&do.GameVersion{Channel: req.Channel, Version: req.Version}).Update() |
|
} else { |
|
model = dao.GameVersion.Ctx(ctx) |
|
_, err = model.Insert(&do.GameVersion{Channel: req.Channel, Version: req.Version}) |
|
} |
|
}) |
|
return |
|
} |
|
|
|
func (c *gameVersionImpl) Del(ctx context.Context, req *game.DelVersionReq) (res *game.DelVersionRes, err error) { |
|
err = g.Try(ctx, func(ctx context.Context) { |
|
if req.Id == 0 { |
|
liberr.ErrIsNil(ctx, err, "错误的id") |
|
return |
|
} |
|
_, e := dao.GameVersion.Ctx(ctx).Where("id=", req.Id).Delete() |
|
if e != nil { |
|
liberr.ErrIsNil(ctx, e, "删除通知失败") |
|
return |
|
} |
|
|
|
}) |
|
return |
|
} |
|
|
|
func (c *gameVersionImpl) GetVersion(ctx context.Context, channel string) (res string) { |
|
g.Try(ctx, func(ctx context.Context) { |
|
model := dao.GameVersion.Ctx(ctx) |
|
model = model.Where("channel=? ", channel) |
|
var noticeList []*entity.GameVersion |
|
_ = model.Scan(¬iceList) |
|
var count = len(noticeList) |
|
if count == 0 { |
|
model = dao.GameVersion.Ctx(ctx) |
|
model = model.Where("channel=? ", "") |
|
_ = model.Scan(¬iceList) |
|
} |
|
res = noticeList[0].Version |
|
}) |
|
return |
|
}
|
|
|