fix(dashboard): 盈亏分析商品产出对齐排行榜计算口径
问题:
盈亏分析(GetUserProfitLossTrend)和用户画像(GetUserProfile)中的
"商品产出"与玩家消费排行榜(DashboardPlayerSpendingLeaderboard)
计算口径不一致,导致同一用户的商品产出差异巨大。
排行榜显示用户9110商品产出¥16,913.40,盈亏分析显示¥0.00。
差异点:
1. status条件: 盈亏用 status=1(仅待发货),排行榜用 status IN (1,3)
2. 价格回退链: 盈亏缺少 price_snapshot_cents 回退层级
3. 道具卡倍率: 盈亏未计算 reward_multiplier_x1000
4. void排除: 盈亏未排除 remark 含 void 的作废项
修复:
- users_profit_loss.go: 商品产出查询完全对齐排行榜公式
- users_profile.go: 库存价值查询同步对齐
- 公式: COALESCE(value_cents, snapshot_cents, price, 0)
* GREATEST(COALESCE(multiplier, 1000), 1000) / 1000
- 条件: status IN (1,3) AND remark NOT LIKE '%void%'
This commit is contained in:
parent
ddd66bf4e9
commit
fe3141e2b5
@ -195,12 +195,20 @@ func (h *handler) GetUserProfile() core.HandlerFunc {
|
||||
}
|
||||
var is invStats
|
||||
_ = h.repo.GetDbR().Raw(`
|
||||
SELECT
|
||||
SELECT
|
||||
COUNT(ui.id) as count,
|
||||
COALESCE(SUM(COALESCE(NULLIF(ui.value_cents, 0), p.price, 0)), 0) as value
|
||||
COALESCE(SUM(
|
||||
COALESCE(NULLIF(ui.value_cents, 0), ars.price_snapshot_cents, p.price, 0)
|
||||
* GREATEST(COALESCE(sic.reward_multiplier_x1000, 1000), 1000) / 1000
|
||||
), 0) as value
|
||||
FROM user_inventory ui
|
||||
LEFT JOIN products p ON p.id = ui.product_id
|
||||
LEFT JOIN activity_reward_settings ars ON ars.id = ui.reward_id
|
||||
LEFT JOIN orders o ON o.id = ui.order_id
|
||||
LEFT JOIN user_item_cards uic ON uic.id = o.item_card_id
|
||||
LEFT JOIN system_item_cards sic ON sic.id = uic.card_id
|
||||
WHERE ui.user_id = ? AND ui.status IN (1, 3)
|
||||
AND COALESCE(ui.remark, '') NOT LIKE '%%void%%'
|
||||
`, userID).Scan(&is).Error
|
||||
rsp.CurrentAssets.InventoryCount = is.Count
|
||||
rsp.CurrentAssets.InventoryValue = is.Value
|
||||
|
||||
@ -88,10 +88,18 @@ func (h *handler) GetUserProfitLossTrend() core.HandlerFunc {
|
||||
}
|
||||
_ = h.repo.GetDbR().Raw("SELECT COALESCE(SUM(points), 0) FROM user_points WHERE user_id = ? AND (valid_end IS NULL OR valid_end > NOW())", userID).Scan(&curAssets.Points).Error
|
||||
_ = h.repo.GetDbR().Raw(`
|
||||
SELECT COALESCE(SUM(COALESCE(NULLIF(ui.value_cents, 0), p.price, 0)), 0)
|
||||
SELECT COALESCE(SUM(
|
||||
COALESCE(NULLIF(ui.value_cents, 0), ars.price_snapshot_cents, p.price, 0)
|
||||
* GREATEST(COALESCE(sic.reward_multiplier_x1000, 1000), 1000) / 1000
|
||||
), 0)
|
||||
FROM user_inventory ui
|
||||
LEFT JOIN products p ON p.id = ui.product_id
|
||||
LEFT JOIN activity_reward_settings ars ON ars.id = ui.reward_id
|
||||
LEFT JOIN orders o ON o.id = ui.order_id
|
||||
LEFT JOIN user_item_cards uic ON uic.id = o.item_card_id
|
||||
LEFT JOIN system_item_cards sic ON sic.id = uic.card_id
|
||||
WHERE ui.user_id = ? AND ui.status IN (1, 3)
|
||||
AND COALESCE(ui.remark, '') NOT LIKE '%%void%%'
|
||||
`, userID).Scan(&curAssets.Products).Error
|
||||
_ = h.repo.GetDbR().Raw("SELECT COALESCE(SUM(sc.price), 0) FROM user_item_cards uic LEFT JOIN system_item_cards sc ON sc.id = uic.card_id WHERE uic.user_id = ? AND uic.status = 1", userID).Scan(&curAssets.Cards).Error
|
||||
_ = h.repo.GetDbR().Raw("SELECT COALESCE(SUM(balance_amount), 0) FROM user_coupons WHERE user_id = ? AND status = 1", userID).Scan(&curAssets.Coupons).Error
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user