From 0039c7f2eec49808b025e9bd51b1efaba03cd3dd Mon Sep 17 00:00:00 2001 From: zhx Date: Fri, 26 Jun 2026 15:17:53 +0800 Subject: [PATCH] fix(activity): skip zero heat gift growth events --- .../internal/service/growth/service.go | 6 +++- .../internal/service/growth/service_test.go | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/services/activity-service/internal/service/growth/service.go b/services/activity-service/internal/service/growth/service.go index 16cca09c..e3538d66 100644 --- a/services/activity-service/internal/service/growth/service.go +++ b/services/activity-service/internal/service/growth/service.go @@ -260,9 +260,13 @@ func (s *Service) HandleRoomEvent(ctx context.Context, envelope *roomeventsv1.Ev if gift.GetIsRobotGift() { return 0, nil } - if gift.GetSenderUserId() <= 0 || gift.GetTargetUserId() <= 0 || gift.GetGiftValue() <= 0 { + if gift.GetSenderUserId() <= 0 || gift.GetTargetUserId() <= 0 || gift.GetGiftValue() < 0 { return 0, xerr.New(xerr.InvalidArgument, "room gift event is incomplete") } + if gift.GetGiftValue() == 0 { + // 低价幸运礼物按房间贡献比例折算后可能为 0;这是合法结算结果,增长服务只确认事件并跳过等级增量。 + return 0, nil + } dimensions, err := roomGiftDimensions(envelope, &gift) if err != nil { return 0, err diff --git a/services/activity-service/internal/service/growth/service_test.go b/services/activity-service/internal/service/growth/service_test.go index be5e2d25..2898a6e3 100644 --- a/services/activity-service/internal/service/growth/service_test.go +++ b/services/activity-service/internal/service/growth/service_test.go @@ -138,6 +138,40 @@ func TestGrowthRoomGiftEventFeedsWealthAndCharm(t *testing.T) { } } +func TestGrowthRoomGiftEventSkipsZeroGiftValue(t *testing.T) { + svc, _ := newGrowthService(t) + ctx := appcode.WithContext(context.Background(), "lalu") + + body, err := proto.Marshal(&activityevents.RoomGiftSent{ + SenderUserId: 20001, + TargetUserId: 20002, + GiftId: "gift-zero-heat", + GiftCount: 1, + GiftValue: 0, + BillingReceiptId: "bill-zero-heat", + VisibleRegionId: 86, + CommandId: "cmd-gift-zero-heat", + }) + if err != nil { + t.Fatalf("marshal zero heat room gift failed: %v", err) + } + consumed, err := svc.HandleRoomEvent(ctx, &activityevents.EventEnvelope{ + EventId: "room-gift-event-zero-heat", + RoomId: "room-1", + EventType: "RoomGiftSent", + RoomVersion: 8, + OccurredAtMs: fixedGrowthNow().UnixMilli(), + Body: body, + AppCode: "lalu", + }) + if err != nil { + t.Fatalf("zero heat RoomGiftSent should be accepted and skipped: %v", err) + } + if consumed != 0 { + t.Fatalf("zero heat RoomGiftSent should not create growth events, consumed=%d", consumed) + } +} + func TestListLevelConfigReturnsAdminRulesAndTiers(t *testing.T) { svc, _ := newGrowthService(t) ctx := appcode.WithContext(context.Background(), "lalu")