fix(distribution): 货架加价打通前台、下单与卖方分成
分站公开列表和详情展示当前货架加价;下单写入 base_price / shelf_markup / markup_site_id 快照并计入实付。 支付分账改用快照加价,不再误用 PlatformFeeCent;结账不退加价,事后改价不影响历史订单。
This commit is contained in:
@@ -31,6 +31,9 @@ func (r *Repository) ListPublic(ctx context.Context, query PublicListQuery) (*Pu
|
||||
return nil, err
|
||||
}
|
||||
items := publicListings(rowsToDTO(rows))
|
||||
if err := r.applyShelfMarkup(ctx, query.DistributionSiteCode, items); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
baseQuery := query
|
||||
baseQuery.Zone = ""
|
||||
items = filterPublicListings(items, baseQuery)
|
||||
@@ -228,15 +231,63 @@ func copyPublicZoneCounts(counts map[string]int64) map[string]int64 {
|
||||
return copied
|
||||
}
|
||||
|
||||
func (r *Repository) FindPublic(ctx context.Context, id uint64) (*ListingDTO, error) {
|
||||
func (r *Repository) FindPublic(ctx context.Context, id uint64, siteCode string) (*ListingDTO, error) {
|
||||
dto, err := r.findDTO(ctx, "l.id = ? AND l.status = ? AND l.review_status = ? AND l.in_transaction = ?", id, "published", "approved", false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
applyPublicListingURLs(dto)
|
||||
markups, err := r.shelfMarkupByListingID(ctx, siteCode, []uint64{dto.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto.PriceCent += markups[dto.ID]
|
||||
return dto, nil
|
||||
}
|
||||
|
||||
func (r *Repository) applyShelfMarkup(ctx context.Context, siteCode string, items []ListingDTO) error {
|
||||
if siteCode == "" || len(items) == 0 {
|
||||
return nil
|
||||
}
|
||||
ids := make([]uint64, 0, len(items))
|
||||
for _, item := range items {
|
||||
ids = append(ids, item.ID)
|
||||
}
|
||||
markups, err := r.shelfMarkupByListingID(ctx, siteCode, ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range items {
|
||||
items[i].PriceCent += markups[items[i].ID]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) shelfMarkupByListingID(ctx context.Context, siteCode string, listingIDs []uint64) (map[uint64]int64, error) {
|
||||
result := make(map[uint64]int64, len(listingIDs))
|
||||
if siteCode == "" || len(listingIDs) == 0 {
|
||||
return result, nil
|
||||
}
|
||||
type markupRow struct {
|
||||
ListingID uint64 `gorm:"column:listing_id"`
|
||||
MarkupAmountCent int64 `gorm:"column:markup_amount_cent"`
|
||||
}
|
||||
var rows []markupRow
|
||||
if err := r.db.WithContext(ctx).Table("distribution_site_accounts AS dsa").
|
||||
Select("dsa.listing_id, COALESCE(dsa.markup_amount_cent, 0) AS markup_amount_cent").
|
||||
Joins("INNER JOIN distribution_sites AS ds ON ds.id = dsa.site_id AND ds.site_code = ? AND ds.status = 'active'", siteCode).
|
||||
Where("dsa.display_status = 'enabled' AND dsa.listing_id IN ?", listingIDs).
|
||||
Scan(&rows).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, row := range rows {
|
||||
if row.MarkupAmountCent > 0 {
|
||||
result[row.ListingID] = row.MarkupAmountCent
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *Repository) FindPublicCoverKey(ctx context.Context, id uint64) (string, error) {
|
||||
return r.FindPublicScreenshotKey(ctx, id, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user