fix(distribution): 货架加价打通前台、下单与卖方分成
分站公开列表和详情展示当前货架加价;下单写入 base_price / shelf_markup / markup_site_id 快照并计入实付。 支付分账改用快照加价,不再误用 PlatformFeeCent;结账不退加价,事后改价不影响历史订单。
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
@@ -57,7 +58,15 @@ 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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pricing := buildOrderPricing(listing, account)
|
||||
basePriceCent := listing.PriceCent
|
||||
if shelfMarkupCent > 0 {
|
||||
pricing.RentAmountCent += shelfMarkupCent
|
||||
}
|
||||
distributionSite, distributionRule, err := distribution.ResolveOrderSourceTx(tx, req.DistributionSiteCode, listing.ID, account.ID, time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -104,6 +113,9 @@ func (r *Repository) Create(ctx context.Context, renterID uint64, req CreateRequ
|
||||
DepositFreeManualQuotaCent: growthSnapshot.ManualDepositFreeQuotaCent,
|
||||
DepositFreeUsedBeforeCent: depositWaiver.UsedBeforeCent,
|
||||
PlatformFeeCent: pricing.PlatformFeeCent,
|
||||
BasePriceCent: basePriceCent,
|
||||
ShelfMarkupCent: shelfMarkupCent,
|
||||
MarkupSiteID: markupSiteID,
|
||||
RentOriginalAmountCent: rentOriginalAmountCent,
|
||||
RentDiscountAmountCent: rentDiscountAmountCent,
|
||||
PureCoinOriginalAmountCent: pricing.PureCoinAmountCent,
|
||||
@@ -156,6 +168,32 @@ 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) {
|
||||
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"`
|
||||
}
|
||||
err := tx.Table("distribution_site_accounts AS dsa").
|
||||
Select("dsa.site_id, COALESCE(dsa.markup_amount_cent, 0) AS markup").
|
||||
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
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return 0, 0, nil
|
||||
}
|
||||
return 0, 0, err
|
||||
}
|
||||
if row.Markup < 0 {
|
||||
row.Markup = 0
|
||||
}
|
||||
return row.Markup, row.SiteID, nil
|
||||
}
|
||||
|
||||
func orderAccountSourceSnapshot(tx *gorm.DB, listingID uint64) (string, string, error) {
|
||||
var upload model.ListingUpload
|
||||
err := tx.Where("listing_id = ?", listingID).Order("id DESC").First(&upload).Error
|
||||
|
||||
Reference in New Issue
Block a user