fix(dashboard): 修复盈亏分析商品产出只统计待发货库存的bug
问题: 盈亏分析(GetUserProfitLossTrend)和用户画像(GetUserProfile)中的 "商品产出"查询条件为 `ui.status = 1`,只统计了待发货/库存中的商品, 已发货/已兑换(status=3)的商品被完全排除。 示例:用户9110实际累计获得874件商品(价值¥16,279.40),但因为大部分 已发货(status=3),盈亏分析只显示商品产出¥12.50,全资产产出严重偏低。 而 dashboard_user_spending.go 中的同类查询正确使用了 `status IN (1, 3)`,说明此处是遗漏。 修复: - users_profit_loss.go: 当前资产快照查询改为 `status IN (1, 3)` - users_profile.go: 库存统计查询改为 `status IN (1, 3)` - 与 dashboard_user_spending.go 的计算口径对齐
This commit is contained in:
parent
535106f158
commit
ddd66bf4e9
@ -200,7 +200,7 @@ func (h *handler) GetUserProfile() core.HandlerFunc {
|
||||
COALESCE(SUM(COALESCE(NULLIF(ui.value_cents, 0), p.price, 0)), 0) as value
|
||||
FROM user_inventory ui
|
||||
LEFT JOIN products p ON p.id = ui.product_id
|
||||
WHERE ui.user_id = ? AND ui.status = 1
|
||||
WHERE ui.user_id = ? AND ui.status IN (1, 3)
|
||||
`, userID).Scan(&is).Error
|
||||
rsp.CurrentAssets.InventoryCount = is.Count
|
||||
rsp.CurrentAssets.InventoryValue = is.Value
|
||||
|
||||
@ -91,7 +91,7 @@ func (h *handler) GetUserProfitLossTrend() core.HandlerFunc {
|
||||
SELECT COALESCE(SUM(COALESCE(NULLIF(ui.value_cents, 0), p.price, 0)), 0)
|
||||
FROM user_inventory ui
|
||||
LEFT JOIN products p ON p.id = ui.product_id
|
||||
WHERE ui.user_id = ? AND ui.status = 1
|
||||
WHERE ui.user_id = ? AND ui.status IN (1, 3)
|
||||
`, 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