diff --git a/api/dto/ProductPlatform.go b/api/dto/ProductPlatform.go index ffe34e5..aee13b2 100644 --- a/api/dto/ProductPlatform.go +++ b/api/dto/ProductPlatform.go @@ -21,6 +21,7 @@ type ProductPlatformDto struct { RetailUnit string `json:"retail_unit"` // 零售单位 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 + Stock uint `json:"stock"` // 现有库存 } // GetProductPlatformDto 平台商品详情 @@ -76,3 +77,12 @@ func GetProductPlatformListDto(m []*model.ProductPlatform) []*ProductPlatformDto return responses } + +// LoadProductAmount 加载商品库存 +func (r *ProductPlatformDto) LoadProductAmount(quantity int) *ProductPlatformDto { + if quantity > 0 { + r.Stock = uint(quantity) + } + + return r +} diff --git a/api/service/product.go b/api/service/product.go index 1efa458..859be79 100644 --- a/api/service/product.go +++ b/api/service/product.go @@ -24,9 +24,32 @@ func (r *ProductService) GetProductPlatform(productPlatformId int64) (g *dto.Pro return nil, errors.New(err.Error()) } + // 获取商品库存 + var quantity int + + ReportPreRequest := prescription.GetProdStockRequest{ + DrugCode: productPlatform.ProductPharmacyCode, + } + + result, err := ReportPreRequest.GetProdStock() + if err != nil { + quantity = 0 + } + + if result != nil { + if result.Quantity != "" { + quantity, err = strconv.Atoi(result.Quantity) + if err != nil { + quantity = 0 + } + } + } + // 处理返回值 g = dto.GetProductPlatformDto(productPlatform) + // 加载商品库存 + g.LoadProductAmount(quantity) return g, nil }