89 lines
3.4 KiB
Go
89 lines
3.4 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hospital-admin-api/api/model"
|
||
)
|
||
|
||
type ProductPlatformDto struct {
|
||
ProductPlatformId string `json:"product_platform_id"` // 主键id
|
||
ProductName string `json:"product_name"` // 商品名称
|
||
ProductPrice float64 `json:"product_price"` // 商品价格
|
||
ProductType int `json:"product_type"` // 药品类型(0:未知 1:中成药 2:西药)
|
||
ProductPlatformCode string `json:"product_platform_code"` // 处方平台商品编码
|
||
ProductPharmacyCode string `json:"product_pharmacy_code"` // 第三方药店商品编码
|
||
ProductSpec string `json:"product_spec"` // 商品规格
|
||
LicenseNumber string `json:"license_number"` // 批准文号
|
||
Manufacturer string `json:"manufacturer"` // 生产厂家
|
||
SingleUnit string `json:"single_unit"` // 单次剂量单位
|
||
PackagingUnit string `json:"packaging_unit"` // 基本包装单位
|
||
PackagingCount string `json:"packaging_count"` // 基本包装数量
|
||
RetailUnit string `json:"retail_unit"` // 零售单位
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||
Stock uint `json:"stock"` // 现有库存
|
||
}
|
||
|
||
// GetProductPlatformDto 平台商品详情
|
||
func GetProductPlatformDto(m *model.ProductPlatform) *ProductPlatformDto {
|
||
return &ProductPlatformDto{
|
||
ProductPlatformId: fmt.Sprintf("%d", m.ProductPlatformId),
|
||
ProductName: m.ProductName,
|
||
ProductPrice: m.ProductPrice,
|
||
ProductType: m.ProductType,
|
||
ProductPlatformCode: m.ProductPlatformCode,
|
||
ProductPharmacyCode: m.ProductPharmacyCode,
|
||
ProductSpec: m.ProductSpec,
|
||
LicenseNumber: m.LicenseNumber,
|
||
Manufacturer: m.Manufacturer,
|
||
SingleUnit: m.SingleUnit,
|
||
PackagingUnit: m.PackagingUnit,
|
||
PackagingCount: m.PackagingCount,
|
||
RetailUnit: m.RetailUnit,
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
// GetProductPlatformListDto 平台商品列表
|
||
func GetProductPlatformListDto(m []*model.ProductPlatform) []*ProductPlatformDto {
|
||
// 处理返回值
|
||
responses := make([]*ProductPlatformDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &ProductPlatformDto{
|
||
ProductPlatformId: fmt.Sprintf("%d", v.ProductPlatformId),
|
||
ProductName: v.ProductName,
|
||
ProductPrice: v.ProductPrice,
|
||
ProductType: v.ProductType,
|
||
ProductPlatformCode: v.ProductPlatformCode,
|
||
ProductPharmacyCode: v.ProductPharmacyCode,
|
||
ProductSpec: v.ProductSpec,
|
||
LicenseNumber: v.LicenseNumber,
|
||
Manufacturer: v.Manufacturer,
|
||
SingleUnit: v.SingleUnit,
|
||
PackagingUnit: v.PackagingUnit,
|
||
PackagingCount: v.PackagingCount,
|
||
RetailUnit: v.RetailUnit,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadProductAmount 加载商品库存
|
||
func (r *ProductPlatformDto) LoadProductAmount(quantity int) *ProductPlatformDto {
|
||
if quantity > 0 {
|
||
r.Stock = uint(quantity)
|
||
}
|
||
|
||
return r
|
||
}
|