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.
86 lines
2.5 KiB
86 lines
2.5 KiB
package serviceGame |
|
|
|
import ( |
|
"context" |
|
"github.com/gogf/gf/v2/database/gdb" |
|
"github.com/gogf/gf/v2/frame/g" |
|
"github.com/gogf/gf/v2/util/gconv" |
|
"tyj_admin/api/v1/game" |
|
"tyj_admin/internal/consts" |
|
"tyj_admin/internal/dao" |
|
"tyj_admin/internal/model/do" |
|
"tyj_admin/library/liberr" |
|
) |
|
|
|
type IGameCustom interface { |
|
List(ctx context.Context, req *game.BugListReq) (res *game.BugListRes, err error) |
|
Add(ctx context.Context, req *game.BugAddReq) (res *game.BugAddRes, err error) |
|
UpdateState(ctx context.Context, req *game.OperateBugReq) (res *game.OperateBugRes, err error) |
|
} |
|
|
|
type gameCustomImpl struct { |
|
} |
|
|
|
func (c gameCustomImpl) UpdateState(ctx context.Context, req *game.OperateBugReq) (res *game.OperateBugRes, err error) { |
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { |
|
err = g.Try(ctx, func(ctx context.Context) { |
|
_, err = dao.GameBug.Ctx(ctx).TX(tx).WherePri(req.Id).Update(do.GameBug{State: 1}) |
|
}) |
|
return err |
|
}) |
|
return |
|
} |
|
|
|
func (c gameCustomImpl) List(ctx context.Context, req *game.BugListReq) (res *game.BugListRes, err error) { |
|
res = new(game.BugListRes) |
|
g.Try(ctx, func(ctx context.Context) { |
|
model := dao.GameBug.Ctx(ctx) |
|
if req.State != 0 { |
|
model = model.Where("state=", gconv.Int(req.State-1)) |
|
} |
|
if req.LowTime != 0 { |
|
model = model.Where("occurrenceTime>", req.LowTime/1000) |
|
} |
|
if req.UpTime != 0 { |
|
model = model.Where("occurrenceTime<", req.UpTime/1000) |
|
} |
|
res.Total, err = model.Count() |
|
liberr.ErrIsNil(ctx, err, "获取BUG数据失败") |
|
if req.PageNum == 0 { |
|
req.PageNum = 1 |
|
} |
|
res.CurrentPage = req.PageNum |
|
if req.PageSize == 0 { |
|
req.PageSize = consts.PageSize |
|
} |
|
err = model.Page(res.CurrentPage, req.PageSize).Order("id asc").Scan(&res.Bugs) |
|
liberr.ErrIsNil(ctx, err, "获取bug数据失败") |
|
}) |
|
return |
|
} |
|
|
|
func (c gameCustomImpl) Add(ctx context.Context, req *game.BugAddReq) (res *game.BugAddRes, err error) { |
|
err = g.DB().Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error { |
|
err = g.Try(ctx, func(ctx context.Context) { |
|
_, err = dao.GameBug.Ctx(ctx).TX(tx).InsertAndGetId(do.GameBug{ |
|
Uid: req.Uid, |
|
Server: req.Server, |
|
Qq: req.Qq, |
|
Tel: req.Tel, |
|
Bug: req.Bug, |
|
CreateTime: req.CreateTime, |
|
OccurrenceTime: req.OccurrenceTime, |
|
State: req.State, |
|
}) |
|
|
|
}) |
|
return err |
|
}) |
|
return |
|
} |
|
|
|
var customMailService = gameCustomImpl{} |
|
|
|
func GameCustom() IGameCustom { |
|
return &customMailService |
|
}
|
|
|