refactor(distribution): 重写分销迁移并落地利润百分比分成与货架比例
将 000064-000078 合并为 064/065/066,默认规则改为收号 35%、卖出 40%、服务费 25%。 货架调价改为增加分站 1 元兑换哈夫币比例。sql-guard 仅保护 main 已发布迁移。
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/chat"
|
||||
"hfb_sys/backend/internal/modules/distribution"
|
||||
listingpkg "hfb_sys/backend/internal/modules/listing"
|
||||
"hfb_sys/backend/internal/modules/notification"
|
||||
"hfb_sys/backend/internal/modules/rentergrowth"
|
||||
"hfb_sys/backend/internal/processlog"
|
||||
@@ -58,14 +59,28 @@ func (r *Repository) Create(ctx context.Context, renterID uint64, req CreateRequ
|
||||
return err
|
||||
}
|
||||
rentHours := estimateOrderDurationHours(snapshot)
|
||||
shelfMarkupCent, markupSiteID, err := loadShelfMarkupTx(tx, req.DistributionSiteCode, listing.ID)
|
||||
shelfRatioDelta, markupSiteID, err := loadShelfRatioTx(tx, req.DistributionSiteCode, listing.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pricing := buildOrderPricing(listing, account)
|
||||
basePriceCent := listing.PriceCent
|
||||
if shelfMarkupCent > 0 {
|
||||
pricing.RentAmountCent += shelfMarkupCent
|
||||
sitePriceCent, _, siteRatio := listingpkg.ApplyShelfRatio(account.HafCoinAmount, listing.PriceCent, shelfRatioDelta)
|
||||
shelfMarkupCent := sitePriceCent - basePriceCent
|
||||
if sitePriceCent != listing.PriceCent {
|
||||
pricing.RentAmountCent = sitePriceCent
|
||||
if pricing.OwnerRentAmountCent > pricing.RentAmountCent {
|
||||
pricing.OwnerRentAmountCent = pricing.RentAmountCent
|
||||
}
|
||||
pricing.PlatformFeeCent = maxCent(pricing.RentAmountCent-pricing.OwnerRentAmountCent, 0)
|
||||
if pricing.ExtraItemAmountCent > pricing.RentAmountCent {
|
||||
pricing.ExtraItemAmountCent = pricing.RentAmountCent
|
||||
}
|
||||
pricing.PureCoinAmountCent = maxCent(pricing.RentAmountCent-pricing.ExtraItemAmountCent, 0)
|
||||
if pricing.OwnerPureCoinAmountCent > pricing.OwnerRentAmountCent {
|
||||
pricing.OwnerPureCoinAmountCent = pricing.OwnerRentAmountCent
|
||||
}
|
||||
pricing.PureCoinPlatformFeeCent = maxCent(pricing.PureCoinAmountCent-pricing.OwnerPureCoinAmountCent, 0)
|
||||
}
|
||||
distributionSite, distributionRule, err := distribution.ResolveOrderSourceTx(tx, req.DistributionSiteCode, listing.ID, account.ID, time.Now())
|
||||
if err != nil {
|
||||
@@ -116,6 +131,8 @@ func (r *Repository) Create(ctx context.Context, renterID uint64, req CreateRequ
|
||||
BasePriceCent: basePriceCent,
|
||||
ShelfMarkupCent: shelfMarkupCent,
|
||||
MarkupSiteID: markupSiteID,
|
||||
ShelfRatio: siteRatio,
|
||||
ShelfRatioDelta: shelfRatioDelta,
|
||||
RentOriginalAmountCent: rentOriginalAmountCent,
|
||||
RentDiscountAmountCent: rentDiscountAmountCent,
|
||||
PureCoinOriginalAmountCent: pricing.PureCoinAmountCent,
|
||||
@@ -168,17 +185,17 @@ func (r *Repository) Create(ctx context.Context, renterID uint64, req CreateRequ
|
||||
return r.FindForUser(ctx, renterID, createdID)
|
||||
}
|
||||
|
||||
func loadShelfMarkupTx(tx *gorm.DB, siteCode string, listingID uint64) (int64, uint64, error) {
|
||||
func loadShelfRatioTx(tx *gorm.DB, siteCode string, listingID uint64) (float64, uint64, error) {
|
||||
siteCode = strings.TrimSpace(siteCode)
|
||||
if siteCode == "" || listingID == 0 {
|
||||
return 0, 0, nil
|
||||
}
|
||||
var row struct {
|
||||
SiteID uint64 `gorm:"column:site_id"`
|
||||
Markup int64 `gorm:"column:markup"`
|
||||
SiteID uint64 `gorm:"column:site_id"`
|
||||
Delta float64 `gorm:"column:delta"`
|
||||
}
|
||||
err := tx.Table("distribution_site_accounts AS dsa").
|
||||
Select("dsa.site_id, COALESCE(dsa.markup_amount_cent, 0) AS markup").
|
||||
Select("dsa.site_id, COALESCE(dsa.shelf_ratio_delta, 0) AS delta").
|
||||
Joins("INNER JOIN distribution_sites AS ds ON ds.id = dsa.site_id AND ds.site_code = ? AND ds.status = 'active'", siteCode).
|
||||
Where("dsa.listing_id = ? AND dsa.display_status = 'enabled'", listingID).
|
||||
Take(&row).Error
|
||||
@@ -188,10 +205,10 @@ func loadShelfMarkupTx(tx *gorm.DB, siteCode string, listingID uint64) (int64, u
|
||||
}
|
||||
return 0, 0, err
|
||||
}
|
||||
if row.Markup < 0 {
|
||||
row.Markup = 0
|
||||
if row.Delta < 0 {
|
||||
row.Delta = 0
|
||||
}
|
||||
return row.Markup, row.SiteID, nil
|
||||
return row.Delta, row.SiteID, nil
|
||||
}
|
||||
|
||||
func orderAccountSourceSnapshot(tx *gorm.DB, listingID uint64) (string, string, error) {
|
||||
|
||||
Reference in New Issue
Block a user