diff --git a/api/dto/SystemMember.go b/api/dto/SystemMember.go index 6e2c020..a664495 100644 --- a/api/dto/SystemMember.go +++ b/api/dto/SystemMember.go @@ -3,6 +3,7 @@ package dto import ( "fmt" "hepa-calc-api/api/model" + "math" ) // SystemMemberDto 配置-会员配置 @@ -13,6 +14,7 @@ type SystemMemberDto struct { DiscountPrice *float64 `json:"discount_price"` // 优惠价格 DiscountEndTime *model.LocalTime `json:"discount_end_time"` // 优惠截止时间 FirstTimePrice *float64 `json:"first_time_price"` // 首次购买价格 + ReductionAmount *float64 `json:"Reduction amount"` // 立减金额 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 } @@ -35,6 +37,9 @@ func GetSystemMemberListDto(m []*model.SystemMember) []*SystemMemberDto { UpdatedAt: v.UpdatedAt, } + // 加载数据-立减金额 + response = response.LoadReductionAmount(v) + // 将转换后的结构体添加到新切片中 responses[i] = response } @@ -56,3 +61,15 @@ func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto { UpdatedAt: m.UpdatedAt, } } + +// LoadReductionAmount 加载数据-立减金额 +func (r *SystemMemberDto) LoadReductionAmount(m *model.SystemMember) *SystemMemberDto { + if m.FirstTimePrice != nil { + reductionAmount := m.Price - *m.FirstTimePrice + reductionAmount = math.Round(reductionAmount*100) / 100 + + r.ReductionAmount = &reductionAmount + } + + return r +}