95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
package dto
|
|
|
|
import (
|
|
"fmt"
|
|
"hospital-admin-api/api/model"
|
|
)
|
|
|
|
// UserCouponDto 用户优惠卷表
|
|
type UserCouponDto struct {
|
|
UserCouponId string `json:"user_coupon_id"` // 主键id
|
|
UserId string `json:"user_id"` // 用户id
|
|
PatientId string `json:"patient_id"` // 患者id
|
|
CouponId string `json:"coupon_id"` // 优惠卷id
|
|
UserCouponStatus int `json:"user_coupon_status"` // 状态(0:未使用 1:已使用 3:已过期)
|
|
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"` // 优惠卷
|
|
UserName string `json:"user_name"` // 用户名称
|
|
}
|
|
|
|
// GetUserCouponDto 用户优惠卷详情
|
|
func GetUserCouponDto(m *model.UserCoupon) *UserCouponDto {
|
|
return &UserCouponDto{
|
|
UserCouponId: fmt.Sprintf("%d", m.UserCouponId),
|
|
UserId: fmt.Sprintf("%d", m.UserId),
|
|
PatientId: fmt.Sprintf("%d", m.PatientId),
|
|
CouponId: fmt.Sprintf("%d", m.CouponId),
|
|
UserCouponStatus: m.UserCouponStatus,
|
|
CouponUseDate: m.CouponUseDate,
|
|
ValidStartTime: model.LocalTime(m.ValidStartTime),
|
|
ValidEndTime: model.LocalTime(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),
|
|
PatientId: fmt.Sprintf("%d", v.PatientId),
|
|
CouponId: fmt.Sprintf("%d", v.CouponId),
|
|
UserCouponStatus: v.UserCouponStatus,
|
|
CouponUseDate: v.CouponUseDate,
|
|
ValidStartTime: model.LocalTime(v.ValidStartTime),
|
|
ValidEndTime: model.LocalTime(v.ValidEndTime),
|
|
CreatedAt: v.CreatedAt,
|
|
UpdatedAt: v.UpdatedAt,
|
|
}
|
|
|
|
// 加载优惠卷数据
|
|
if v.Coupon != nil {
|
|
response = response.LoadCoupon(v.Coupon)
|
|
}
|
|
|
|
// 加载用户属性
|
|
if v.User != nil {
|
|
response = response.LoadUserAttr(v.User)
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
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
|
|
}
|
|
|
|
// LoadUserAttr 加载用户属性
|
|
func (r *UserCouponDto) LoadUserAttr(m *model.User) *UserCouponDto {
|
|
if m != nil {
|
|
r.UserName = m.UserName
|
|
}
|
|
return r
|
|
}
|