feat(backend): 出入库汇总近30天滚动窗口 + 跨租户安全加固
- summaryBounds:本月/近30天滚动双口径(stock-in/out Summary ?window=rolling30) - security(SEC-001):新增 ownership.go ensureShopRef 写入侧防线(stock-in/out/finance/ 盘点建单的 warehouse/partner/product 外键归属校验);读取侧全部 Preload 补 shop_id 作用域,finance Summary JOIN 补租户条件;回归测试 CrossTenantRefs - security(SEC-002):release 模式 JWT 密钥为空/默认值时拒绝启动 - gofmt 对齐若干 model/cmd 文件 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
This commit is contained in:
@@ -6,21 +6,21 @@ import "time"
|
||||
|
||||
type StockInOrder struct {
|
||||
TenantBase
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_shop_order_no" json:"order_no"`
|
||||
Type string `gorm:"size:30;default:'purchase'" json:"type"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id" binding:"required,min=1"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
CreatorID *uint64 `json:"creator_id"`
|
||||
ReviewerID *uint64 `json:"reviewer_id"`
|
||||
Status string `gorm:"type:enum('draft','pending','approved','rejected');default:'draft'" json:"status"`
|
||||
OrderDate Date `gorm:"type:date" json:"order_date"`
|
||||
TotalAmount float64 `gorm:"type:decimal(16,2);default:0" json:"total_amount"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_shop_order_no" json:"order_no"`
|
||||
Type string `gorm:"size:30;default:'purchase'" json:"type"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id" binding:"required,min=1"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
CreatorID *uint64 `json:"creator_id"`
|
||||
ReviewerID *uint64 `json:"reviewer_id"`
|
||||
Status string `gorm:"type:enum('draft','pending','approved','rejected');default:'draft'" json:"status"`
|
||||
OrderDate Date `gorm:"type:date" json:"order_date"`
|
||||
TotalAmount float64 `gorm:"type:decimal(16,2);default:0" json:"total_amount"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
// 退单状态:none=无 / partial=部分退单 / full=已全退(仅 approved 单可退)
|
||||
ReturnState string `gorm:"size:20;default:'none'" json:"return_state"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
ReturnState string `gorm:"size:20;default:'none'" json:"return_state"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
|
||||
Items []StockInItem `gorm:"foreignKey:OrderID" json:"items,omitempty"`
|
||||
Warehouse *Warehouse `gorm:"foreignKey:WarehouseID" json:"warehouse,omitempty"`
|
||||
@@ -32,25 +32,25 @@ type StockInOrder struct {
|
||||
|
||||
type StockInItem struct {
|
||||
Base
|
||||
OrderID uint64 `gorm:"not null;index" json:"order_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
OrderID uint64 `gorm:"not null;index" json:"order_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
// 历史导入快照列:源明细自带的商品信息,不依赖 product 主数据(product_id 可为 0)。
|
||||
ProductCode string `gorm:"size:50" json:"product_code"`
|
||||
ProductName string `gorm:"size:255" json:"product_name"`
|
||||
Series string `gorm:"size:100" json:"series"`
|
||||
Spec string `gorm:"size:100" json:"spec"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
||||
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
||||
ProductCode string `gorm:"size:50" json:"product_code"`
|
||||
ProductName string `gorm:"size:255" json:"product_name"`
|
||||
Series string `gorm:"size:100" json:"series"`
|
||||
Spec string `gorm:"size:100" json:"spec"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
||||
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
||||
// 建议售价:仅用于入库建产品时写入 product.SalePrice,不落 stock_in_items 表(gorm:"-")。
|
||||
SalePrice float64 `gorm:"-" json:"sale_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
||||
SalePrice float64 `gorm:"-" json:"sale_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
||||
// 已退数量:0=未退,=Quantity 表示整行已退单(整行退,不做部分数量)
|
||||
ReturnedQuantity float64 `gorm:"type:decimal(12,3);default:0" json:"returned_quantity"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
ProductionDate *Date `gorm:"type:date" json:"production_date"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:255" json:"remark"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
ProductionDate *Date `gorm:"type:date" json:"production_date"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:255" json:"remark"`
|
||||
|
||||
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
||||
Order *StockInOrder `gorm:"foreignKey:OrderID" json:"order,omitempty"`
|
||||
@@ -60,21 +60,21 @@ type StockInItem struct {
|
||||
|
||||
type StockOutOrder struct {
|
||||
TenantBase
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_shop_order_no" json:"order_no"`
|
||||
Type string `gorm:"size:30;default:'sale'" json:"type"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id" binding:"required,min=1"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
CreatorID *uint64 `json:"creator_id"`
|
||||
ReviewerID *uint64 `json:"reviewer_id"`
|
||||
Status string `gorm:"type:enum('draft','pending','approved','rejected');default:'draft'" json:"status"`
|
||||
OrderDate Date `gorm:"type:date" json:"order_date"`
|
||||
TotalAmount float64 `gorm:"type:decimal(16,2);default:0" json:"total_amount"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
OrderNo string `gorm:"size:50;uniqueIndex:uk_shop_order_no" json:"order_no"`
|
||||
Type string `gorm:"size:30;default:'sale'" json:"type"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id" binding:"required,min=1"`
|
||||
PartnerID *uint64 `json:"partner_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
CreatorID *uint64 `json:"creator_id"`
|
||||
ReviewerID *uint64 `json:"reviewer_id"`
|
||||
Status string `gorm:"type:enum('draft','pending','approved','rejected');default:'draft'" json:"status"`
|
||||
OrderDate Date `gorm:"type:date" json:"order_date"`
|
||||
TotalAmount float64 `gorm:"type:decimal(16,2);default:0" json:"total_amount"`
|
||||
ReviewedAt *time.Time `json:"reviewed_at"`
|
||||
// 退单状态:none / partial / full
|
||||
ReturnState string `gorm:"size:20;default:'none'" json:"return_state"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
ReturnState string `gorm:"size:20;default:'none'" json:"return_state"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
|
||||
Items []StockOutItem `gorm:"foreignKey:OrderID" json:"items,omitempty"`
|
||||
Warehouse *Warehouse `gorm:"foreignKey:WarehouseID" json:"warehouse,omitempty"`
|
||||
@@ -86,25 +86,25 @@ type StockOutOrder struct {
|
||||
|
||||
type StockOutItem struct {
|
||||
Base
|
||||
OrderID uint64 `gorm:"not null;index" json:"order_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
OrderID uint64 `gorm:"not null;index" json:"order_id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
ProductID uint64 `gorm:"not null" json:"product_id"`
|
||||
// 历史导入快照列:源明细自带的商品信息,不依赖 product 主数据(product_id 可为 0)。
|
||||
ProductCode string `gorm:"size:50" json:"product_code"`
|
||||
ProductName string `gorm:"size:255" json:"product_name"`
|
||||
Series string `gorm:"size:100" json:"series"`
|
||||
Spec string `gorm:"size:100" json:"spec"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
||||
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
||||
ProductCode string `gorm:"size:50" json:"product_code"`
|
||||
ProductName string `gorm:"size:255" json:"product_name"`
|
||||
Series string `gorm:"size:100" json:"series"`
|
||||
Spec string `gorm:"size:100" json:"spec"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
||||
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
||||
// 售价:出库实际销售单价(可编辑),应收账款按 售价×数量 计;与 UnitPrice(入库成本) 区分
|
||||
SalePrice float64 `gorm:"type:decimal(16,2);default:0" json:"sale_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
||||
SalePrice float64 `gorm:"type:decimal(16,2);default:0" json:"sale_price"`
|
||||
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
||||
// 已退数量:0=未退,=Quantity 表示整行已退单
|
||||
ReturnedQuantity float64 `gorm:"type:decimal(12,3);default:0" json:"returned_quantity"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
ProductionDate *Date `gorm:"type:date" json:"production_date"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:255" json:"remark"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
ProductionDate *Date `gorm:"type:date" json:"production_date"`
|
||||
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
||||
Remark string `gorm:"size:255" json:"remark"`
|
||||
|
||||
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
||||
}
|
||||
@@ -112,30 +112,30 @@ type StockOutItem struct {
|
||||
// -------- 实时库存(批次模式:每条记录代表一个批次/批次) --------
|
||||
|
||||
type Inventory struct {
|
||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
WarehouseID *uint64 `json:"warehouse_id"`
|
||||
ProductID *uint64 `json:"product_id"`
|
||||
StockInItemID *uint64 `json:"stock_in_item_id"`
|
||||
InventoryCheckID *uint64 `json:"inventory_check_id"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null;default:0" json:"quantity"`
|
||||
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
||||
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
||||
WarehouseID *uint64 `json:"warehouse_id"`
|
||||
ProductID *uint64 `json:"product_id"`
|
||||
StockInItemID *uint64 `json:"stock_in_item_id"`
|
||||
InventoryCheckID *uint64 `json:"inventory_check_id"`
|
||||
Quantity float64 `gorm:"type:decimal(12,3);not null;default:0" json:"quantity"`
|
||||
// Snapshot fields: copied from product/warehouse/stock-in at approval time.
|
||||
// They reflect the state at the moment of stock-in and are NOT updated when the
|
||||
// referenced product or warehouse record is later modified.
|
||||
ProductCode string `gorm:"size:50" json:"product_code"`
|
||||
ProductName string `gorm:"size:200" json:"product_name"`
|
||||
Series string `gorm:"size:100" json:"series"`
|
||||
Spec string `gorm:"size:100" json:"spec"`
|
||||
Unit string `gorm:"size:20" json:"unit"`
|
||||
WarehouseName string `gorm:"size:100" json:"warehouse_name"`
|
||||
UnitPrice *float64 `gorm:"type:decimal(16,2)" json:"unit_price"`
|
||||
ProductionDate *Date `gorm:"type:date" json:"production_date"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
SupplierName string `gorm:"size:200" json:"supplier_name"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index" json:"-"`
|
||||
ProductCode string `gorm:"size:50" json:"product_code"`
|
||||
ProductName string `gorm:"size:200" json:"product_name"`
|
||||
Series string `gorm:"size:100" json:"series"`
|
||||
Spec string `gorm:"size:100" json:"spec"`
|
||||
Unit string `gorm:"size:20" json:"unit"`
|
||||
WarehouseName string `gorm:"size:100" json:"warehouse_name"`
|
||||
UnitPrice *float64 `gorm:"type:decimal(16,2)" json:"unit_price"`
|
||||
ProductionDate *Date `gorm:"type:date" json:"production_date"`
|
||||
BatchNo string `gorm:"size:50" json:"batch_no"`
|
||||
SupplierName string `gorm:"size:200" json:"supplier_name"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt *time.Time `gorm:"index" json:"-"`
|
||||
|
||||
StockInItem *StockInItem `gorm:"foreignKey:StockInItemID" json:"stock_in_item,omitempty"`
|
||||
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
||||
@@ -166,12 +166,12 @@ type InventoryLog struct {
|
||||
|
||||
type InventoryCheck struct {
|
||||
TenantBase
|
||||
CheckNo string `gorm:"size:50;uniqueIndex:uk_shop_check_no" json:"check_no"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
Status string `gorm:"type:enum('draft','completed');default:'draft'" json:"status"`
|
||||
CheckDate Date `gorm:"type:date" json:"check_date"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
CheckNo string `gorm:"size:50;uniqueIndex:uk_shop_check_no" json:"check_no"`
|
||||
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
||||
OperatorID uint64 `gorm:"not null" json:"operator_id"`
|
||||
Status string `gorm:"type:enum('draft','completed');default:'draft'" json:"status"`
|
||||
CheckDate Date `gorm:"type:date" json:"check_date"`
|
||||
Remark string `gorm:"size:500" json:"remark"`
|
||||
|
||||
Items []InventoryCheckItem `gorm:"foreignKey:CheckID" json:"items,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user