From ddd66bf4e91a44c1841f93fb4611148f8deeaded Mon Sep 17 00:00:00 2001 From: Zuncle <34310384@qq.com> Date: Fri, 20 Mar 2026 20:39:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(dashboard):=20=E4=BF=AE=E5=A4=8D=E7=9B=88?= =?UTF-8?q?=E4=BA=8F=E5=88=86=E6=9E=90=E5=95=86=E5=93=81=E4=BA=A7=E5=87=BA?= =?UTF-8?q?=E5=8F=AA=E7=BB=9F=E8=AE=A1=E5=BE=85=E5=8F=91=E8=B4=A7=E5=BA=93?= =?UTF-8?q?=E5=AD=98=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 盈亏分析(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 的计算口径对齐 --- internal/api/admin/users_profile.go | 2 +- internal/api/admin/users_profit_loss.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/api/admin/users_profile.go b/internal/api/admin/users_profile.go index 9eeb6ed..24dfc93 100755 --- a/internal/api/admin/users_profile.go +++ b/internal/api/admin/users_profile.go @@ -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 diff --git a/internal/api/admin/users_profit_loss.go b/internal/api/admin/users_profit_loss.go index 18ffa82..ee0cba5 100755 --- a/internal/api/admin/users_profit_loss.go +++ b/internal/api/admin/users_profit_loss.go @@ -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