fix(listing): 修复编号序列冲突并按角色隔离价格字段
This commit is contained in:
@@ -57,6 +57,7 @@ func normalizedListingPriceCent(req CreateRequest) int64 {
|
|||||||
func publicListings(items []ListingDTO) []ListingDTO {
|
func publicListings(items []ListingDTO) []ListingDTO {
|
||||||
for index := range items {
|
for index := range items {
|
||||||
applyPublicListingURLs(&items[index])
|
applyPublicListingURLs(&items[index])
|
||||||
|
applyPublicListingPrice(&items[index])
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
@@ -156,12 +157,47 @@ func applySellerListingPrice(item *ListingDTO) {
|
|||||||
item.AssetSummary["publish_ratio"] = sellerRatio
|
item.AssetSummary["publish_ratio"] = sellerRatio
|
||||||
}
|
}
|
||||||
delete(breakdown, "buyer_coin_base_price")
|
delete(breakdown, "buyer_coin_base_price")
|
||||||
|
delete(breakdown, "buyer_coin_base_price_cent")
|
||||||
delete(breakdown, "buyer_total_price")
|
delete(breakdown, "buyer_total_price")
|
||||||
|
delete(breakdown, "buyer_total_price_cent")
|
||||||
delete(breakdown, "buyer_ratio")
|
delete(breakdown, "buyer_ratio")
|
||||||
|
delete(breakdown, "buyer_ratio_bps")
|
||||||
delete(breakdown, "platform_markup_amount")
|
delete(breakdown, "platform_markup_amount")
|
||||||
|
delete(breakdown, "platform_markup_amount_cent")
|
||||||
delete(breakdown, "platform_rule_type")
|
delete(breakdown, "platform_rule_type")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applyPublicListingPrice 只保留买家侧价格字段,隐藏卖家成本与平台加价。
|
||||||
|
func applyPublicListingPrice(item *ListingDTO) {
|
||||||
|
if item == nil || item.AssetSummary == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
breakdown, ok := item.AssetSummary["price_breakdown"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, key := range []string{
|
||||||
|
"seller_reference_ratio",
|
||||||
|
"seller_reference_ratio_bps",
|
||||||
|
"seller_ratio",
|
||||||
|
"seller_ratio_bps",
|
||||||
|
"seller_coin_base_price",
|
||||||
|
"seller_coin_base_price_cent",
|
||||||
|
"seller_total_price",
|
||||||
|
"seller_total_price_cent",
|
||||||
|
"platform_markup_amount",
|
||||||
|
"platform_markup_amount_cent",
|
||||||
|
"platform_rule_type",
|
||||||
|
"admin_adjust_reason",
|
||||||
|
"admin_adjusted_at",
|
||||||
|
"admin_adjusted_by",
|
||||||
|
"site_receive_ratio_delta",
|
||||||
|
"site_receive_cost_delta",
|
||||||
|
} {
|
||||||
|
delete(breakdown, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (row listingRow) toDTO() ListingDTO {
|
func (row listingRow) toDTO() ListingDTO {
|
||||||
assetSummary := decodeAssetSummary(row.AssetSummary)
|
assetSummary := decodeAssetSummary(row.AssetSummary)
|
||||||
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(row.ScreenshotURLS))
|
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(row.ScreenshotURLS))
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ func (r *Repository) FindPublic(ctx context.Context, id uint64, siteCode string)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
applyPublicListingURLs(dto)
|
applyPublicListingURLs(dto)
|
||||||
|
applyPublicListingPrice(dto)
|
||||||
items := []ListingDTO{*dto}
|
items := []ListingDTO{*dto}
|
||||||
if err := r.applyShelfMarkup(ctx, siteCode, items); err != nil {
|
if err := r.applyShelfMarkup(ctx, siteCode, items); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -258,11 +258,21 @@ func (r *Repository) findForReviewUpdate(tx *gorm.DB, listingID uint64) (*model.
|
|||||||
func (r *Repository) nextListingNo(tx *gorm.DB, now time.Time) (string, error) {
|
func (r *Repository) nextListingNo(tx *gorm.DB, now time.Time) (string, error) {
|
||||||
bizDate := now.Format("20060102")
|
bizDate := now.Format("20060102")
|
||||||
if tx.Dialector.Name() == "mysql" {
|
if tx.Dialector.Name() == "mysql" {
|
||||||
|
// 以当天已有编号的最大值为兜底,避免种子数据或外部写入后序列落后导致编号冲突。
|
||||||
|
var maxSeq int
|
||||||
|
if err := tx.Raw(
|
||||||
|
`SELECT COALESCE(MAX(CAST(SUBSTRING(listing_no, 9) AS UNSIGNED)), 0)
|
||||||
|
FROM rental_listings WHERE listing_no LIKE ?`,
|
||||||
|
bizDate+"%",
|
||||||
|
).Scan(&maxSeq).Error; err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
nextSeq := maxSeq + 1
|
||||||
if err := tx.Exec(`
|
if err := tx.Exec(`
|
||||||
INSERT INTO listing_no_sequences (biz_date, next_seq)
|
INSERT INTO listing_no_sequences (biz_date, next_seq)
|
||||||
VALUES (?, LAST_INSERT_ID(1))
|
VALUES (?, LAST_INSERT_ID(?))
|
||||||
ON DUPLICATE KEY UPDATE next_seq = LAST_INSERT_ID(next_seq + 1)
|
ON DUPLICATE KEY UPDATE next_seq = LAST_INSERT_ID(GREATEST(next_seq + 1, ?))
|
||||||
`, bizDate).Error; err != nil {
|
`, bizDate, nextSeq, nextSeq).Error; err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
var seq int
|
var seq int
|
||||||
|
|||||||
Reference in New Issue
Block a user