67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package dto
|
|
|
|
import (
|
|
"fmt"
|
|
"hepa-calc-api/api/model"
|
|
)
|
|
|
|
// SystemMemberDto 配置-会员配置
|
|
type SystemMemberDto struct {
|
|
SystemMemberId string `json:"system_member_id"` // 主键id
|
|
MemberDays uint `json:"member_days"` // 会员天数
|
|
Price float64 `json:"price"` // 价格(原价)
|
|
DiscountPrice *float64 `json:"discount_price"` // 优惠价格
|
|
DiscountEndTime *model.LocalTime `json:"discount_end_time"` // 优惠截止时间
|
|
ReductionAmount *float64 `json:"reduction_amount"` // 立减金额
|
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
|
}
|
|
|
|
// GetSystemMemberListDto 列表
|
|
func GetSystemMemberListDto(m []*model.SystemMember) []*SystemMemberDto {
|
|
// 处理返回值
|
|
responses := make([]*SystemMemberDto, len(m))
|
|
|
|
if len(m) > 0 {
|
|
for i, v := range m {
|
|
response := &SystemMemberDto{
|
|
SystemMemberId: fmt.Sprintf("%d", v.SystemMemberId),
|
|
MemberDays: v.MemberDays,
|
|
Price: v.Price,
|
|
DiscountPrice: v.DiscountPrice,
|
|
DiscountEndTime: v.DiscountEndTime,
|
|
CreatedAt: v.CreatedAt,
|
|
UpdatedAt: v.UpdatedAt,
|
|
}
|
|
|
|
// 加载数据-立减金额
|
|
response = response.LoadReductionAmount(v)
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
responses[i] = response
|
|
}
|
|
}
|
|
|
|
return responses
|
|
}
|
|
|
|
// GetSystemMemberDto 详情
|
|
func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto {
|
|
return &SystemMemberDto{
|
|
SystemMemberId: fmt.Sprintf("%d", m.SystemMemberId),
|
|
MemberDays: m.MemberDays,
|
|
Price: m.Price,
|
|
DiscountPrice: m.DiscountPrice,
|
|
DiscountEndTime: m.DiscountEndTime,
|
|
CreatedAt: m.CreatedAt,
|
|
UpdatedAt: m.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// LoadReductionAmount 加载数据-立减金额
|
|
func (r *SystemMemberDto) LoadReductionAmount(m *model.SystemMember) *SystemMemberDto {
|
|
r.ReductionAmount = m.ReductionAmount
|
|
|
|
return r
|
|
}
|