refactor(listing): 卖家发布定价改用整数分与基点
This commit is contained in:
@@ -28,14 +28,37 @@ type ReceivePricingView struct {
|
||||
func ReceivePricingFromAssetSummary(raw datatypes.JSON) ReceivePricingView {
|
||||
summary := decodeAssetSummary(raw)
|
||||
breakdown := ensurePriceBreakdown(summary)
|
||||
sellerTotal := readSummaryNumber(breakdown["seller_total_price"])
|
||||
return ReceivePricingView{
|
||||
SellerRatio: readSummaryNumber(breakdown["seller_ratio"]),
|
||||
SellerTotalPriceCent: yuanToCent(sellerTotal),
|
||||
BuyerRatio: readSummaryNumber(breakdown["buyer_ratio"]),
|
||||
SellerRatio: summaryRatio(breakdown, "seller_ratio_bps", "seller_ratio"),
|
||||
SellerTotalPriceCent: summaryMoneyCent(breakdown, "seller_total_price_cent", "seller_total_price"),
|
||||
BuyerRatio: summaryRatio(breakdown, "buyer_ratio_bps", "buyer_ratio"),
|
||||
}
|
||||
}
|
||||
|
||||
func summaryMoneyCent(breakdown map[string]any, centKey, yuanKey string) int64 {
|
||||
if breakdown == nil {
|
||||
return 0
|
||||
}
|
||||
if cent := readSummaryInt64(breakdown[centKey]); cent > 0 {
|
||||
return cent
|
||||
}
|
||||
return centFromYuanFloat(readSummaryNumber(breakdown[yuanKey]))
|
||||
}
|
||||
|
||||
func summaryBPS(breakdown map[string]any, bpsKey, ratioKey string) int64 {
|
||||
if breakdown == nil {
|
||||
return 0
|
||||
}
|
||||
if bps := readSummaryInt64(breakdown[bpsKey]); bps > 0 {
|
||||
return bps
|
||||
}
|
||||
return ratioToBPS(readSummaryNumber(breakdown[ratioKey]))
|
||||
}
|
||||
|
||||
func summaryRatio(breakdown map[string]any, bpsKey, ratioKey string) float64 {
|
||||
return bpsToRatio(summaryBPS(breakdown, bpsKey, ratioKey))
|
||||
}
|
||||
|
||||
func (s *Service) applyMainSiteReceivePricing(ctx context.Context, req *CreateRequest, receiveRatioDelta, receiveCostDelta float64, onDistributionSite bool) error {
|
||||
if req == nil {
|
||||
return nil
|
||||
@@ -60,58 +83,76 @@ func applyMainSiteReceivePricing(req *CreateRequest, options systemconfig.Publis
|
||||
if req.AssetSummary == nil {
|
||||
req.AssetSummary = map[string]any{}
|
||||
}
|
||||
coinM := coinMFromHafCoinAmount(req.HafCoinAmount)
|
||||
referenceRatio := calculateSellerReferenceRatio(coinM, req.AssetSummary, options)
|
||||
if referenceRatio <= 0 {
|
||||
referenceRatioBPS := calculateSellerReferenceRatioBPS(req.HafCoinAmount, req.AssetSummary, options)
|
||||
if referenceRatioBPS <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
breakdown := ensurePriceBreakdown(req.AssetSummary)
|
||||
requestedRatio := readSummaryNumber(breakdown["seller_ratio"])
|
||||
if requestedRatio <= 0 {
|
||||
requestedRatio = readSummaryNumber(breakdown["accelerated_sale_ratio"])
|
||||
requestedRatioBPS := summaryBPS(breakdown, "seller_ratio_bps", "seller_ratio")
|
||||
if requestedRatioBPS <= 0 {
|
||||
requestedRatioBPS = summaryBPS(breakdown, "accelerated_sale_ratio_bps", "accelerated_sale_ratio")
|
||||
}
|
||||
costDelta := NormalizeSiteReceiveCostDelta(receiveCostDelta)
|
||||
ratioDelta := NormalizeSiteReceiveRatioDelta(receiveRatioDelta)
|
||||
sellerRatio := clampSaleRatio(referenceRatio, requestedRatio)
|
||||
sellerRatioBPS := clampSaleRatioBPS(referenceRatioBPS, requestedRatioBPS)
|
||||
// 分站新口径:收号比例 = R + 压价点数(收号价更低),买家定价锚定主站参考比例 R,不随收号价联动。
|
||||
if onDistributionSite {
|
||||
sellerRatio = ApplySiteReceiveCostDelta(referenceRatio, costDelta)
|
||||
sellerRatioBPS = applySiteReceiveCostDeltaBPS(referenceRatioBPS, costDelta)
|
||||
}
|
||||
coinWan := coinM * 100
|
||||
sellerCoinBasePrice := roundMoney(coinWan / sellerRatio)
|
||||
consumablePrice := consumableValue(req.AssetSummary)
|
||||
sellerTotalPrice := roundMoney(sellerCoinBasePrice + consumablePrice)
|
||||
dailyLoss := readSummaryNumber(req.AssetSummary["daily_loss_m"])
|
||||
sellerCoinBasePriceCent := sellerCoinBasePriceCentFromHafCoin(req.HafCoinAmount, sellerRatioBPS)
|
||||
consumablePriceCent := consumableValueCent(req.AssetSummary, options.QuantityItems)
|
||||
sellerTotalPriceCent := sellerCoinBasePriceCent + consumablePriceCent
|
||||
// 主站买家价仍跟 sellerRatio(含加速出售);分站买家价锚定 R,压价差进入三方分成池。
|
||||
buyerAnchorRatio := sellerRatio
|
||||
buyerAnchorCoinBase := sellerCoinBasePrice
|
||||
buyerAnchorRatioBPS := sellerRatioBPS
|
||||
buyerAnchorCoinBasePriceCent := sellerCoinBasePriceCent
|
||||
if onDistributionSite {
|
||||
buyerAnchorRatio = referenceRatio
|
||||
buyerAnchorCoinBase = referenceSellerCoinBasePrice(coinWan, referenceRatio)
|
||||
buyerAnchorRatioBPS = referenceRatioBPS
|
||||
buyerAnchorCoinBasePriceCent = sellerCoinBasePriceCentFromHafCoin(req.HafCoinAmount, referenceRatioBPS)
|
||||
}
|
||||
pricing := calculateExternalPlatformPricing(coinM, buyerAnchorRatio, buyerAnchorCoinBase, consumablePrice, config)
|
||||
breakdown["seller_reference_ratio"] = referenceRatio
|
||||
breakdown["seller_ratio"] = sellerRatio
|
||||
breakdown["seller_coin_base_price"] = sellerCoinBasePrice
|
||||
breakdown["seller_total_price"] = sellerTotalPrice
|
||||
breakdown["consumable_price"] = consumablePrice
|
||||
breakdown["daily_loss_ratio_adjustment"] = calculateDailyLossRatioAdjustment(dailyLoss)
|
||||
breakdown["accelerated_sale_ratio"] = sellerRatio
|
||||
pricing := calculateExternalPlatformPricingCent(
|
||||
req.HafCoinAmount,
|
||||
buyerAnchorRatioBPS,
|
||||
buyerAnchorCoinBasePriceCent,
|
||||
consumablePriceCent,
|
||||
config,
|
||||
)
|
||||
dailyLossRatioAdjustmentBPS := calculateDailyLossRatioAdjustmentBPS(req.AssetSummary)
|
||||
|
||||
// 规范字段:整数分 + 基点。
|
||||
breakdown["seller_reference_ratio_bps"] = referenceRatioBPS
|
||||
breakdown["seller_ratio_bps"] = sellerRatioBPS
|
||||
breakdown["buyer_ratio_bps"] = pricing.BuyerRatioBPS
|
||||
breakdown["seller_coin_base_price_cent"] = sellerCoinBasePriceCent
|
||||
breakdown["seller_total_price_cent"] = sellerTotalPriceCent
|
||||
breakdown["consumable_price_cent"] = consumablePriceCent
|
||||
breakdown["buyer_coin_base_price_cent"] = pricing.BuyerCoinBasePriceCent
|
||||
breakdown["buyer_total_price_cent"] = pricing.BuyerTotalPriceCent
|
||||
breakdown["platform_markup_amount_cent"] = pricing.PlatformMarkupCent
|
||||
|
||||
// 旧 float 字段:由规范字段一次性派生,供历史前端与历史商品读取。
|
||||
breakdown["seller_reference_ratio"] = bpsToRatio(referenceRatioBPS)
|
||||
breakdown["seller_ratio"] = bpsToRatio(sellerRatioBPS)
|
||||
breakdown["seller_coin_base_price"] = centToYuanFloat(sellerCoinBasePriceCent)
|
||||
breakdown["seller_total_price"] = centToYuanFloat(sellerTotalPriceCent)
|
||||
breakdown["consumable_price"] = centToYuanFloat(consumablePriceCent)
|
||||
breakdown["daily_loss_ratio_adjustment"] = bpsToRatio(dailyLossRatioAdjustmentBPS)
|
||||
breakdown["accelerated_sale_ratio"] = bpsToRatio(sellerRatioBPS)
|
||||
breakdown["accelerated_sale_ratio_bps"] = sellerRatioBPS
|
||||
if onDistributionSite {
|
||||
breakdown["site_receive_cost_delta"] = costDelta
|
||||
breakdown["pricing_model"] = "site_cost_decoupled_v1"
|
||||
} else {
|
||||
breakdown["site_receive_ratio_delta"] = ratioDelta
|
||||
}
|
||||
breakdown["buyer_coin_base_price"] = pricing.BuyerCoinBasePrice
|
||||
breakdown["buyer_total_price"] = pricing.BuyerTotalPrice
|
||||
breakdown["buyer_ratio"] = pricing.BuyerRatio
|
||||
breakdown["platform_markup_amount"] = pricing.PlatformMarkupPrice
|
||||
breakdown["buyer_coin_base_price"] = centToYuanFloat(pricing.BuyerCoinBasePriceCent)
|
||||
breakdown["buyer_total_price"] = centToYuanFloat(pricing.BuyerTotalPriceCent)
|
||||
breakdown["buyer_ratio"] = bpsToRatio(pricing.BuyerRatioBPS)
|
||||
breakdown["platform_markup_amount"] = centToYuanFloat(pricing.PlatformMarkupCent)
|
||||
breakdown["platform_rule_type"] = pricing.RuleType
|
||||
req.AssetSummary["price_breakdown"] = breakdown
|
||||
req.AssetSummary["publish_ratio"] = pricing.BuyerRatio
|
||||
req.PriceCent = yuanToCent(pricing.BuyerTotalPrice)
|
||||
req.AssetSummary["publish_ratio"] = bpsToRatio(pricing.BuyerRatioBPS)
|
||||
req.PriceCent = pricing.BuyerTotalPriceCent
|
||||
}
|
||||
|
||||
// NormalizeSiteReceiveCostDelta 将分站收号压价点数限制在 [0, 20]。
|
||||
|
||||
Reference in New Issue
Block a user