151 lines
7.7 KiB
Go
151 lines
7.7 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hospital-admin-api/api/model"
|
||
"hospital-admin-api/utils"
|
||
"strings"
|
||
)
|
||
|
||
// CouponDto 优惠卷表
|
||
type CouponDto struct {
|
||
CouponId string `json:"coupon_id"` // 主键id
|
||
CouponName string `json:"coupon_name"` // 优惠卷名称
|
||
CouponIcon string `json:"coupon_icon"` // 优惠卷图片
|
||
CouponClient int `json:"coupon_client"` // 使用平台(1:小程序)
|
||
CouponType int `json:"coupon_type"` // 优惠卷类型(1:无门槛 2:满减 3:数量)
|
||
CouponStatus int `json:"coupon_status"` // 状态(1:正常 2:强制失效 3:结束 4:删除)
|
||
DistributionObject int `json:"distribution_object"` // 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)
|
||
ApplicationScope int `json:"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(如不限制品牌,此项为空)
|
||
IsMutex int `json:"is_mutex"` // 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
|
||
IsDisplay int `json:"is_display"` // 是否展示(0:否 1:是)
|
||
DistributionWithDay *int `json:"distribution_with_day"` // 发放关联天数(发放对象为近期消费等类型时规定天数)
|
||
MinUsableNumber int `json:"min_usable_number"` // 单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)
|
||
CouponCount int `json:"coupon_count"` // 发放数量
|
||
CouponTakeCount int `json:"coupon_take_count"` // 已领取数量
|
||
CouponUsedCount int `json:"coupon_used_count"` // 已使用数量
|
||
CouponPrice float64 `json:"coupon_price"` // 优惠卷金额
|
||
WithAmount float64 `json:"with_amount"` // 符合满减标准金额(优惠卷类型为满减时使用)
|
||
ValidType int `json:"valid_type"` // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
||
ValidDays int `json:"valid_days"` // 自领取之日起有效天数
|
||
ValidStartTime *model.LocalTime `json:"valid_start_time"` // 开始使用时间
|
||
ValidEndTime *model.LocalTime `json:"valid_end_time"` // 结束使用时间
|
||
ProductId string `json:"product_id"` // 关联商品id,逗号分隔,指定商品时,填入此项。
|
||
ReissueIntervalDays int `json:"reissue_interval_days"` // 确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效)
|
||
IsReissuableAfterExpire int `json:"is_reissuable_after_expire"` // 过期之后是否允许再次发放(0:否 1:是)
|
||
IsPopup int `json:"is_popup"` // 是否首页弹窗(0:否 1:是)
|
||
CouponDesc string `json:"coupon_desc"` // 优惠卷描述
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||
CouponGrant []*CouponGrantDto `json:"coupon_grant"` // 发放记录
|
||
}
|
||
|
||
// GetCouponDto 优惠卷详情
|
||
func GetCouponDto(m *model.Coupon) *CouponDto {
|
||
return &CouponDto{
|
||
CouponId: fmt.Sprintf("%d", m.CouponId),
|
||
CouponName: m.CouponName,
|
||
CouponIcon: utils.AddOssDomain(m.CouponIcon),
|
||
CouponClient: m.CouponClient,
|
||
CouponType: m.CouponType,
|
||
CouponStatus: m.CouponStatus,
|
||
DistributionObject: m.DistributionObject,
|
||
ApplicationScope: m.ApplicationScope,
|
||
BrandId: fmt.Sprintf("%d", m.BrandId),
|
||
IsMutex: *m.IsMutex,
|
||
IsDisplay: m.IsDisplay,
|
||
DistributionWithDay: &m.DistributionWithDay,
|
||
MinUsableNumber: *m.MinUsableNumber,
|
||
CouponCount: m.CouponCount,
|
||
CouponTakeCount: m.CouponTakeCount,
|
||
CouponUsedCount: m.CouponUsedCount,
|
||
CouponPrice: m.CouponPrice,
|
||
WithAmount: m.WithAmount,
|
||
ValidType: m.ValidType,
|
||
ValidDays: m.ValidDays,
|
||
ValidStartTime: m.ValidStartTime,
|
||
ValidEndTime: m.ValidEndTime,
|
||
ProductId: m.ProductId,
|
||
ReissueIntervalDays: m.ReissueIntervalDays,
|
||
IsReissuableAfterExpire: m.IsReissuableAfterExpire,
|
||
IsPopup: m.IsPopup,
|
||
CouponDesc: m.CouponDesc,
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
// GetCouponListDto 优惠卷列表
|
||
func GetCouponListDto(m []*model.Coupon) []*CouponDto {
|
||
// 处理返回值
|
||
responses := make([]*CouponDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &CouponDto{
|
||
CouponId: fmt.Sprintf("%d", v.CouponId),
|
||
CouponName: v.CouponName,
|
||
CouponIcon: utils.AddOssDomain(v.CouponIcon),
|
||
CouponClient: v.CouponClient,
|
||
CouponType: v.CouponType,
|
||
CouponStatus: v.CouponStatus,
|
||
DistributionObject: v.DistributionObject,
|
||
ApplicationScope: v.ApplicationScope,
|
||
BrandId: fmt.Sprintf("%d", v.BrandId),
|
||
IsMutex: *v.IsMutex,
|
||
IsDisplay: v.IsDisplay,
|
||
DistributionWithDay: &v.DistributionWithDay,
|
||
MinUsableNumber: *v.MinUsableNumber,
|
||
CouponCount: v.CouponCount,
|
||
CouponTakeCount: v.CouponTakeCount,
|
||
CouponUsedCount: v.CouponUsedCount,
|
||
CouponPrice: v.CouponPrice,
|
||
WithAmount: v.WithAmount,
|
||
ValidType: v.ValidType,
|
||
ValidDays: v.ValidDays,
|
||
ValidStartTime: v.ValidStartTime,
|
||
ValidEndTime: v.ValidEndTime,
|
||
ProductId: v.ProductId,
|
||
ReissueIntervalDays: v.ReissueIntervalDays,
|
||
IsReissuableAfterExpire: v.IsReissuableAfterExpire,
|
||
IsPopup: v.IsPopup,
|
||
CouponDesc: v.CouponDesc,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 加载关联问诊类型
|
||
if v.InquiryType != "" {
|
||
response.LoadInquiryType(v.InquiryType)
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadCouponGrant 加载发放优惠卷数据
|
||
func (r *CouponDto) LoadCouponGrant(m []*model.CouponGrant) *CouponDto {
|
||
if len(m) > 0 {
|
||
d := GetCouponGrantListDto(m)
|
||
|
||
r.CouponGrant = d
|
||
}
|
||
return r
|
||
}
|
||
|
||
// LoadInquiryType 加载关联问诊类型
|
||
func (r *CouponDto) LoadInquiryType(m string) *CouponDto {
|
||
if m != "" {
|
||
inquiryType := strings.Split(m, ",")
|
||
|
||
r.InquiryType = inquiryType
|
||
}
|
||
return r
|
||
}
|