package serviceGame import ( "context" "github.com/gogf/gf/v2/frame/g" "tyj_admin/api/v1/game" "tyj_admin/internal/consts" "tyj_admin/internal/serviceGame/internal" "tyj_admin/utils" ) type IGameWhiteList interface { Get(ctx context.Context, req *game.GetListWhiteListReq) (res *game.GetListWhiteListRes, err error) Update(ctx context.Context, req *game.UpdateWhiteListReq) (res *game.UpdateWhiteListRes, err error) Del(ctx context.Context, req *game.DelWhiteListReq) (res *game.DelWhiteListRes, err error) GetWhiteState(ctx context.Context, ip string) (res int) GetWhiteList(ctx context.Context) (res *game.WhiteListRes) } type gameWhiteListImpl struct { } var gameWhiteListService = gameWhiteListImpl{} func GameWhiteList() IGameWhiteList { return &gameWhiteListService } func (c *gameWhiteListImpl) Get(ctx context.Context, req *game.GetListWhiteListReq) (res *game.GetListWhiteListRes, err error) { g.Try(ctx, func(ctx context.Context) { res, err = internal.GetWhiteListByPage(ctx, req) }) return } func (c *gameWhiteListImpl) Update(ctx context.Context, req *game.UpdateWhiteListReq) (res *game.UpdateWhiteListRes, err error) { g.Try(ctx, func(ctx context.Context) { res, err = internal.UpdateWhiteList(ctx, req) if err != nil { panic(err) } }) return } func (c *gameWhiteListImpl) Del(ctx context.Context, req *game.DelWhiteListReq) (res *game.DelWhiteListRes, err error) { //fmt.Println("DelWhiteListReq: ", req) err = g.Try(ctx, func(ctx context.Context) { res, err = internal.DelWhiteList(ctx, req) if err != nil { panic(err) } }) return } func (c *gameWhiteListImpl) GetWhiteState(ctx context.Context, ip string) (res int) { g.Try(ctx, func(ctx context.Context) { list, err := internal.GetWhiteList(ctx) //model := dao.GameWhiteList.Ctx(ctx) //model = model.Where("ip=? ", req.Ip) //var list []*entity.GameWhiteList //err := model.Scan(&list) //if err != nil { // panic(err) //} //lock, err := internal.GetWhiteLock(ctx) if err != nil { panic(err) } //fmt.Println("AddCCD ---》 ip: ", lock) if utils.ContainsWhiteList(list, ip) { res = consts.White_List_Belong return } res = consts.White_List_Not_In return }) return res } func (c *gameWhiteListImpl) GetWhiteList(ctx context.Context) (res *game.WhiteListRes) { g.Try(ctx, func(ctx context.Context) { res = new(game.WhiteListRes) list, _ := internal.GetWhiteList(ctx) for _, v := range list { res.WhiteList = append(res.WhiteList, v.Ip) } }) return }