diff --git a/internal/api/admin/users_profile.go b/internal/api/admin/users_profile.go index 20faf47..cecc471 100755 --- a/internal/api/admin/users_profile.go +++ b/internal/api/admin/users_profile.go @@ -197,10 +197,10 @@ func (h *handler) GetUserProfile() core.HandlerFunc { _ = h.repo.GetDbR().Raw(` SELECT COUNT(ui.id) as count, - COALESCE(SUM( + CAST(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 + ), 0) AS SIGNED) 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 diff --git a/internal/api/admin/users_profit_loss.go b/internal/api/admin/users_profit_loss.go index 48ba554..fafda9c 100755 --- a/internal/api/admin/users_profit_loss.go +++ b/internal/api/admin/users_profit_loss.go @@ -88,10 +88,10 @@ 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( + SELECT CAST(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) + ), 0) AS SIGNED) 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 @@ -216,10 +216,10 @@ func (h *handler) GetUserProfitLossTrend() core.HandlerFunc { p.Breakdown.Cards = curAssets.Cards p.Breakdown.Coupons = curAssets.Coupons - p.Profit = p.Value - p.Cost - if p.Cost > 0 { - p.Ratio = float64(p.Value) / float64(p.Cost) - } else if p.Value > 0 { + p.Profit = p.Cost - p.Value + if p.Value > 0 { + p.Ratio = float64(p.Cost) / float64(p.Value) + } else if p.Cost > 0 { p.Ratio = 99.9 } } @@ -262,10 +262,10 @@ func (h *handler) GetUserProfitLossTrend() core.HandlerFunc { } resp.Summary.TotalCost = finalNetCost resp.Summary.TotalValue = totalAssetValue - resp.Summary.TotalProfit = totalAssetValue - finalNetCost - if finalNetCost > 0 { - resp.Summary.AvgRatio = float64(totalAssetValue) / float64(finalNetCost) - } else if totalAssetValue > 0 { + resp.Summary.TotalProfit = finalNetCost - totalAssetValue + if totalAssetValue > 0 { + resp.Summary.AvgRatio = float64(finalNetCost) / float64(totalAssetValue) + } else if finalNetCost > 0 { resp.Summary.AvgRatio = 99.9 }