修改了 系统优惠卷详情 ,增加发放记录
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
|
||||||
|
}
|
||||||
@ -8,36 +8,37 @@ import (
|
|||||||
|
|
||||||
// CouponDto 优惠卷表
|
// CouponDto 优惠卷表
|
||||||
type CouponDto struct {
|
type CouponDto struct {
|
||||||
CouponId string `json:"coupon_id"` // 主键id
|
CouponId string `json:"coupon_id"` // 主键id
|
||||||
CouponName string `json:"coupon_name"` // 优惠卷名称
|
CouponName string `json:"coupon_name"` // 优惠卷名称
|
||||||
CouponIcon string `json:"coupon_icon"` // 优惠卷图片
|
CouponIcon string `json:"coupon_icon"` // 优惠卷图片
|
||||||
CouponClient int `json:"coupon_client"` // 使用平台(1:小程序)
|
CouponClient int `json:"coupon_client"` // 使用平台(1:小程序)
|
||||||
CouponType int `json:"coupon_type"` // 优惠卷类型(1:无门槛 2:满减 3:数量)
|
CouponType int `json:"coupon_type"` // 优惠卷类型(1:无门槛 2:满减 3:数量)
|
||||||
CouponStatus int `json:"coupon_status"` // 状态(1:正常 2:强制失效 3:结束 4:删除)
|
CouponStatus int `json:"coupon_status"` // 状态(1:正常 2:强制失效 3:结束 4:删除)
|
||||||
DistributionObject int `json:"distribution_object"` // 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)
|
DistributionObject int `json:"distribution_object"` // 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)
|
||||||
ApplicationScope int `json:"application_scope"` // 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)
|
ApplicationScope int `json:"application_scope"` // 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)
|
||||||
InquiryType string `json:"inquiry_type"` // 关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)
|
InquiryType string `json:"inquiry_type"` // 关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)
|
||||||
BrandId string `json:"brand_id"` // 关联品牌id(如不限制品牌,此项为空)
|
BrandId string `json:"brand_id"` // 关联品牌id(如不限制品牌,此项为空)
|
||||||
IsMutex int `json:"is_mutex"` // 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
|
IsMutex int `json:"is_mutex"` // 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
|
||||||
IsDisplay int `json:"is_display"` // 是否展示(0:否 1:是)
|
IsDisplay int `json:"is_display"` // 是否展示(0:否 1:是)
|
||||||
DistributionWithDay int `json:"distribution_with_day"` // 发放关联天数(发放对象为近期消费等类型时规定天数)
|
DistributionWithDay int `json:"distribution_with_day"` // 发放关联天数(发放对象为近期消费等类型时规定天数)
|
||||||
MinUsableNumber int `json:"min_usable_number"` // 单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)
|
MinUsableNumber int `json:"min_usable_number"` // 单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)
|
||||||
CouponCount int `json:"coupon_count"` // 发放数量
|
CouponCount int `json:"coupon_count"` // 发放数量
|
||||||
CouponTakeCount int `json:"coupon_take_count"` // 已领取数量
|
CouponTakeCount int `json:"coupon_take_count"` // 已领取数量
|
||||||
CouponUsedCount int `json:"coupon_used_count"` // 已使用数量
|
CouponUsedCount int `json:"coupon_used_count"` // 已使用数量
|
||||||
CouponPrice float64 `json:"coupon_price"` // 优惠卷金额
|
CouponPrice float64 `json:"coupon_price"` // 优惠卷金额
|
||||||
WithAmount float64 `json:"with_amount"` // 符合满减标准金额(优惠卷类型为满减时使用)
|
WithAmount float64 `json:"with_amount"` // 符合满减标准金额(优惠卷类型为满减时使用)
|
||||||
ValidType int `json:"valid_type"` // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
ValidType int `json:"valid_type"` // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
||||||
ValidDays int `json:"valid_days"` // 自领取之日起有效天数
|
ValidDays int `json:"valid_days"` // 自领取之日起有效天数
|
||||||
ValidStartTime *model.LocalTime `json:"valid_start_time"` // 开始使用时间
|
ValidStartTime *model.LocalTime `json:"valid_start_time"` // 开始使用时间
|
||||||
ValidEndTime *model.LocalTime `json:"valid_end_time"` // 结束使用时间
|
ValidEndTime *model.LocalTime `json:"valid_end_time"` // 结束使用时间
|
||||||
ProductId string `json:"product_id"` // 关联商品id,逗号分隔,指定商品时,填入此项。
|
ProductId string `json:"product_id"` // 关联商品id,逗号分隔,指定商品时,填入此项。
|
||||||
ReissueIntervalDays int `json:"reissue_interval_days"` // 确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效)
|
ReissueIntervalDays int `json:"reissue_interval_days"` // 确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效)
|
||||||
IsReissuableAfterExpire int `json:"is_reissuable_after_expire"` // 过期之后是否允许再次发放(0:否 1:是)
|
IsReissuableAfterExpire int `json:"is_reissuable_after_expire"` // 过期之后是否允许再次发放(0:否 1:是)
|
||||||
IsPopup int `json:"is_popup"` // 是否首页弹窗(0:否 1:是)
|
IsPopup int `json:"is_popup"` // 是否首页弹窗(0:否 1:是)
|
||||||
CouponDesc string `json:"coupon_desc"` // 优惠卷描述
|
CouponDesc string `json:"coupon_desc"` // 优惠卷描述
|
||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||||
|
CouponGrant []*CouponGrantDto `json:"coupon_grant"` // 发放记录
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCouponDto 优惠卷详情
|
// GetCouponDto 优惠卷详情
|
||||||
@ -123,3 +124,13 @@ func GetCouponListDto(m []*model.Coupon) []*CouponDto {
|
|||||||
|
|
||||||
return responses
|
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"`
|
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"`
|
CouponDesc string `gorm:"column:coupon_desc;type:text;comment:优惠卷描述" json:"coupon_desc"`
|
||||||
Model
|
Model
|
||||||
|
CouponGrant []*CouponGrant `gorm:"foreignKey:CouponId;references:coupon_id" json:"coupon_grant"` // 优惠卷发放记录
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Coupon) TableName() string {
|
func (m *Coupon) TableName() string {
|
||||||
|
|||||||
@ -22,7 +22,7 @@ type CouponService struct {
|
|||||||
// GetSystemCoupon 系统优惠卷详情
|
// GetSystemCoupon 系统优惠卷详情
|
||||||
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
||||||
couponDao := dao.CouponDao{}
|
couponDao := dao.CouponDao{}
|
||||||
coupon, err := couponDao.GetCouponById(couponId)
|
coupon, err := couponDao.GetCouponPreloadById(couponId)
|
||||||
if err != nil || coupon == nil {
|
if err != nil || coupon == nil {
|
||||||
return nil, errors.New(err.Error())
|
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)
|
g = dto.GetCouponDto(coupon)
|
||||||
|
|
||||||
|
// 加载发放优惠卷数据
|
||||||
|
if len(coupon.CouponGrant) > 0 {
|
||||||
|
g = g.LoadCouponGrant(coupon.CouponGrant)
|
||||||
|
}
|
||||||
|
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user