fix(dashboard): 修正活动奖品分析成本口径
活动奖品分析接口统一使用 products.cost_price 计算 prizeValue、cost 和 totalCost,避免误用售价导致成本统计偏差。
This commit is contained in:
parent
25dacc066a
commit
5dc9f034c8
@ -1237,13 +1237,13 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
||||
issueTotalWeights[r.IssueID] += int64(r.Weight)
|
||||
}
|
||||
|
||||
// 4. 批量查询商品价格和名称 (Product Price and Name)
|
||||
priceMap := make(map[int64]int64)
|
||||
// 4. 批量查询商品成本价和名称 (Product Cost and Name)
|
||||
productCostMap := make(map[int64]int64)
|
||||
productNameMap := make(map[int64]string)
|
||||
if len(productIDs) > 0 {
|
||||
products, _ := h.readDB.Products.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.Products.ID.In(productIDs...)).Find()
|
||||
for _, p := range products {
|
||||
priceMap[p.ID] = p.Price
|
||||
productCostMap[p.ID] = p.CostPrice
|
||||
productNameMap[p.ID] = p.Name
|
||||
}
|
||||
}
|
||||
@ -1306,7 +1306,7 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
||||
for i, r := range rsAll {
|
||||
dc := drawCounts[r.IssueID] // 该期的总抽奖数
|
||||
wc := winCounts[r.ID] // 该奖品的中奖数
|
||||
price := priceMap[r.ProductID]
|
||||
cost := productCostMap[r.ProductID]
|
||||
|
||||
issued := r.OriginalQty - r.Quantity
|
||||
|
||||
@ -1332,7 +1332,7 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
||||
}
|
||||
return "虚拟/道具"
|
||||
}(),
|
||||
PrizeValue: price,
|
||||
PrizeValue: cost,
|
||||
TotalQuantity: r.OriginalQty,
|
||||
IssuedQuantity: issued,
|
||||
DrawCount: dc,
|
||||
@ -1340,10 +1340,10 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
||||
WinRate: actual,
|
||||
Probability: prob,
|
||||
ActualProbability: actual,
|
||||
Cost: price,
|
||||
Cost: cost,
|
||||
}
|
||||
|
||||
totalCost += price * wc
|
||||
totalCost += cost * wc
|
||||
winRates = append(winRates, actual)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user