hospital-admin-api/api/dto/OrderProductCoupon.go

53 lines
1.7 KiB
Go

package dto
import (
"fmt"
"hospital-admin-api/api/model"
)
type OrderProductCouponDto struct {
OrderCouponId string `json:"order_coupon_id"` // 主键id
OrderProductId string `json:"order_product_id"` // 订单-商品id
UserCouponId string `json:"user_coupon_id"` // 用户优惠卷表id
CouponName string `json:"coupon_name"` // 优惠卷名称
CouponUsePrice float64 `json:"coupon_use_price"` // 优惠卷使用金额
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
}
func GetOrderProductCouponDto(m *model.OrderProductCoupon) *OrderProductCouponDto {
return &OrderProductCouponDto{
OrderCouponId: fmt.Sprintf("%d", m.OrderCouponId),
OrderProductId: fmt.Sprintf("%d", m.OrderProductId),
UserCouponId: fmt.Sprintf("%d", m.UserCouponId),
CouponName: m.CouponName,
CouponUsePrice: m.CouponUsePrice,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func GetOrderProductCouponListDto(m []*model.OrderProductCoupon) []OrderProductCouponDto {
// 处理返回值
responses := make([]OrderProductCouponDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := OrderProductCouponDto{
OrderCouponId: fmt.Sprintf("%d", v.OrderCouponId),
OrderProductId: fmt.Sprintf("%d", v.OrderProductId),
UserCouponId: fmt.Sprintf("%d", v.UserCouponId),
CouponName: v.CouponName,
CouponUsePrice: v.CouponUsePrice,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}