package dto import ( "fmt" "hospital-admin-api/api/model" ) // HealthPackageProductDto 健康包-关联商品 type HealthPackageProductDto struct { PackageProductId string `json:"package_product_id"` // 主键id PackageId string `json:"package_id"` // 健康包id ProductId string `json:"product_id"` // 商品id ProductName string `json:"product_name"` // 商品名称 Quantity int `json:"quantity"` // 数量 DiscountProductPrice float64 `json:"discount_product_price"` // 折扣商品价格 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间 } func GetHealthPackageProductDto(m *model.HealthPackageProduct) *HealthPackageProductDto { return &HealthPackageProductDto{ PackageProductId: fmt.Sprintf("%d", m.PackageProductId), PackageId: fmt.Sprintf("%d", m.PackageId), ProductId: fmt.Sprintf("%d", m.ProductId), ProductName: m.ProductName, Quantity: m.Quantity, DiscountProductPrice: m.DiscountProductPrice, CreatedAt: m.CreatedAt, UpdatedAt: m.UpdatedAt, } } func GetHealthPackageProductListDto(m []*model.HealthPackageProduct) []*HealthPackageProductDto { // 处理返回值 responses := make([]*HealthPackageProductDto, len(m)) if len(m) > 0 { for i, v := range m { response := &HealthPackageProductDto{ PackageProductId: fmt.Sprintf("%d", v.PackageProductId), PackageId: fmt.Sprintf("%d", v.PackageId), ProductId: fmt.Sprintf("%d", v.ProductId), ProductName: v.ProductName, Quantity: v.Quantity, DiscountProductPrice: v.DiscountProductPrice, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, } // 将转换后的结构体添加到新切片中 responses[i] = response } } return responses }