修改了优惠卷数据
This commit is contained in:
+26
-44
@@ -11,6 +11,7 @@ import (
|
||||
"hepa-calc-admin-api/global"
|
||||
"hepa-calc-admin-api/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -84,6 +85,9 @@ func (b *Coupon) GetCoupon(c *gin.Context) {
|
||||
// 处理返回值
|
||||
g := dto.GetCouponDto(coupon)
|
||||
|
||||
// 加载会员id
|
||||
g.LoadSystemMemberIds(coupon.SystemMemberIds)
|
||||
|
||||
responses.OkWithData(g, c)
|
||||
}
|
||||
|
||||
@@ -174,29 +178,32 @@ func (r *Coupon) AddSystemCoupon(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 适用范围(1:全场通用 2:单项 3:会员)
|
||||
if req.ApplicationScope == 1 {
|
||||
// 全场通用
|
||||
if req.QuestionId == nil && req.SystemMemberId == nil {
|
||||
responses.FailWithMessage("请填入关联选项", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if req.ApplicationScope == 2 {
|
||||
// 单项
|
||||
if req.QuestionId == nil {
|
||||
responses.FailWithMessage("请填入关联算一算", c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 适用范围(1:全场通用 2:单项 3:会员)
|
||||
systemMemberIds := make([]string, len(req.SystemMemberIds))
|
||||
if req.ApplicationScope == 3 {
|
||||
// 会员
|
||||
if req.SystemMemberId == nil {
|
||||
if req.SystemMemberIds == nil {
|
||||
responses.FailWithMessage("请填入关联会员", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 关联会员id
|
||||
systemMemberDao := dao.SystemMemberDao{}
|
||||
|
||||
for i, id := range req.SystemMemberIds {
|
||||
systemMemberId, err := strconv.ParseInt(*id, 10, 64)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
systemMember, err := systemMemberDao.GetSystemMemberById(systemMemberId)
|
||||
if err != nil || systemMember == nil {
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
systemMemberIds[i] = *id
|
||||
}
|
||||
}
|
||||
|
||||
// 有效类型-绝对时效
|
||||
@@ -244,8 +251,7 @@ func (r *Coupon) AddSystemCoupon(c *gin.Context) {
|
||||
ValidStartTime: nil,
|
||||
ValidEndTime: nil,
|
||||
CouponDesc: req.CouponDesc,
|
||||
QuestionId: nil,
|
||||
SystemMemberId: nil,
|
||||
SystemMemberIds: strings.Join(systemMemberIds, ","),
|
||||
}
|
||||
|
||||
// 符合满减标准金额
|
||||
@@ -310,30 +316,6 @@ func (r *Coupon) AddSystemCoupon(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// 关联单项id
|
||||
if req.QuestionId != nil {
|
||||
questionId, err := strconv.ParseInt(*req.QuestionId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
coupon.QuestionId = &questionId
|
||||
}
|
||||
|
||||
// 关联会员id
|
||||
if req.SystemMemberId != nil {
|
||||
systemMemberId, err := strconv.ParseInt(*req.SystemMemberId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage("新增失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
coupon.QuestionId = &systemMemberId
|
||||
}
|
||||
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, err := couponDao.AddCoupon(tx, coupon)
|
||||
if err != nil || coupon == nil {
|
||||
|
||||
Reference in New Issue
Block a user