refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
1.7 KiB
1.7 KiB
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) tosimulateRewardStat(Unit cost in cents). - Add
TotalCost(int64) tosimulateRewardStat(WonCount * Cost). - Add
TotalSimulationCost(int64) tosimulateIssueResponse. - Add
TotalSimulationRevenue(int64) tosimulateIssueResponse(TotalDraws * Activity.PriceDraw). - Add
GrossProfit(int64) tosimulateIssueResponse(Revenue - Cost). - Add
GrossProfitRate(float64) tosimulateIssueResponse.
- Add
-
Logic Update:
- In
SimulateIssue:- Fetch the
Activitydetails to getPriceDraw. - Collect all
ProductIDs from the rewards. - Batch query the
Productstable to get prices. - Map product prices to rewards (if
ProductID > 0). - Calculate financial stats after the simulation loop.
- Fetch the
- In
2. Frontend Changes (web/admin/src/views/operations/lottery-simulation/index.vue)
- Update API Type Definition: Update
SimulateRewardStatandSimulateIssueResponseinterfaces inapi/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.
- Summary Cards: Add a row of summary cards at the top of the results section showing:
3. Verification
- Verify compilation.
- (Self-Correction) Ensure
Priceis handled as integer (cents) and formatted correctly in frontend (divided by 100).