393e227de5
后端: - 新增 product_images 表,支持每商品最多5张图(服务端压缩至1200px/JPEG85%) - products 表新增 public_id(UUID)、description 字段 - 新增商品详情接口、二维码接口、公开商品接口(无鉴权) - 修复 XLS 导入:OLE2 magic bytes 检测 + 临时文件解析,兼容 extrame/xls - 修复商品/名称/系列/规格三张表导入数据为0(LastCol()=0 bug) - 所有导入接口返回 total/imported/skipped 统计 - config 新增 StorageConfig,支持 STORAGE_* 环境变量覆盖 - 种子数据修复:products 补 public_id、新增 product_images TRUNCATE、schema.sql 表名修正 前端: - 商品详情页:图片上传/删除、描述内联编辑、二维码弹窗、公开链接复制 - 公开商品页:无鉴权路由 /product/:public_id,Flutter Web SPA - 商品详情列表(批次追踪)商品名超链接跳转详情页 - 导航「商品管理」改名「商品详情」 - 所有列表表格新增每页条数选择(10/20/50/100) - 表格列头内嵌筛选(FilterableColumnHeader) - 导出 Excel 功能(入库/出库/库存/财务/批次/往来单位) - 网络恢复自动刷新 + 离线缓存展示 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
143 lines
6.7 KiB
Go
143 lines
6.7 KiB
Go
package model
|
|
|
|
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"`
|
|
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"`
|
|
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"`
|
|
Partner *Partner `gorm:"foreignKey:PartnerID" json:"partner,omitempty"`
|
|
Operator *User `gorm:"foreignKey:OperatorID" json:"operator,omitempty"`
|
|
Reviewer *User `gorm:"foreignKey:ReviewerID" json:"reviewer,omitempty"`
|
|
}
|
|
|
|
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"`
|
|
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
|
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
|
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
|
BatchNo string `gorm:"size:50" json:"batch_no"`
|
|
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"`
|
|
}
|
|
|
|
// -------- 出库单 --------
|
|
|
|
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"`
|
|
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"`
|
|
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"`
|
|
Partner *Partner `gorm:"foreignKey:PartnerID" json:"partner,omitempty"`
|
|
Operator *User `gorm:"foreignKey:OperatorID" json:"operator,omitempty"`
|
|
Reviewer *User `gorm:"foreignKey:ReviewerID" json:"reviewer,omitempty"`
|
|
}
|
|
|
|
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"`
|
|
Quantity float64 `gorm:"type:decimal(12,3);not null" json:"quantity"`
|
|
UnitPrice float64 `gorm:"type:decimal(16,2);default:0" json:"unit_price"`
|
|
TotalPrice float64 `gorm:"type:decimal(16,2);default:0" json:"total_price"`
|
|
CustomFields JSON `gorm:"type:json" json:"custom_fields,omitempty"`
|
|
Remark string `gorm:"size:255" json:"remark"`
|
|
|
|
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
|
}
|
|
|
|
// -------- 实时库存 --------
|
|
|
|
type Inventory struct {
|
|
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
ShopID uint64 `gorm:"not null;uniqueIndex:uk_shop_wh_product" json:"shop_id"`
|
|
WarehouseID uint64 `gorm:"not null;uniqueIndex:uk_shop_wh_product" json:"warehouse_id"`
|
|
ProductID uint64 `gorm:"not null;uniqueIndex:uk_shop_wh_product" json:"product_id"`
|
|
Quantity float64 `gorm:"type:decimal(12,3);default:0" json:"quantity"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
|
Warehouse *Warehouse `gorm:"foreignKey:WarehouseID" json:"warehouse,omitempty"`
|
|
}
|
|
|
|
// -------- 库存流水 --------
|
|
|
|
type InventoryLog struct {
|
|
ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"`
|
|
ShopID uint64 `gorm:"not null;index:idx_shop_product" json:"shop_id"`
|
|
WarehouseID uint64 `gorm:"not null" json:"warehouse_id"`
|
|
ProductID uint64 `gorm:"not null;index:idx_shop_product" json:"product_id"`
|
|
Direction string `gorm:"type:enum('in','out')" json:"direction"`
|
|
Quantity float64 `gorm:"type:decimal(12,3)" json:"quantity"`
|
|
QtyBefore float64 `gorm:"type:decimal(12,3)" json:"qty_before"`
|
|
QtyAfter float64 `gorm:"type:decimal(12,3)" json:"qty_after"`
|
|
RefType string `gorm:"size:30" json:"ref_type"`
|
|
RefID uint64 `json:"ref_id"`
|
|
OperatorID *uint64 `json:"operator_id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
|
|
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
|
Warehouse *Warehouse `gorm:"foreignKey:WarehouseID" json:"warehouse,omitempty"`
|
|
}
|
|
|
|
// -------- 库存盘点 --------
|
|
|
|
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"`
|
|
|
|
Items []InventoryCheckItem `gorm:"foreignKey:CheckID" json:"items,omitempty"`
|
|
}
|
|
|
|
type InventoryCheckItem struct {
|
|
Base
|
|
CheckID uint64 `gorm:"not null;index" json:"check_id"`
|
|
ShopID uint64 `gorm:"not null" json:"shop_id"`
|
|
ProductID uint64 `gorm:"not null" json:"product_id"`
|
|
SystemQty float64 `gorm:"type:decimal(12,3)" json:"system_qty"`
|
|
ActualQty float64 `gorm:"type:decimal(12,3)" json:"actual_qty"`
|
|
DiffQty float64 `gorm:"->" json:"diff_qty"` // generated column,只读
|
|
Remark string `gorm:"size:255" json:"remark"`
|
|
|
|
Product *Product `gorm:"foreignKey:ProductID" json:"product,omitempty"`
|
|
}
|