275 lines
8.6 KiB
Go
275 lines
8.6 KiB
Go
package luckygift
|
||
|
||
const (
|
||
DefaultPoolID = "default"
|
||
|
||
StatusDraft = "draft"
|
||
StatusActive = "active"
|
||
StatusPaused = "paused"
|
||
StatusClosed = "closed"
|
||
StatusPending = "pending"
|
||
StatusGranted = "granted"
|
||
StatusFailed = "failed"
|
||
|
||
PoolNovice = "novice"
|
||
PoolIntermediate = "intermediate"
|
||
PoolAdvanced = "advanced"
|
||
|
||
StageNovice = "novice"
|
||
StageNormal = "normal"
|
||
StageAdvanced = "advanced"
|
||
|
||
EventTypeLuckyGiftDrawn = "LuckyGiftDrawn"
|
||
EventTypeLuckyGiftRewardSettlement = "LuckyGiftRewardSettlement"
|
||
EventTypeExternalLuckyGiftDrawn = "ExternalLuckyGiftDrawn"
|
||
)
|
||
|
||
// Tier 是单个体验池里的候选奖档;权重只塑造体验节奏,基础成本仍由 RTP 窗口兜住。
|
||
type Tier struct {
|
||
Pool string `json:"pool"`
|
||
TierID string `json:"tier_id"`
|
||
RewardCoins int64 `json:"reward_coins"`
|
||
MultiplierPPM int64 `json:"multiplier_ppm"`
|
||
Weight int64 `json:"weight"`
|
||
HighWaterOnly bool `json:"high_water_only"`
|
||
Enabled bool `json:"enabled"`
|
||
}
|
||
|
||
// Config 是幸运礼物线上规则快照。金额均为整数金币,比例均为 ppm。
|
||
type Config struct {
|
||
AppCode string `json:"app_code"`
|
||
GiftID string `json:"gift_id"`
|
||
PoolID string `json:"pool_id"`
|
||
Enabled bool `json:"enabled"`
|
||
RuleVersion int64 `json:"rule_version"`
|
||
GiftPrice int64 `json:"gift_price"`
|
||
TargetRTPPPM int64 `json:"target_rtp_ppm"`
|
||
PoolRatePPM int64 `json:"pool_rate_ppm"`
|
||
ControlBandPPM int64 `json:"control_band_ppm"`
|
||
GlobalWindowDraws int64 `json:"global_window_draws"`
|
||
GiftWindowDraws int64 `json:"gift_window_draws"`
|
||
NoviceMaxEquivalentDraws int64 `json:"novice_max_equivalent_draws"`
|
||
NormalMaxEquivalentDraws int64 `json:"normal_max_equivalent_draws"`
|
||
HighMultiplier int64 `json:"high_multiplier"`
|
||
HighWaterPoolMultiple int64 `json:"high_water_pool_multiple"`
|
||
InitialBasePool int64 `json:"initial_base_pool"`
|
||
BasePoolReserve int64 `json:"base_pool_reserve"`
|
||
MultiplierPPMs []int64 `json:"multiplier_ppms"`
|
||
Tiers []Tier `json:"tiers"`
|
||
UpdatedByAdminID int64 `json:"updated_by_admin_id"`
|
||
CreatedAtMS int64 `json:"created_at_ms"`
|
||
UpdatedAtMS int64 `json:"updated_at_ms"`
|
||
}
|
||
|
||
// RuleTier 是 v2 配置契约里的阶段奖档。倍率和概率在服务端内部统一用 ppm 保存。
|
||
type RuleTier struct {
|
||
Stage string `json:"stage"`
|
||
TierID string `json:"tier_id"`
|
||
MultiplierPPM int64 `json:"multiplier_ppm"`
|
||
BaseWeightPPM int64 `json:"base_weight_ppm"`
|
||
HighWaterOnly bool `json:"high_water_only"`
|
||
Enabled bool `json:"enabled"`
|
||
}
|
||
|
||
// RuleStage 保存某个用户阶段的完整奖档概率。每个阶段的基础概率必须合计 1000000。
|
||
type RuleStage struct {
|
||
Stage string `json:"stage"`
|
||
Tiers []RuleTier `json:"tiers"`
|
||
}
|
||
|
||
// RuleConfig 是幸运礼物 v2 配置版本快照。比例和倍率均为 ppm,业务单位转换发生在发布入口。
|
||
type RuleConfig struct {
|
||
AppCode string `json:"app_code"`
|
||
PoolID string `json:"pool_id"`
|
||
RuleVersion int64 `json:"rule_version"`
|
||
Enabled bool `json:"enabled"`
|
||
TargetRTPPPM int64 `json:"target_rtp_ppm"`
|
||
PoolRatePPM int64 `json:"pool_rate_ppm"`
|
||
SettlementWindowWager int64 `json:"settlement_window_wager"`
|
||
ControlBandPPM int64 `json:"control_band_ppm"`
|
||
GiftPriceReference int64 `json:"gift_price_reference"`
|
||
NoviceMaxEquivalentDraws int64 `json:"novice_max_equivalent_draws"`
|
||
NormalMaxEquivalentDraws int64 `json:"normal_max_equivalent_draws"`
|
||
EffectiveFromMS int64 `json:"effective_from_ms"`
|
||
CreatedByAdminID int64 `json:"created_by_admin_id"`
|
||
CreatedAtMS int64 `json:"created_at_ms"`
|
||
Stages []RuleStage `json:"stages"`
|
||
}
|
||
|
||
type CheckCommand struct {
|
||
PoolID string
|
||
GiftID string
|
||
UserID int64
|
||
RoomID string
|
||
}
|
||
|
||
type DrawCommand struct {
|
||
CommandID string
|
||
PoolID string
|
||
UserID int64
|
||
TargetUserID int64
|
||
DeviceID string
|
||
RoomID string
|
||
AnchorID string
|
||
GiftID string
|
||
GiftCount int32
|
||
CoinSpent int64
|
||
PaidAtMS int64
|
||
VisibleRegionID int64
|
||
CountryID int64
|
||
// Sender* 是扣费时刻的公开展示快照;owner outbox 必须携带快照,避免下游为一条飘屏同步反查 user-service。
|
||
SenderName string
|
||
SenderAvatar string
|
||
SenderDisplayUserID string
|
||
SenderPrettyDisplayUserID string
|
||
}
|
||
|
||
type CheckResult struct {
|
||
Enabled bool
|
||
Reason string
|
||
PoolID string
|
||
GiftID string
|
||
GiftPrice int64
|
||
RuleVersion int64
|
||
TargetRTPPPM int64
|
||
ExperiencePool string
|
||
}
|
||
|
||
type DrawResult struct {
|
||
DrawID string
|
||
DrawIDs []string
|
||
CommandID string
|
||
AppCode string
|
||
UserID int64
|
||
ExternalUserID string
|
||
PoolID string
|
||
GiftID string
|
||
RuleVersion int64
|
||
ExperiencePool string
|
||
SelectedTierID string
|
||
MultiplierPPM int64
|
||
BaseRewardCoins int64
|
||
EffectiveRewardCoins int64
|
||
RewardStatus string
|
||
RTPWindowIndex int64
|
||
GiftRTPWindowIndex int64
|
||
GlobalBaseRTPPPM int64
|
||
GiftBaseRTPPPM int64
|
||
StageFeedback bool
|
||
HighMultiplier bool
|
||
CreatedAtMS int64
|
||
WalletTransactionID string
|
||
CoinBalanceAfter int64
|
||
// Hits 只保留 gift_count 批量中的中奖子抽,避免为了连击表现把所有 999 条审计记录塞进同步响应。
|
||
Hits []DrawHit
|
||
}
|
||
|
||
type DrawHit struct {
|
||
GiftIndex int32
|
||
DrawID string
|
||
SelectedTierID string
|
||
MultiplierPPM int64
|
||
RewardCoins int64
|
||
}
|
||
|
||
type DrawSummary struct {
|
||
PoolID string
|
||
TotalDraws int64
|
||
UniqueUsers int64
|
||
UniqueRooms int64
|
||
TotalSpentCoins int64
|
||
TotalRewardCoins int64
|
||
BaseRewardCoins int64
|
||
ActualRTPPPM int64
|
||
PendingDraws int64
|
||
GrantedDraws int64
|
||
FailedDraws int64
|
||
}
|
||
|
||
// PoolBalance 是后台看到的 app+pool_id 单池账本快照。
|
||
// materialized=false 表示该池还没有真实 lucky_pools 行,展示的是规则默认初始水位,不能当成已经入库的资金流水。
|
||
type PoolBalance struct {
|
||
AppCode string
|
||
PoolID string
|
||
Balance int64
|
||
ReserveFloor int64
|
||
AvailableBalance int64
|
||
TotalIn int64
|
||
TotalOut int64
|
||
Materialized bool
|
||
UpdatedAtMS int64
|
||
}
|
||
|
||
type PoolBalanceQuery struct {
|
||
AppCode string
|
||
PoolID string
|
||
}
|
||
|
||
type AdminConfigQuery struct {
|
||
PoolID string
|
||
}
|
||
|
||
type DrawQuery struct {
|
||
AppCode string
|
||
PoolID string
|
||
GiftID string
|
||
UserID int64
|
||
RoomID string
|
||
Status string
|
||
Page int32
|
||
PageSize int32
|
||
// ExternalUserID 只用于外部 App 接入流水查询;内部房间抽奖不会填这个字段。
|
||
ExternalUserID string
|
||
ExternalOnly bool
|
||
}
|
||
|
||
// ExternalDrawCommand 是外部 App “已扣费后请求抽奖”的业务事实。
|
||
// HyApp 不接管外部 App 余额,因此这里没有 target_user_id、room_id 或 wallet command_id;幂等边界固定为
|
||
// app_code + request_id,任何重试都必须返回同一条抽奖结果。
|
||
type ExternalDrawCommand struct {
|
||
AppCode string
|
||
ExternalUserID string
|
||
RequestID string
|
||
GiftCount int64
|
||
UnitAmount int64
|
||
TotalAmount int64
|
||
Currency string
|
||
PaidAtMS int64
|
||
MetadataJSON string
|
||
PoolID string
|
||
}
|
||
|
||
// ExternalDrawResult 是返回给外部 App 的最终抽奖结果。
|
||
// reward_status=granted 表示 HyApp 已完成抽奖审计并把 reward_amount 交给调用方处理;它不代表 HyApp wallet 入账。
|
||
type ExternalDrawResult struct {
|
||
DrawID string
|
||
RequestID string
|
||
AppCode string
|
||
ExternalUserID string
|
||
GiftCount int64
|
||
UnitAmount int64
|
||
TotalAmount int64
|
||
RewardAmount int64
|
||
MultiplierPPM int64
|
||
RewardStatus string
|
||
RuleVersion int64
|
||
CreatedAtMS int64
|
||
}
|
||
|
||
// DrawOutbox 是幸运礼物抽奖事务写出的异步副作用载体,worker 只消费这个持久事实。
|
||
type DrawOutbox struct {
|
||
AppCode string
|
||
OutboxID string
|
||
EventType string
|
||
PayloadJSON string
|
||
RetryCount int
|
||
CreatedAtMS int64
|
||
}
|
||
|
||
type DrawRewardState struct {
|
||
AllGranted bool
|
||
WalletTransactionID string
|
||
// RewardGrantedAtMS 取 granted draw 的稳定 updated_at_ms;owner MQ 重投必须保持同一事实正文不漂移。
|
||
RewardGrantedAtMS int64
|
||
}
|