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.
60 lines
1.5 KiB
60 lines
1.5 KiB
package internal |
|
|
|
import ( |
|
"context" |
|
"tyj_admin/api/v1/game" |
|
"tyj_admin/internal/dao" |
|
"tyj_admin/internal/model/do" |
|
"tyj_admin/internal/model/entity" |
|
"tyj_admin/library/liberr" |
|
) |
|
|
|
func GetBlackListByPage(ctx context.Context, req *game.GetListBlackListReq) (res *game.GetListBlackListRes, err error) { |
|
res = new(game.GetListBlackListRes) |
|
model := dao.GameBlackList.Ctx(ctx) |
|
res.Total, err = model.Count() |
|
model = model.Page(req.PageNum, req.PageSize) |
|
err = model.Scan(&res.WhiteList) |
|
return |
|
} |
|
|
|
func UpdateBlackList(ctx context.Context, req *game.UpdateBlackListReq) (res *game.UpdateBlackListRes, err error) { |
|
model := dao.GameBlackList.Ctx(ctx) |
|
var list []*entity.GameBlackList |
|
err = model.Where("ip=? ", req.Ip).Scan(&list) |
|
if err != nil { |
|
return |
|
} |
|
|
|
if len(list) > 0 { |
|
return |
|
} else { |
|
if req.Id > 0 { |
|
_, err = model.Where("id=", req.Id).Data(&do.GameBlackList{Ip: req.Ip}).Update() |
|
} |
|
_, err = model.Insert(&do.GameBlackList{Ip: req.Ip}) |
|
} |
|
|
|
return |
|
} |
|
|
|
func DelBlackList(ctx context.Context, req *game.DelBlackListReq) (res *game.DelBlackListRes, err error) { |
|
if req.Ip == "" { |
|
liberr.ErrIsNil(ctx, err, "错误的id") |
|
return |
|
} |
|
_, e := dao.GameBlackList.Ctx(ctx).Where("ip=?", req.Ip).Delete() |
|
if e != nil { |
|
liberr.ErrIsNil(ctx, e, "删除白名单失败") |
|
return |
|
} |
|
|
|
return |
|
} |
|
|
|
func GetBlackList(ctx context.Context) (list []*entity.GameBlackList, err error) { |
|
model := dao.GameBlackList.Ctx(ctx) |
|
list = []*entity.GameBlackList{} |
|
err = model.Scan(&list) |
|
return |
|
}
|
|
|