修改了 系统优惠卷详情 ,增加发放记录
This commit is contained in:
parent
7b021906a2
commit
61ca263d0d
67
api/dto/CouponGrant.go
Normal file
67
api/dto/CouponGrant.go
Normal file
@ -0,0 +1,67 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
)
|
||||
|
||||
// CouponGrantDto 发放优惠券表
|
||||
type CouponGrantDto struct {
|
||||
GrantId string `json:"grant_id"` // 主键id
|
||||
CouponId string `json:"coupon_id"` // 优惠卷id
|
||||
GrantType int `json:"grant_type"` // 发放类型(1:具体用户 2:未拥有用户)
|
||||
UserId string `json:"user_id"` // 用户id(发放类型为具体用户时存在)
|
||||
TotalQuantity int `json:"total_quantity"` // 目标发放数量
|
||||
GrantQuantity int `json:"grant_quantity"` // 已发放数量
|
||||
GrantResult int `json:"grant_result"` // 发放结果(1:成功 2:发放中 3:部分 4:失败)
|
||||
StopReason string `json:"stop_reason"` // 停止原因
|
||||
AdminUserId string `json:"admin_user_id"` // 后台操作用户id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
|
||||
// GetCouponGrantDto 优惠卷详情
|
||||
func GetCouponGrantDto(m *model.CouponGrant) *CouponGrantDto {
|
||||
return &CouponGrantDto{
|
||||
GrantId: fmt.Sprintf("%d", m.GrantId),
|
||||
CouponId: fmt.Sprintf("%d", m.CouponId),
|
||||
GrantType: m.GrantType,
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
TotalQuantity: m.TotalQuantity,
|
||||
GrantQuantity: m.GrantQuantity,
|
||||
GrantResult: m.GrantResult,
|
||||
StopReason: m.StopReason,
|
||||
AdminUserId: fmt.Sprintf("%d", m.AdminUserId),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetCouponGrantListDto 优惠卷列表
|
||||
func GetCouponGrantListDto(m []*model.CouponGrant) []*CouponGrantDto {
|
||||
// 处理返回值
|
||||
responses := make([]*CouponGrantDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &CouponGrantDto{
|
||||
GrantId: fmt.Sprintf("%d", v.GrantId),
|
||||
CouponId: fmt.Sprintf("%d", v.CouponId),
|
||||
GrantType: v.GrantType,
|
||||
UserId: fmt.Sprintf("%d", v.UserId),
|
||||
TotalQuantity: v.TotalQuantity,
|
||||
GrantQuantity: v.GrantQuantity,
|
||||
GrantResult: v.GrantResult,
|
||||
StopReason: v.StopReason,
|
||||
AdminUserId: fmt.Sprintf("%d", v.AdminUserId),
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
@ -38,6 +38,7 @@ type CouponDto struct {
|
||||
CouponDesc string `json:"coupon_desc"` // 优惠卷描述
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
CouponGrant []*CouponGrantDto `json:"coupon_grant"` // 发放记录
|
||||
}
|
||||
|
||||
// GetCouponDto 优惠卷详情
|
||||
@ -123,3 +124,13 @@ func GetCouponListDto(m []*model.Coupon) []*CouponDto {
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadCouponGrant 加载发放优惠卷数据
|
||||
func (r *CouponDto) LoadCouponGrant(m []*model.CouponGrant) *CouponDto {
|
||||
if len(m) > 0 {
|
||||
d := GetCouponGrantListDto(m)
|
||||
|
||||
r.CouponGrant = d
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
@ -37,6 +37,7 @@ type Coupon struct {
|
||||
IsPopup int `gorm:"column:is_popup;type:tinyint(1);default:0;comment:是否首页弹窗(0:否 1:是)" json:"is_popup"`
|
||||
CouponDesc string `gorm:"column:coupon_desc;type:text;comment:优惠卷描述" json:"coupon_desc"`
|
||||
Model
|
||||
CouponGrant []*CouponGrant `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon_grant"` // 优惠卷发放记录
|
||||
}
|
||||
|
||||
func (m *Coupon) TableName() string {
|
||||
|
||||
@ -22,7 +22,7 @@ type CouponService struct {
|
||||
// GetSystemCoupon 系统优惠卷详情
|
||||
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, err := couponDao.GetCouponById(couponId)
|
||||
coupon, err := couponDao.GetCouponPreloadById(couponId)
|
||||
if err != nil || coupon == nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
@ -30,6 +30,11 @@ func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err e
|
||||
// 处理返回值
|
||||
g = dto.GetCouponDto(coupon)
|
||||
|
||||
// 加载发放优惠卷数据
|
||||
if len(coupon.CouponGrant) > 0 {
|
||||
g = g.LoadCouponGrant(coupon.CouponGrant)
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user