feat(backend): 库存接口带出售价 sale_price(库存屏成本价/单价两列地基)

照原型库存表「成本价(进价)+单价(售价)」两列:
- 库存查询 SELECT 加 p.sale_price AS sale_price;成本价 unit_price 补 p.purchase_price 兜底
- inventoryRow 加 SalePrice;前端 Inventory model 加 salePrice
- 多租户隔离不变(baseWhere 仍 inv.shop_id);库存测试通过

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TSKEiHsvauyxYUW2itzUXX
This commit is contained in:
wangjia
2026-06-25 19:56:27 +08:00
parent 23a583918d
commit 5e4cc668e5
2 changed files with 8 additions and 3 deletions
+4 -2
View File
@@ -36,7 +36,8 @@ type inventoryRow struct {
Spec string `json:"spec"`
Unit string `json:"unit"`
WarehouseName string `json:"warehouse_name"`
UnitPrice *float64 `json:"unit_price"`
UnitPrice *float64 `json:"unit_price"` // 成本价(入库进价)
SalePrice *float64 `json:"sale_price"` // 单价(product 售价)
ProductionDate *string `json:"production_date"`
BatchNo string `json:"batch_no"`
SupplierName string `json:"supplier_name"`
@@ -131,7 +132,8 @@ func (h *InventoryHandler) List(c *gin.Context) {
COALESCE(NULLIF(p.spec,''), NULLIF(sii.spec,''), inv.spec, '') AS spec,
COALESCE(NULLIF(p.unit,''), inv.unit, '') AS unit,
COALESCE(NULLIF(w.name,''), inv.warehouse_name, '') AS warehouse_name,
COALESCE(sii.unit_price, inv.unit_price) AS unit_price,
COALESCE(sii.unit_price, inv.unit_price, p.purchase_price) AS unit_price,
p.sale_price AS sale_price,
COALESCE(DATE(sii.production_date), DATE(inv.production_date)) AS production_date,
COALESCE(NULLIF(sii.batch_no,''), inv.batch_no, '') AS batch_no,
inv.supplier_name,
+4 -1
View File
@@ -15,7 +15,8 @@ class Inventory {
final String spec;
final String unit;
final String warehouseName;
final double? unitPrice;
final double? unitPrice; // 成本价(入库进价)
final double? salePrice; // 单价(product 售价)
final String? productionDate;
final String batchNo;
final String supplierName;
@@ -37,6 +38,7 @@ class Inventory {
this.unit = '',
this.warehouseName = '',
this.unitPrice,
this.salePrice,
this.productionDate,
this.batchNo = '',
this.supplierName = '',
@@ -59,6 +61,7 @@ class Inventory {
unit: json['unit'] as String? ?? '',
warehouseName: json['warehouse_name'] as String? ?? '',
unitPrice: (json['unit_price'] as num?)?.toDouble(),
salePrice: (json['sale_price'] as num?)?.toDouble(),
productionDate: _parseDate(json['production_date'] as String?),
batchNo: json['batch_no'] as String? ?? '',
supplierName: json['supplier_name'] as String? ?? '',