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)
|
issueTotalWeights[r.IssueID] += int64(r.Weight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 批量查询商品价格和名称 (Product Price and Name)
|
// 4. 批量查询商品成本价和名称 (Product Cost and Name)
|
||||||
priceMap := make(map[int64]int64)
|
productCostMap := make(map[int64]int64)
|
||||||
productNameMap := make(map[int64]string)
|
productNameMap := make(map[int64]string)
|
||||||
if len(productIDs) > 0 {
|
if len(productIDs) > 0 {
|
||||||
products, _ := h.readDB.Products.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.Products.ID.In(productIDs...)).Find()
|
products, _ := h.readDB.Products.WithContext(ctx.RequestContext()).ReadDB().Where(h.readDB.Products.ID.In(productIDs...)).Find()
|
||||||
for _, p := range products {
|
for _, p := range products {
|
||||||
priceMap[p.ID] = p.Price
|
productCostMap[p.ID] = p.CostPrice
|
||||||
productNameMap[p.ID] = p.Name
|
productNameMap[p.ID] = p.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1306,7 +1306,7 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
|||||||
for i, r := range rsAll {
|
for i, r := range rsAll {
|
||||||
dc := drawCounts[r.IssueID] // 该期的总抽奖数
|
dc := drawCounts[r.IssueID] // 该期的总抽奖数
|
||||||
wc := winCounts[r.ID] // 该奖品的中奖数
|
wc := winCounts[r.ID] // 该奖品的中奖数
|
||||||
price := priceMap[r.ProductID]
|
cost := productCostMap[r.ProductID]
|
||||||
|
|
||||||
issued := r.OriginalQty - r.Quantity
|
issued := r.OriginalQty - r.Quantity
|
||||||
|
|
||||||
@ -1332,7 +1332,7 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
|||||||
}
|
}
|
||||||
return "虚拟/道具"
|
return "虚拟/道具"
|
||||||
}(),
|
}(),
|
||||||
PrizeValue: price,
|
PrizeValue: cost,
|
||||||
TotalQuantity: r.OriginalQty,
|
TotalQuantity: r.OriginalQty,
|
||||||
IssuedQuantity: issued,
|
IssuedQuantity: issued,
|
||||||
DrawCount: dc,
|
DrawCount: dc,
|
||||||
@ -1340,10 +1340,10 @@ func (h *handler) DashboardActivityPrizeAnalysis() core.HandlerFunc {
|
|||||||
WinRate: actual,
|
WinRate: actual,
|
||||||
Probability: prob,
|
Probability: prob,
|
||||||
ActualProbability: actual,
|
ActualProbability: actual,
|
||||||
Cost: price,
|
Cost: cost,
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCost += price * wc
|
totalCost += cost * wc
|
||||||
winRates = append(winRates, actual)
|
winRates = append(winRates, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user