package mysql import "hyapp/pkg/xerr" // giftPointPolicyAmounts 把一次付费礼物拆成主播 POINT 与 Agency POINT 两个独立账务分量。 // AgencyShareBaseAmount 一并固化到审计流水,避免策略发布后只能看到 20% 却无法证明当时的计算基数。 type giftPointPolicyAmounts struct { HostPointAdded int64 AgencyPointAdded int64 AgencyShareBaseAmount int64 } // calculateGiftPointPolicyAmounts 只处理金额公式,不决定 Agency 资格;owner 快照仍由 gateway 在 // 送礼受理时从 user-service 获取,并由调用方在 owner_id>0 时才真正写 Agency 账。 func calculateGiftPointPolicyAmounts(chargeAmount int64, giftTypeRatio giftDiamondRatioSnapshot, policy walletPolicyInstance) (giftPointPolicyAmounts, error) { if chargeAmount < 0 || giftTypeRatio.PPM < 0 || giftTypeRatio.PPM > 1_000_000 { return giftPointPolicyAmounts{}, xerr.New(xerr.InvalidArgument, "gift point policy amount is invalid") } hostBaseAmount := chargeAmount if policy.HostGiftTypeRatioEnabled { // Fami 的普通/幸运/超级幸运礼物先沿用主播原有 100%/10%/1% 钻石口径;区域覆盖也在 // 调用本函数前由 wallet owner 解析。这里保留两阶段向下取整,严格对应“主播实收后的 20%”。 var err error hostBaseAmount, err = giftDiamondAmount(chargeAmount, giftTypeRatio.PPM) if err != nil { return giftPointPolicyAmounts{}, err } } hostPointAdded, err := giftDiamondAmount(hostBaseAmount, policy.HostPointRatioPPM) if err != nil { return giftPointPolicyAmounts{}, err } agencyShareBaseAmount := chargeAmount switch policy.AgencyPointShareBase { case agencyPointShareBaseChargeAmount: // 旧政策直接从礼物实扣金额切分 Agency POINT,保持已发布 Huwaa/Fami 历史实例兼容。 case agencyPointShareBaseHostIncome: agencyShareBaseAmount = hostPointAdded default: return giftPointPolicyAmounts{}, xerr.New(xerr.InvalidArgument, "wallet policy agency share base is invalid") } agencyPointAdded, err := giftDiamondAmount(agencyShareBaseAmount, policy.AgencyPointRatioPPM) if err != nil { return giftPointPolicyAmounts{}, err } return giftPointPolicyAmounts{ HostPointAdded: hostPointAdded, AgencyPointAdded: agencyPointAdded, AgencyShareBaseAmount: agencyShareBaseAmount, }, nil }