50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/dto"
|
|
)
|
|
|
|
type ProductService struct {
|
|
}
|
|
|
|
// GetProductPlatform 平台商品详情
|
|
func (r *ProductService) GetProductPlatform(productPlatformId int64) (g *dto.ProductPlatformDto, err error) {
|
|
// 获取平台商品数据
|
|
productPlatformDao := dao.ProductPlatformDao{}
|
|
productPlatform, err := productPlatformDao.GetProductPlatformById(productPlatformId)
|
|
if err != nil || productPlatform == nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 处理返回值
|
|
g = dto.GetProductPlatformDto(productPlatform)
|
|
|
|
return g, nil
|
|
}
|
|
|
|
// GetProduct 商品详情
|
|
func (r *ProductService) GetProduct(productId int64) (g *dto.ProductDto, err error) {
|
|
// 获取商品数据
|
|
productDao := dao.ProductDao{}
|
|
product, err := productDao.GetProductById(productId)
|
|
if err != nil || product == nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取商品库存数据
|
|
productPlatformAmountDao := dao.ProductPlatformAmountDao{}
|
|
productPlatformAmount, err := productPlatformAmountDao.GetProductPlatformAmountByProductPlatformId(product.ProductPlatformId)
|
|
|
|
// 处理返回值
|
|
g = dto.GetProductDto(product)
|
|
|
|
if productPlatformAmount != nil {
|
|
// 加载库存
|
|
g.LoadProductAmount(productPlatformAmount)
|
|
}
|
|
|
|
return g, nil
|
|
}
|