80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hepa-calc-admin-api/api/model"
|
||
)
|
||
|
||
type UserCouponDto struct {
|
||
UserCouponId string `json:"user_coupon_id"` // 主键id
|
||
UserId string `json:"user_id"` // 用户id
|
||
CouponId string `json:"coupon_id"` // 优惠券id
|
||
UserCouponStatus int `json:"user_coupon_status"` // 状态(0:未使用 1:已使用 3:已过期)
|
||
IsWindows int `json:"is_windows"` // 是否已弹窗(0:否 1:是)
|
||
CouponUseDate model.LocalTime `json:"coupon_use_date"` // 使用时间
|
||
ValidStartTime model.LocalTime `json:"valid_start_time"` // 有效开始时间
|
||
ValidEndTime model.LocalTime `json:"valid_end_time"` // 过期时间
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||
Coupon *CouponDto `json:"coupon"` // 优惠卷
|
||
}
|
||
|
||
// GetUserCouponDto 用户优惠卷详情
|
||
func GetUserCouponDto(m *model.UserCoupon) *UserCouponDto {
|
||
return &UserCouponDto{
|
||
UserCouponId: fmt.Sprintf("%d", m.UserCouponId),
|
||
UserId: fmt.Sprintf("%d", m.UserId),
|
||
CouponId: fmt.Sprintf("%d", m.CouponId),
|
||
UserCouponStatus: m.UserCouponStatus,
|
||
IsWindows: m.IsWindows,
|
||
CouponUseDate: m.CouponUseDate,
|
||
ValidStartTime: m.ValidStartTime,
|
||
ValidEndTime: m.ValidEndTime,
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
// GetUserCouponListDto 列表
|
||
func GetUserCouponListDto(m []*model.UserCoupon) []*UserCouponDto {
|
||
// 处理返回值
|
||
responses := make([]*UserCouponDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &UserCouponDto{
|
||
UserCouponId: fmt.Sprintf("%d", v.UserCouponId),
|
||
UserId: fmt.Sprintf("%d", v.UserId),
|
||
CouponId: fmt.Sprintf("%d", v.CouponId),
|
||
UserCouponStatus: v.UserCouponStatus,
|
||
IsWindows: v.IsWindows,
|
||
CouponUseDate: v.CouponUseDate,
|
||
ValidStartTime: v.ValidStartTime,
|
||
ValidEndTime: v.ValidEndTime,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 加载优惠卷数据
|
||
if v.Coupon != nil {
|
||
response = response.LoadCoupon(v.Coupon)
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadCoupon 加载优惠卷数据
|
||
func (r *UserCouponDto) LoadCoupon(m *model.Coupon) *UserCouponDto {
|
||
if m != nil {
|
||
d := GetCouponDto(m)
|
||
|
||
r.Coupon = d
|
||
}
|
||
return r
|
||
}
|