资产增加批次库存管理模式

This commit is contained in:
2026-01-04 12:20:45 +08:00
parent 1ce24a84cd
commit 30eb8bcf89
3 changed files with 69 additions and 15 deletions

View File

@@ -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,
})
}