#5036·go-zero

在 mr.Finish 中调用多个函数时发生覆盖错误

作者: phpstudyer创建于 2025年7月29日更新于 2026年9月25日
标签stalekind/need-more-info

go-zero version: 1.8.5 1.8.3 1.8.0 all tried Code: err = mr.Finish( func() error { // Check whether page betting is prohibited forbidBetConfig, err := l.svcCtx.CacheRpc.GetForbidBetConfig(l.ctx, &cache.GetForbidBetConfigReq{ Key: vars.ForbidPageRewardConfigKey, }) if err != nil { return err } if forbidBetConfig.IsForbid { return errors.New("page betting is prohibited") } return nil }, func() error { // Check whether the user is prohibited from page betting user, err := User.WithContext(l.ctx).Where(User.ID.Eq(uid)).First() if err != nil { return errors.New("user does not exist") } if user.ForbidPageBet { return errors.New("user is prohibited from page betting") } return nil }, func() error { // Check whether the game exists game, err := Game.WithContext(l.ctx).Where(Game.ID.Eq(req.GameID)).First() if err != nil { return errors.New("game does not exist") } if game.Status != vars.StatusNormal { return errors.New("game status is abnormal") } return nil }, func() error { // Check whether the round exists round, err := GameRound.WithContext(l.ctx).Where(GameRound.GameID.Eq(req.GameID), GameRound.Round.Eq(req.Round)).First() if err != nil { return errors.New("round does not exist") } if round.Status == vars.GameStatusSettling || round.Status == vars.GameStatusSettled { return errors.New("round is not in the betting range") } return nil }, func() error { // Check whether the betting limit in the round is exceeded betLimitResp, err := l.svcCtx.CacheRpc.GetBetLimit(l.ctx, &cache.GetBetLimitReq{ GameId: req.GameID, }) if err != nil { return err } betLimit := &vars.BetLimitCacheConfigValue{} for k, v := range betLimitResp.BetLimits { betLimit.Set(k, vars.BetLimit{ Min: v.Min, Max: v.Max, }) } return nil }, func() error { // Check whether the current round's bet has reached the limit err = GameRoundJoin.WithContext(l.ctx).Where(GameRoundJoin.GameID.Eq(req.GameID), GameRoundJoin.Round.Eq(req.Round), GameRoundJoin.Symbol.Eq(req.Symbol), GameRoundJoin.JoinType.Eq(vars.GameJoinTypePage), GameRoundJoin.UserID.Eq(uid)).Select(field.NewUnsafeFieldRaw("COALESCE(SUM(amount_int),0)")).Scan(&sum) if err != nil { return errors.New("failed to get the current round's bet amount") } return nil }, func() error { // Check whether the user's wallet exists userWallet, err := UserWallet.WithContext(l.ctx).Where(UserWallet.UserID.Eq(uid), UserWallet.Symbol.Eq(req.Symbol)).First() if err != nil { return errors.New("user wallet does not exist") } return nil }, ), if err != nil { logx.Errorf("CreateGameRoundJoinLogic mr query failed Error: %v", err) logx.Errorf("CreateGameRoundJoinLogic2 mr query failed Error: %v", err) return nil, err } …

内容来源: zeromicro/go-zero