bindbox-game/.trae/documents/Add Cost Analysis to Lottery Simulation.md
邹方成 45815bfb7d chore: 清理无用文件与优化代码结构
refactor(utils): 修复密码哈希比较逻辑错误
feat(user): 新增按状态筛选优惠券接口
docs: 添加虚拟发货与任务中心相关文档
fix(wechat): 修正Code2Session上下文传递问题
test: 补充订单折扣与积分转换测试用例
build: 更新配置文件与构建脚本
style: 清理多余的空行与注释
2025-12-18 17:35:55 +08:00

39 lines
1.7 KiB
Markdown

# Add Cost Analysis to Lottery Simulation
I will enhance the lottery simulation feature to include cost calculation and financial analysis.
## 1. Backend Changes (`internal/api/admin/lottery_admin.go`)
- **Update Response Structures**:
- Add `Cost` (int64) to `simulateRewardStat` (Unit cost in cents).
- Add `TotalCost` (int64) to `simulateRewardStat` (WonCount * Cost).
- Add `TotalSimulationCost` (int64) to `simulateIssueResponse`.
- Add `TotalSimulationRevenue` (int64) to `simulateIssueResponse` (TotalDraws * Activity.PriceDraw).
- Add `GrossProfit` (int64) to `simulateIssueResponse` (Revenue - Cost).
- Add `GrossProfitRate` (float64) to `simulateIssueResponse`.
- **Logic Update**:
- In `SimulateIssue`:
- Fetch the `Activity` details to get `PriceDraw`.
- Collect all `ProductID`s from the rewards.
- Batch query the `Products` table to get prices.
- Map product prices to rewards (if `ProductID > 0`).
- Calculate financial stats after the simulation loop.
## 2. Frontend Changes (`web/admin/src/views/operations/lottery-simulation/index.vue`)
- **Update API Type Definition**: Update `SimulateRewardStat` and `SimulateIssueResponse` interfaces in `api/operations.ts`.
- **UI Enhancement**:
- **Summary Cards**: Add a row of summary cards at the top of the results section showing:
- Total Revenue (总收入)
- Total Cost (总成本)
- Gross Profit (毛利润)
- Profit Margin (毛利率)
- **Table Columns**:
- Add "Unit Cost" (单价/成本) column.
- Add "Total Cost" (总发放成本) column.
## 3. Verification
- Verify compilation.
- (Self-Correction) Ensure `Price` is handled as integer (cents) and formatted correctly in frontend (divided by 100).