新增了:新增系统优惠卷接口
This commit is contained in:
parent
76e1bd831a
commit
44f9cdcb93
@ -6,8 +6,10 @@ import (
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Coupon struct{}
|
||||
@ -56,3 +58,55 @@ func (r *Coupon) GetSystemCouponPage(c *gin.Context) {
|
||||
result["data"] = GetProductPlatformPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetSystemCoupon 系统优惠卷详情
|
||||
func (r *Coupon) GetSystemCoupon(c *gin.Context) {
|
||||
id := c.Param("coupon_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
couponId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
couponService := service.CouponService{}
|
||||
getSystemCouponResponses, err := couponService.GetSystemCoupon(couponId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getSystemCouponResponses, c)
|
||||
}
|
||||
|
||||
// AddSystemCoupon 新增系统优惠卷
|
||||
func (r *Coupon) AddSystemCoupon(c *gin.Context) {
|
||||
couponRequest := requests.CouponRequest{}
|
||||
req := couponRequest.AddSystemCoupon
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
couponService := service.CouponService{}
|
||||
_, err := couponService.AddSystemCoupon(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@ -3,40 +3,41 @@ package dto
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/utils"
|
||||
)
|
||||
|
||||
// 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"` // 修改时间
|
||||
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"` // 修改时间
|
||||
}
|
||||
|
||||
// GetCouponDto 优惠卷详情
|
||||
@ -44,7 +45,7 @@ func GetCouponDto(m *model.Coupon) *CouponDto {
|
||||
return &CouponDto{
|
||||
CouponId: fmt.Sprintf("%d", m.CouponId),
|
||||
CouponName: m.CouponName,
|
||||
CouponIcon: m.CouponIcon,
|
||||
CouponIcon: utils.AddOssDomain(m.CouponIcon),
|
||||
CouponClient: m.CouponClient,
|
||||
CouponType: m.CouponType,
|
||||
CouponStatus: m.CouponStatus,
|
||||
@ -85,7 +86,7 @@ func GetCouponListDto(m []*model.Coupon) []*CouponDto {
|
||||
response := &CouponDto{
|
||||
CouponId: fmt.Sprintf("%d", v.CouponId),
|
||||
CouponName: v.CouponName,
|
||||
CouponIcon: v.CouponIcon,
|
||||
CouponIcon: utils.AddOssDomain(v.CouponIcon),
|
||||
CouponClient: v.CouponClient,
|
||||
CouponType: v.CouponType,
|
||||
CouponStatus: v.CouponStatus,
|
||||
|
||||
@ -8,34 +8,34 @@ import (
|
||||
|
||||
// Coupon 优惠卷表
|
||||
type Coupon struct {
|
||||
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);primary_key;comment:主键id" json:"coupon_id"`
|
||||
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
|
||||
CouponIcon string `gorm:"column:coupon_icon;type:varchar(255);comment:优惠卷图片" json:"coupon_icon"`
|
||||
CouponClient int `gorm:"column:coupon_client;type:tinyint(1);comment:使用平台(1:小程序);NOT NULL" json:"coupon_client"`
|
||||
CouponType int `gorm:"column:coupon_type;type:tinyint(1);comment:优惠卷类型(1:无门槛 2:满减 3:数量);NOT NULL" json:"coupon_type"`
|
||||
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态(1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
|
||||
DistributionObject int `gorm:"column:distribution_object;type:tinyint(1);default:1;comment:发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)" json:"distribution_object"`
|
||||
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)" json:"application_scope"`
|
||||
InquiryType string `gorm:"column:inquiry_type;type:varchar(100);comment:关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)" json:"inquiry_type"`
|
||||
BrandId int64 `gorm:"column:brand_id;type:bigint(19);comment:关联品牌id(如不限制品牌,此项为空)" json:"brand_id"`
|
||||
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
|
||||
IsDisplay int `gorm:"column:is_display;type:tinyint(1);comment:是否展示(0:否 1:是)" json:"is_display"`
|
||||
DistributionWithDay int `gorm:"column:distribution_with_day;type:int(11);default:0;comment:发放关联天数(发放对象为近期消费等类型时规定天数)" json:"distribution_with_day"`
|
||||
MinUsableNumber int `gorm:"column:min_usable_number;type:int(11);default:1;comment:单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)" json:"min_usable_number"`
|
||||
CouponCount int `gorm:"column:coupon_count;type:int(10);default:0;comment:发放数量" json:"coupon_count"`
|
||||
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);default:0;comment:已领取数量" json:"coupon_take_count"`
|
||||
CouponUsedCount int `gorm:"column:coupon_used_count;type:int(10);default:0;comment:已使用数量" json:"coupon_used_count"`
|
||||
CouponPrice float64 `gorm:"column:coupon_price;type:decimal(10,2);default:0.00;comment:优惠卷金额" json:"coupon_price"`
|
||||
WithAmount float64 `gorm:"column:with_amount;type:decimal(10,2);default:0.00;comment:符合满减标准金额(优惠卷类型为满减时使用)" json:"with_amount"`
|
||||
ValidType int `gorm:"column:valid_type;type:tinyint(4);comment:有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效);NOT NULL" json:"valid_type"`
|
||||
ValidDays int `gorm:"column:valid_days;type:int(3);comment:自领取之日起有效天数" json:"valid_days"`
|
||||
ValidStartTime LocalTime `gorm:"column:valid_start_time;type:datetime;comment:开始使用时间" json:"valid_start_time"`
|
||||
ValidEndTime LocalTime `gorm:"column:valid_end_time;type:datetime;comment:结束使用时间" json:"valid_end_time"`
|
||||
ProductId string `gorm:"column:product_id;type:text;comment:关联商品id,逗号分隔,指定商品时,填入此项。" json:"product_id"`
|
||||
ReissueIntervalDays int `gorm:"column:reissue_interval_days;type:int(5);default:0;comment:确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效)" json:"reissue_interval_days"`
|
||||
IsReissuableAfterExpire int `gorm:"column:is_reissuable_after_expire;type:tinyint(1);default:0;comment:过期之后是否允许再次发放(0:否 1:是)" json:"is_reissuable_after_expire"`
|
||||
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"`
|
||||
CouponId int64 `gorm:"column:coupon_id;type:bigint(19);primary_key;comment:主键id" json:"coupon_id"`
|
||||
CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"`
|
||||
CouponIcon string `gorm:"column:coupon_icon;type:varchar(255);comment:优惠卷图片" json:"coupon_icon"`
|
||||
CouponClient int `gorm:"column:coupon_client;type:tinyint(1);comment:使用平台(1:小程序);NOT NULL" json:"coupon_client"`
|
||||
CouponType int `gorm:"column:coupon_type;type:tinyint(1);comment:优惠卷类型(1:无门槛 2:满减 3:数量);NOT NULL" json:"coupon_type"`
|
||||
CouponStatus int `gorm:"column:coupon_status;type:tinyint(1);default:1;comment:状态(1:正常 2:强制失效 3:结束 4:删除)" json:"coupon_status"`
|
||||
DistributionObject int `gorm:"column:distribution_object;type:tinyint(1);default:1;comment:发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)" json:"distribution_object"`
|
||||
ApplicationScope int `gorm:"column:application_scope;type:tinyint(1);default:1;comment:适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)" json:"application_scope"`
|
||||
InquiryType string `gorm:"column:inquiry_type;type:varchar(100);comment:关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)" json:"inquiry_type"`
|
||||
BrandId *int64 `gorm:"column:brand_id;type:bigint(19);comment:关联品牌id(如不限制品牌,此项为空)" json:"brand_id"`
|
||||
IsMutex int `gorm:"column:is_mutex;type:tinyint(1);default:1;comment:是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用" json:"is_mutex"`
|
||||
IsDisplay int `gorm:"column:is_display;type:tinyint(1);comment:是否展示(0:否 1:是)" json:"is_display"`
|
||||
DistributionWithDay int `gorm:"column:distribution_with_day;type:int(11);default:0;comment:发放关联天数(发放对象为近期消费等类型时规定天数)" json:"distribution_with_day"`
|
||||
MinUsableNumber int `gorm:"column:min_usable_number;type:int(11);default:1;comment:单商品最小可使用数量(默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)" json:"min_usable_number"`
|
||||
CouponCount int `gorm:"column:coupon_count;type:int(10);default:0;comment:发放数量" json:"coupon_count"`
|
||||
CouponTakeCount int `gorm:"column:coupon_take_count;type:int(10);default:0;comment:已领取数量" json:"coupon_take_count"`
|
||||
CouponUsedCount int `gorm:"column:coupon_used_count;type:int(10);default:0;comment:已使用数量" json:"coupon_used_count"`
|
||||
CouponPrice float64 `gorm:"column:coupon_price;type:decimal(10,2);default:0.00;comment:优惠卷金额" json:"coupon_price"`
|
||||
WithAmount float64 `gorm:"column:with_amount;type:decimal(10,2);default:0.00;comment:符合满减标准金额(优惠卷类型为满减时使用)" json:"with_amount"`
|
||||
ValidType int `gorm:"column:valid_type;type:tinyint(4);comment:有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效);NOT NULL" json:"valid_type"`
|
||||
ValidDays int `gorm:"column:valid_days;type:int(3);comment:自领取之日起有效天数" json:"valid_days"`
|
||||
ValidStartTime *LocalTime `gorm:"column:valid_start_time;type:datetime;comment:开始使用时间" json:"valid_start_time"`
|
||||
ValidEndTime *LocalTime `gorm:"column:valid_end_time;type:datetime;comment:结束使用时间" json:"valid_end_time"`
|
||||
ProductId string `gorm:"column:product_id;type:text;comment:关联商品id,逗号分隔,指定商品时,填入此项。" json:"product_id"`
|
||||
ReissueIntervalDays int `gorm:"column:reissue_interval_days;type:int(5);default:0;comment:确认收货后的再次发放间隔天数(如果设置为 0,则表示不再次发放。当适用范围为商品时生效)" json:"reissue_interval_days"`
|
||||
IsReissuableAfterExpire int `gorm:"column:is_reissuable_after_expire;type:tinyint(1);default:0;comment:过期之后是否允许再次发放(0:否 1:是)" json:"is_reissuable_after_expire"`
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package requests
|
||||
|
||||
type CouponRequest struct {
|
||||
GetSystemCouponPage // 获取系统优惠卷列表-分页
|
||||
AddSystemCoupon // 新增系统优惠卷
|
||||
}
|
||||
|
||||
// GetSystemCouponPage 获取系统优惠卷列表-分页
|
||||
@ -24,3 +25,31 @@ type GetSystemCouponPage struct {
|
||||
CouponDesc string `json:"coupon_desc" form:"coupon_desc" label:"优惠卷描述"`
|
||||
CreatedAt string `json:"created_at" form:"created_at" label:"创建时间"` // 创建时间
|
||||
}
|
||||
|
||||
// AddSystemCoupon 新增系统优惠卷
|
||||
type AddSystemCoupon struct {
|
||||
CouponName string `json:"coupon_name" form:"coupon_name" label:"优惠卷名称" validate:"required"` // 优惠卷名称
|
||||
CouponIcon string `json:"coupon_icon" form:"coupon_icon" label:"头像"` // 优惠卷名称
|
||||
CouponClient *int `json:"coupon_client" form:"coupon_client" label:"使用平台" validate:"required,oneof=1"` // 使用平台(1:小程序)
|
||||
CouponType *int `json:"coupon_type" form:"coupon_type" label:"优惠卷类型" validate:"required,oneof=1 2 3"` // 优惠卷类型(1 :无门槛 2:满减 3:数量)
|
||||
DistributionObject *int `json:"distribution_object" form:"distribution_object" label:"发放对象" validate:"required,oneof=1 2 3 4 5 6 7"`
|
||||
ApplicationScope *int `json:"application_scope" form:"application_scope" label:"适用范围" validate:"required,oneof=1 2 3 4 5 6"`
|
||||
InquiryType *string `json:"inquiry_type" form:"inquiry_type" label:"关联问诊类型" validate:"omitempty,oneof=1 2 3 4 5 6"` // 关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)
|
||||
BrandId *string `json:"brand_id" form:"brand_id" label:"关联品牌id"` // 关联品牌id(如不限制品牌,此项为空)
|
||||
IsMutex *int `json:"is_mutex" form:"is_mutex" label:"是否互斥" validate:"required,oneof=0 1"` // 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
|
||||
IsDisplay *int `json:"is_display" form:"is_display" label:"是否展示" validate:"required,oneof=0 1"` // 是否展示(0:否 1:是)
|
||||
DistributionWithDay *int `json:"distribution_with_day" form:"distribution_with_day" label:"发放关联天数" validate:"omitempty,numeric,min=1"` // (发放对象为近期消费等类型时规定天数)
|
||||
MinUsableNumber *int `json:"min_usable_number" form:"min_usable_number" label:"单商品最小可使用数量" validate:"omitempty,numeric,min=1"` // (默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)
|
||||
CouponCount *int `json:"coupon_count" form:"coupon_count" label:"发放数量" validate:"required,number,min=1"` // (默认为1,类型为数量时使用,如需限制优惠卷使用数量,请填写此处)
|
||||
CouponPrice *float64 `json:"coupon_price" form:"coupon_price" label:"优惠卷金额" validate:"required,numeric,gt=0"`
|
||||
WithAmount *float64 `json:"with_amount" form:"with_amount" label:"符合满减标准金额" validate:"omitempty,gt=1"` // (优惠卷类型为满减时使用)
|
||||
ValidType *int `json:"valid_type" form:"valid_type" label:"有效类型" validate:"required,oneof=1 2"` // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
||||
ValidDays *int `json:"valid_days" form:"valid_days" label:"自领取之日起有效天数" validate:"omitempty,numeric,min=1"` // 自领取之日起有效天数
|
||||
ValidStartTime *string `json:"valid_start_time" form:"valid_start_time" label:"开始使用时间"` // 开始使用时间
|
||||
ValidEndTime *string `json:"valid_end_time" form:"valid_end_time" label:"结束使用时间"` // 结束使用时间
|
||||
ProductId []string `json:"product_id" form:"product_id" label:"关联商品id"` // ,逗号分隔,指定商品时,填入此项。
|
||||
ReissueIntervalDays *int `json:"reissue_interval_days" form:"reissue_interval_days" label:"确认收货后的再次发放间隔天数" validate:"omitempty,numeric,min=0"` // (如果设置为 0,则表示不再次发放。当适用范围为商品时生效)
|
||||
IsReissuableAfterExpire *int `json:"is_reissuable_after_expire" form:"is_reissuable_after_expire" label:"过期之后是否允许再次发放" validate:"omitempty,oneof=0 1"` // 过期之后是否允许再次发放(0:否 1:是)
|
||||
IsPopup *int `json:"is_popup" form:"is_popup" label:"是否首页弹窗" validate:"required,oneof=0 1"` // 是否首页弹窗(0:否 1:是)
|
||||
CouponDesc *string `json:"coupon_desc" form:"coupon_desc" label:"优惠卷描述"`
|
||||
}
|
||||
|
||||
@ -730,13 +730,13 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
systemGroup.POST("/page", api.Coupon.GetSystemCouponPage)
|
||||
|
||||
// 系统优惠卷详情
|
||||
systemGroup.GET("/:product_id", api.Product.GetProduct)
|
||||
systemGroup.GET("/:coupon_id", api.Coupon.GetSystemCoupon)
|
||||
|
||||
// 新增系统优惠卷
|
||||
systemGroup.POST("", api.Product.AddProduct)
|
||||
systemGroup.POST("", api.Coupon.AddSystemCoupon)
|
||||
|
||||
// 修改系统优惠卷
|
||||
systemGroup.PUT("/:product_id", api.Product.PutProduct)
|
||||
systemGroup.PUT("/:coupon_id", api.Product.PutProduct)
|
||||
|
||||
// 修改系统优惠卷状态
|
||||
systemGroup.PUT("/status/:product_id", api.Product.PutProductStatus)
|
||||
|
||||
250
api/service/coupon.go
Normal file
250
api/service/coupon.go
Normal file
@ -0,0 +1,250 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CouponService struct {
|
||||
}
|
||||
|
||||
// GetSystemCoupon 系统优惠卷详情
|
||||
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, err := couponDao.GetCouponById(couponId)
|
||||
if err != nil || coupon == nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g = dto.GetCouponDto(coupon)
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// AddSystemCoupon 新增系统优惠卷
|
||||
func (r *CouponService) AddSystemCoupon(req requests.AddSystemCoupon) (bool, error) {
|
||||
// 满减
|
||||
if *req.CouponType == 2 {
|
||||
if *req.WithAmount == 0 {
|
||||
return false, errors.New("请填入符合满减标准金额")
|
||||
}
|
||||
}
|
||||
|
||||
// 数量
|
||||
if *req.CouponType == 3 {
|
||||
if *req.MinUsableNumber == 0 {
|
||||
return false, errors.New("请填入单商品最小可使用数量")
|
||||
}
|
||||
}
|
||||
|
||||
// 发放对象-近期消费
|
||||
if *req.DistributionObject == 4 {
|
||||
if *req.DistributionWithDay == 0 {
|
||||
return false, errors.New("请填入发放关联天数")
|
||||
}
|
||||
}
|
||||
|
||||
// 适用范围-全场通用
|
||||
if *req.ApplicationScope == 1 {
|
||||
// 满减
|
||||
if *req.CouponType == 2 {
|
||||
if *req.WithAmount == 0 {
|
||||
return false, errors.New("请填入符合满减标准金额")
|
||||
}
|
||||
}
|
||||
|
||||
// 数量
|
||||
if *req.CouponType == 3 {
|
||||
if *req.MinUsableNumber == 0 {
|
||||
return false, errors.New("请填入单商品最小可使用数量")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 适用范围-问诊
|
||||
if *req.ApplicationScope == 2 {
|
||||
// 关联问诊类型
|
||||
if req.InquiryType == nil {
|
||||
return false, errors.New("请填入关联问诊类型")
|
||||
}
|
||||
}
|
||||
|
||||
// 适用范围-按品牌适用
|
||||
if *req.ApplicationScope == 3 {
|
||||
// 关联品牌id
|
||||
if req.BrandId == nil {
|
||||
return false, errors.New("请填入关联品牌")
|
||||
}
|
||||
}
|
||||
|
||||
// 适用范围-单品使用
|
||||
if *req.ApplicationScope == 5 {
|
||||
// 关联商品id
|
||||
if len(req.ProductId) == 0 {
|
||||
return false, errors.New("请填入关联商品")
|
||||
}
|
||||
|
||||
productDao := dao.ProductDao{}
|
||||
for _, s := range req.ProductId {
|
||||
// 将 id 转换为 int64 类型
|
||||
productId, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
_, err = productDao.GetProductById(productId)
|
||||
if err != nil {
|
||||
return false, errors.New("存在错误商品")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 有效类型-绝对时效
|
||||
if *req.ValidType == 1 {
|
||||
if req.ValidStartTime == nil {
|
||||
return false, errors.New("请填入开始使用时间")
|
||||
}
|
||||
|
||||
if req.ValidEndTime == nil {
|
||||
return false, errors.New("请填入结束使用时间")
|
||||
}
|
||||
}
|
||||
|
||||
// 有效类型-相对时效
|
||||
if *req.ValidType == 2 {
|
||||
if req.ValidDays == nil {
|
||||
return false, errors.New("请填入有效天数")
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
fmt.Println(r)
|
||||
}
|
||||
}()
|
||||
|
||||
// 新增优惠卷表
|
||||
coupon := &model.Coupon{
|
||||
CouponName: req.CouponName,
|
||||
CouponIcon: utils.AddOssDomain(req.CouponIcon),
|
||||
CouponClient: *req.CouponClient,
|
||||
CouponType: *req.CouponType,
|
||||
CouponStatus: *req.CouponClient,
|
||||
DistributionObject: *req.DistributionObject,
|
||||
ApplicationScope: *req.ApplicationScope,
|
||||
IsMutex: *req.IsMutex,
|
||||
IsDisplay: *req.IsDisplay,
|
||||
CouponCount: *req.CouponCount,
|
||||
CouponPrice: *req.CouponPrice,
|
||||
ValidType: *req.ValidType,
|
||||
IsPopup: *req.IsPopup,
|
||||
}
|
||||
|
||||
// 关联品牌id
|
||||
if req.BrandId != nil {
|
||||
// 将 id 转换为 int64 类型
|
||||
brandId, err := strconv.ParseInt(*req.BrandId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
coupon.BrandId = &brandId
|
||||
}
|
||||
|
||||
// 时间区间
|
||||
if req.ValidStartTime != nil {
|
||||
t, err := time.Parse("2006-01-02", *req.ValidStartTime)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
validStartTime := model.LocalTime(t)
|
||||
|
||||
coupon.ValidStartTime = &validStartTime
|
||||
}
|
||||
|
||||
if req.ValidEndTime != nil {
|
||||
t, err := time.Parse("2006-01-02", *req.ValidEndTime)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
ValidEndTime := model.LocalTime(t)
|
||||
|
||||
coupon.ValidEndTime = &ValidEndTime
|
||||
}
|
||||
|
||||
// 关联商品id
|
||||
if req.ProductId != nil {
|
||||
productId := strings.Join(req.ProductId, ",")
|
||||
if productId != "" {
|
||||
coupon.ProductId = productId
|
||||
}
|
||||
}
|
||||
|
||||
// 关联问诊类型
|
||||
if req.InquiryType != nil {
|
||||
coupon.InquiryType = *req.InquiryType
|
||||
}
|
||||
|
||||
// 发放关联天数
|
||||
if req.DistributionWithDay != nil {
|
||||
coupon.DistributionWithDay = *req.DistributionWithDay
|
||||
}
|
||||
|
||||
// 关联 单商品最小可使用数量
|
||||
if req.DistributionWithDay != nil {
|
||||
coupon.DistributionWithDay = *req.DistributionWithDay
|
||||
}
|
||||
|
||||
// 符合满减标准金额
|
||||
if req.WithAmount != nil {
|
||||
coupon.WithAmount = *req.WithAmount
|
||||
}
|
||||
|
||||
// 有效天数
|
||||
if req.ValidDays != nil {
|
||||
coupon.ValidDays = *req.ValidDays
|
||||
}
|
||||
|
||||
// 再次发放间隔天数
|
||||
if req.ReissueIntervalDays != nil {
|
||||
coupon.ReissueIntervalDays = *req.ReissueIntervalDays
|
||||
}
|
||||
|
||||
// 允许再次发放
|
||||
if req.IsReissuableAfterExpire != nil {
|
||||
coupon.IsReissuableAfterExpire = *req.IsReissuableAfterExpire
|
||||
}
|
||||
|
||||
// 优惠卷描述
|
||||
if req.CouponDesc != nil {
|
||||
coupon.CouponDesc = *req.CouponDesc
|
||||
}
|
||||
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, err := couponDao.AddCoupon(tx, coupon)
|
||||
if err != nil || coupon == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user