资产增加批次库存管理模式
This commit is contained in:
@@ -32,9 +32,19 @@ type OrderItemReq struct {
|
||||
// OrderItemStockReq 创建订单商品项库存明细请求
|
||||
|
||||
type OrderItemStockReq struct {
|
||||
StockID string `json:"stock_id" binding:"required"` // 库存ID
|
||||
Price int64 `json:"price" binding:"required,min=1"` // 单价(分)
|
||||
StockAttrs map[string]interface{} `json:"stock_attrs"` // 库存项属性(动态字段)
|
||||
// 库存ID(明细模式必填,批次模式为空)
|
||||
StockID string `json:"stock_id,omitempty"` // 库存ID
|
||||
// 批次信息(批次模式必填,明细模式为空)
|
||||
BatchID string `json:"batch_id,omitempty"` // 批次ID
|
||||
BatchNo string `json:"batch_no,omitempty"` // 批次号
|
||||
// 数量
|
||||
Quantity int `json:"quantity" binding:"required,min=1"` // 使用数量
|
||||
// 价格信息
|
||||
Price int64 `json:"price" binding:"required,min=1"` // 单价(分)
|
||||
// 库存管理模式
|
||||
StockMode int `json:"stock_mode" binding:"required"` // 库存管理模式:1-明细模式,2-批次模式
|
||||
// 库存项属性
|
||||
StockAttrs map[string]interface{} `json:"stock_attrs"` // 库存项属性(动态字段)
|
||||
}
|
||||
|
||||
// ShippingInfoReq 收货信息请求
|
||||
@@ -136,8 +146,18 @@ type OrderItem struct {
|
||||
// OrderItemStock 订单商品项库存明细(响应)
|
||||
|
||||
type OrderItemStock struct {
|
||||
StockID string `json:"stock_id"` // 库存ID
|
||||
Price int64 `json:"price"` // 单价(分)
|
||||
// 库存ID(明细模式)
|
||||
StockID string `json:"stock_id,omitempty"` // 库存ID
|
||||
// 批次信息(批次模式)
|
||||
BatchID string `json:"batch_id,omitempty"` // 批次ID
|
||||
BatchNo string `json:"batch_no,omitempty"` // 批次号
|
||||
// 数量
|
||||
Quantity int `json:"quantity"` // 使用数量
|
||||
// 价格信息
|
||||
Price int64 `json:"price"` // 单价(分)
|
||||
// 库存管理模式
|
||||
StockMode int `json:"stock_mode"` // 库存管理模式:1-明细模式,2-批次模式
|
||||
// 库存项属性
|
||||
StockAttrs map[string]interface{} `json:"stock_attrs"` // 库存项属性(动态字段)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,11 +40,28 @@ type OrderItem struct {
|
||||
}
|
||||
|
||||
// OrderItemStock 订单商品项库存明细
|
||||
// 用于追溯具体使用了哪些库存项,一个库存项只会有一个实例
|
||||
// 用于追溯具体使用了哪些库存项,支持明细模式和批次模式
|
||||
// 明细模式:一个库存项对应一条记录,数量固定为1
|
||||
// 批次模式:一个批次记录可以包含多个数量
|
||||
type OrderItemStock struct {
|
||||
StockID string `bson:"stock_id" json:"stock_id"` // 库存ID
|
||||
Price int64 `bson:"price" json:"price"` // 该库存项的单价(分)
|
||||
StockAttrs map[string]interface{} `bson:"stock_attrs,omitempty" json:"stock_attrs"` // 库存项属性(动态字段,存储该库存项的具体规格属性)
|
||||
// 库存ID(明细模式必填,批次模式为空)
|
||||
StockID string `bson:"stock_id,omitempty" json:"stock_id,omitempty"`
|
||||
|
||||
// 批次信息(批次模式必填,明细模式为空)
|
||||
BatchID string `bson:"batch_id,omitempty" json:"batch_id,omitempty"` // 批次ID
|
||||
BatchNo string `bson:"batch_no,omitempty" json:"batch_no,omitempty"` // 批次号
|
||||
|
||||
// 数量(明细模式固定为1,批次模式可以>1)
|
||||
Quantity int `bson:"quantity" json:"quantity"` // 使用数量
|
||||
|
||||
// 价格信息
|
||||
Price int64 `bson:"price" json:"price"` // 该库存项的单价(分)
|
||||
|
||||
// 库存管理模式
|
||||
StockMode int `bson:"stock_mode" json:"stock_mode"` // 库存管理模式:1-明细模式,2-批次模式
|
||||
|
||||
// 库存项属性(动态字段,存储该库存项的具体规格属性)
|
||||
StockAttrs map[string]interface{} `bson:"stock_attrs,omitempty" json:"stock_attrs,omitempty"`
|
||||
}
|
||||
|
||||
// ShippingInfo 收货信息
|
||||
|
||||
@@ -39,18 +39,23 @@ var Order = new(order)
|
||||
func convertOrderItemsFromDTO(items []dto.OrderItemReq) []entity.OrderItem {
|
||||
var result []entity.OrderItem
|
||||
for _, item := range items {
|
||||
// 转换库存明细,每个库存项只会有一个实例
|
||||
// 转换库存明细,支持明细模式和批次模式
|
||||
var stocks []entity.OrderItemStock
|
||||
totalQuantity := len(item.Stocks) // 每个库存项数量为1
|
||||
totalQuantity := 0
|
||||
totalAmount := int64(0)
|
||||
|
||||
for _, stock := range item.Stocks {
|
||||
stocks = append(stocks, entity.OrderItemStock{
|
||||
StockID: stock.StockID,
|
||||
BatchID: stock.BatchID,
|
||||
BatchNo: stock.BatchNo,
|
||||
Quantity: stock.Quantity,
|
||||
Price: stock.Price,
|
||||
StockMode: stock.StockMode,
|
||||
StockAttrs: stock.StockAttrs,
|
||||
})
|
||||
totalAmount += stock.Price // 每个库存项数量为1
|
||||
totalQuantity += stock.Quantity
|
||||
totalAmount += int64(stock.Quantity) * stock.Price
|
||||
}
|
||||
|
||||
result = append(result, entity.OrderItem{
|
||||
@@ -70,12 +75,16 @@ func convertOrderItemsFromDTO(items []dto.OrderItemReq) []entity.OrderItem {
|
||||
func convertOrderItems(items []entity.OrderItem) []dto.OrderItem {
|
||||
var result []dto.OrderItem
|
||||
for _, item := range items {
|
||||
// 转换库存明细
|
||||
// 转换库存明细,支持明细模式和批次模式
|
||||
var stocks []dto.OrderItemStock
|
||||
for _, stock := range item.Stocks {
|
||||
stocks = append(stocks, dto.OrderItemStock{
|
||||
StockID: stock.StockID,
|
||||
BatchID: stock.BatchID,
|
||||
BatchNo: stock.BatchNo,
|
||||
Quantity: stock.Quantity,
|
||||
Price: stock.Price,
|
||||
StockMode: stock.StockMode,
|
||||
StockAttrs: stock.StockAttrs,
|
||||
})
|
||||
}
|
||||
@@ -97,12 +106,16 @@ func convertOrderItems(items []entity.OrderItem) []dto.OrderItem {
|
||||
func convertEntityOrderItemsToDTO(items []entity.OrderItem) []dto.OrderItem {
|
||||
var result []dto.OrderItem
|
||||
for _, item := range items {
|
||||
// 转换库存明细
|
||||
// 转换库存明细,支持明细模式和批次模式
|
||||
var stocks []dto.OrderItemStock
|
||||
for _, stock := range item.Stocks {
|
||||
stocks = append(stocks, dto.OrderItemStock{
|
||||
StockID: stock.StockID,
|
||||
BatchID: stock.BatchID,
|
||||
BatchNo: stock.BatchNo,
|
||||
Quantity: stock.Quantity,
|
||||
Price: stock.Price,
|
||||
StockMode: stock.StockMode,
|
||||
StockAttrs: stock.StockAttrs,
|
||||
})
|
||||
}
|
||||
@@ -412,12 +425,16 @@ func (s *order) convertCompletedOrderToDetail(order *entity.OrderCompleted) dto.
|
||||
func (s *order) convertOrderItems(items []*entity.OrderItem) []dto.OrderItem {
|
||||
var result []dto.OrderItem
|
||||
for _, item := range items {
|
||||
// 转换库存明细
|
||||
// 转换库存明细,支持明细模式和批次模式
|
||||
var stocks []dto.OrderItemStock
|
||||
for _, stock := range item.Stocks {
|
||||
stocks = append(stocks, dto.OrderItemStock{
|
||||
StockID: stock.StockID,
|
||||
BatchID: stock.BatchID,
|
||||
BatchNo: stock.BatchNo,
|
||||
Quantity: stock.Quantity,
|
||||
Price: stock.Price,
|
||||
StockMode: stock.StockMode,
|
||||
StockAttrs: stock.StockAttrs,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user