diff --git a/models/response/product.go b/models/response/product.go index 637c47b..26c15c2 100644 --- a/models/response/product.go +++ b/models/response/product.go @@ -229,6 +229,7 @@ type ProductFullInfoResponse struct { Status int8 `json:"status"` // 状态 CreatedAt int64 `json:"created_at"` // 创建时间 UpdatedAt int64 `json:"updated_at"` // 更新时间 + TotalStock int64 `json:"total_stock"` // 总库存数量 Inventories []ProductInventoryDetail `json:"inventories"` // 库存详情列表 ShopList []ShopInfo `json:"shop_list"` // 店铺信息列表 } diff --git a/service/product.go b/service/product.go index e62260c..012ebac 100644 --- a/service/product.go +++ b/service/product.go @@ -495,6 +495,13 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ fmt.Printf("【断点8】库存信息查询完成 - 数量: %d\n", len(inventories)) + totalStock := int64(0) + for _, inv := range inventories { + totalStock += inv.Quantity + } + + fmt.Printf("【断点9】计算总库存: %d\n", totalStock) + outTaskInfoMap, err := s.getProductOutTaskInfo(databaseConn, []int64{req.ProductID}) if err != nil { utils.ErrorLog(constant.LoggerChannelWork, map[string]interface{}{ @@ -508,7 +515,7 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ shopList = outTaskInfo.ShopList } - fmt.Printf("【断点9】店铺信息查询完成 - 数量: %d\n", len(shopList)) + fmt.Printf("【断点10】店铺信息查询完成 - 数量: %d\n", len(shopList)) response := &systemRes.ProductFullInfoResponse{ ID: product.ID, @@ -526,11 +533,12 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ Status: product.Status, CreatedAt: product.CreatedAt, UpdatedAt: product.UpdatedAt, + TotalStock: totalStock, Inventories: inventories, ShopList: shopList, } - fmt.Printf("【断点10】商品完整信息查询成功,准备返回\n") + fmt.Printf("【断点11】商品完整信息查询成功,准备返回\n") utils.InfoLog(constant.LoggerChannelWork, map[string]interface{}{ "action": "商品完整信息查询成功", @@ -538,6 +546,7 @@ func (s *ProductService) GetProductFullInfo(req systemReq.GetProductFullInfoRequ "user_id": req.UserID, "product_name": product.Name, "barcode": product.Barcode, + "total_stock": totalStock, "inventory_count": len(inventories), "shop_count": len(shopList), "success": true,