fix(activity): skip zero heat gift growth events

This commit is contained in:
zhx 2026-06-26 15:17:53 +08:00
parent bea9dcf1dd
commit 0039c7f2ee
2 changed files with 39 additions and 1 deletions

View File

@ -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

View File

@ -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")