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
+7 -6
View File
@@ -339,8 +339,8 @@ func (h *ImportHandler) ImportStockIn(c *gin.Context) {
ShopID: shopID,
ProductID: prod.ID,
Quantity: qty,
UnitPrice: price,
TotalPrice: total,
CostPrice: price,
CostAmount: total,
BatchNo: batchNo,
})
}
@@ -359,7 +359,7 @@ func (h *ImportHandler) ImportStockIn(c *gin.Context) {
OperatorID: userID,
Status: "draft",
OrderDate: orderDate,
TotalAmount: totalAmount,
CostTotal: totalAmount,
}
if err := h.db.Create(&order).Error; err != nil {
@@ -442,8 +442,8 @@ func (h *ImportHandler) ImportStockOut(c *gin.Context) {
ShopID: shopID,
ProductID: prod.ID,
Quantity: qty,
UnitPrice: price,
TotalPrice: total,
CostPrice: price,
CostAmount: total,
})
}
@@ -461,7 +461,8 @@ func (h *ImportHandler) ImportStockOut(c *gin.Context) {
OperatorID: userID,
Status: "draft",
OrderDate: orderDate,
TotalAmount: totalAmount,
// 导入单沿旧行为:合计=源金额(明细 sale_price=0 待定价,确认售价后按差额调整)
SaleTotal: totalAmount,
}
if err := h.db.Create(&order).Error; err != nil {