feat(backend): 出入库定价字段消歧 + 总利润落库 + 成本仅管理员可见

- 字段重命名(旧列弃用保留,启动幂等回填 BackfillPricingColumns):
  入库 unit_price/total_price/total_amount → cost_price/cost_amount/cost_total;
  出库同前缀 + 新增 sale_amount(售价小计)/ sale_total(应收)/ profit_total(总利润)
- 建单落三值;确认售价联动重算 sale_amount/sale_total/profit_total;
  确认进价回填成本后联动重算受影响出库单利润(recalcStockOutProfit)
- 出库 List/Get 对 operator/readonly 抹零成本与利润(stripStockOutCost 服务端兜底)
- 兼容一版:Create/Update 接受旧 key unit_price 回落(v1.0.87 及之前客户端)
- SUM 聚合/价格趋势/导入/种子工具同步切新列;测试全量改名 + 6 个新回归

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
This commit is contained in:
wangjia
2026-07-03 12:44:22 +08:00
parent 607b8aa763
commit 4fd0bb8b83
24 changed files with 601 additions and 135 deletions
+5 -4
View File
@@ -200,12 +200,13 @@ func (h *FinanceHandler) Trend(c *gin.Context) {
In float64 `json:"in"`
Out float64 `json:"out"`
}
sum := func(table, from, to string) float64 {
// 出库=应收合计(sale_total),入库=应付合计(cost_total)——2026-07 定价字段消歧后分列
sum := func(table, col, from, to string) float64 {
var v float64
h.db.Table(table).
Where("shop_id = ? AND deleted_at IS NULL AND order_date >= ? AND order_date < ?",
shopID, from, to).
Select("COALESCE(SUM(total_amount),0)").Scan(&v)
Select("COALESCE(SUM(" + col + "),0)").Scan(&v)
return v
}
const f = "2006-01-02"
@@ -215,8 +216,8 @@ func (h *FinanceHandler) Trend(c *gin.Context) {
mEnd := mStart.AddDate(0, 1, 0)
points = append(points, point{
Month: mStart.Format("2006-01"),
In: sum("stock_out_orders", mStart.Format(f), mEnd.Format(f)),
Out: sum("stock_in_orders", mStart.Format(f), mEnd.Format(f)),
In: sum("stock_out_orders", "sale_total", mStart.Format(f), mEnd.Format(f)),
Out: sum("stock_in_orders", "cost_total", mStart.Format(f), mEnd.Format(f)),
})
}
c.JSON(http.StatusOK, gin.H{"data": points})