优惠卷新增了用户数据
This commit is contained in:
parent
2cdeb0d299
commit
bfa338d71f
@ -133,6 +133,9 @@ func (r *UserCouponDao) GetUserCouponPageSearch(req requests.GetUserCouponPage,
|
|||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
query := global.Db.Model(&model.UserCoupon{})
|
query := global.Db.Model(&model.UserCoupon{})
|
||||||
|
|
||||||
|
// 用户
|
||||||
|
query = query.Preload("User")
|
||||||
|
|
||||||
// 优惠卷
|
// 优惠卷
|
||||||
query = query.Preload("Coupon")
|
query = query.Preload("Coupon")
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,7 @@ type UserCouponDto struct {
|
|||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||||
Coupon *CouponDto `json:"coupon"` // 优惠卷
|
Coupon *CouponDto `json:"coupon"` // 优惠卷
|
||||||
|
User *UserDto `json:"user"` // 用户
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserCouponDto 用户优惠卷详情
|
// GetUserCouponDto 用户优惠卷详情
|
||||||
@ -60,6 +61,11 @@ func GetUserCouponListDto(m []*model.UserCoupon) []*UserCouponDto {
|
|||||||
response = response.LoadCoupon(v.Coupon)
|
response = response.LoadCoupon(v.Coupon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加载用户数据
|
||||||
|
if v.User != nil {
|
||||||
|
response = response.LoadCoupon(v.Coupon)
|
||||||
|
}
|
||||||
|
|
||||||
// 将转换后的结构体添加到新切片中
|
// 将转换后的结构体添加到新切片中
|
||||||
responses[i] = response
|
responses[i] = response
|
||||||
}
|
}
|
||||||
@ -80,3 +86,12 @@ func (r *UserCouponDto) LoadCoupon(m *model.Coupon) *UserCouponDto {
|
|||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadUser 加载用户数据
|
||||||
|
func (r *UserCouponDto) LoadUser(m *model.User) *UserCouponDto {
|
||||||
|
if m != nil {
|
||||||
|
r.User = GetUserDto(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ type UserCoupon struct {
|
|||||||
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:过期使用时间" json:"valid_end_time"`
|
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:过期使用时间" json:"valid_end_time"`
|
||||||
Model
|
Model
|
||||||
Coupon *Coupon `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon"`
|
Coupon *Coupon `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon"`
|
||||||
|
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UserCoupon) TableName() string {
|
func (m *UserCoupon) TableName() string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user