修改活动校验规则
This commit is contained in:
@@ -23,7 +23,7 @@ const (
|
|||||||
DefActSkuStock = 200 // 缺省活动库存
|
DefActSkuStock = 200 // 缺省活动库存
|
||||||
|
|
||||||
maxDiscount4SkuSecKill = 80
|
maxDiscount4SkuSecKill = 80
|
||||||
maxDiscount4Sku = 98
|
maxDiscount4Sku = 99
|
||||||
minDiscount4SkuDirectDown = 0
|
minDiscount4SkuDirectDown = 0
|
||||||
minDiscount4SkuDirectDownMTWM = 30
|
minDiscount4SkuDirectDownMTWM = 30
|
||||||
)
|
)
|
||||||
@@ -64,11 +64,71 @@ type tPreCreateActInfo struct {
|
|||||||
ActStoreSku []*tPreCreateActStoreSku `json:"actStoreSku"`
|
ActStoreSku []*tPreCreateActStoreSku `json:"actStoreSku"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tActRuleInfo struct {
|
||||||
|
MinDiscount int
|
||||||
|
MaxDiscount int
|
||||||
|
}
|
||||||
|
|
||||||
type ActManager struct {
|
type ActManager struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
FixedActManager *ActManager
|
FixedActManager *ActManager
|
||||||
|
|
||||||
|
actRuleMap = map[int]map[int]*tActRuleInfo{
|
||||||
|
model.VendorIDJD: map[int]*tActRuleInfo{
|
||||||
|
model.ActSkuFake: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 500,
|
||||||
|
},
|
||||||
|
model.ActSkuDirectDown: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 99,
|
||||||
|
},
|
||||||
|
model.ActSkuSecKill: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
model.VendorIDMTWM: map[int]*tActRuleInfo{
|
||||||
|
model.ActSkuFake: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 500,
|
||||||
|
},
|
||||||
|
model.ActSkuDirectDown: &tActRuleInfo{
|
||||||
|
MinDiscount: 30,
|
||||||
|
MaxDiscount: 99,
|
||||||
|
},
|
||||||
|
model.ActSkuSecKill: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 30,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
model.VendorIDEBAI: map[int]*tActRuleInfo{
|
||||||
|
model.ActSkuFake: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 500,
|
||||||
|
},
|
||||||
|
model.ActSkuDirectDown: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 99,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
model.VendorIDJX: map[int]*tActRuleInfo{
|
||||||
|
model.ActSkuFake: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 500,
|
||||||
|
},
|
||||||
|
model.ActSkuDirectDown: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 99,
|
||||||
|
},
|
||||||
|
model.ActSkuSecKill: &tActRuleInfo{
|
||||||
|
MinDiscount: 0,
|
||||||
|
MaxDiscount: 80,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -309,25 +369,54 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func checkDiscountValidation(vendorIDs []int, actType int, pricePercentage float64) (err error) {
|
||||||
|
// pricePercentageMin := int(math.Floor(pricePercentage))
|
||||||
|
// pricePercentageMax := int(math.Ceil(pricePercentage))
|
||||||
|
// if actType == model.ActSkuDirectDown && (pricePercentageMin < minDiscount4SkuDirectDown || pricePercentageMax > 99) {
|
||||||
|
// if pricePercentageMin < minDiscount4SkuDirectDown {
|
||||||
|
// err = fmt.Errorf("%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDown)
|
||||||
|
// } else if pricePercentageMax > maxDiscount4Sku {
|
||||||
|
// err = fmt.Errorf("%s活动必须至少有%d折扣", model.ActTypeName[actType], maxDiscount4Sku)
|
||||||
|
// } else if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMin < minDiscount4SkuDirectDownMTWM {
|
||||||
|
// err = fmt.Errorf("美团平台%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM)
|
||||||
|
// }
|
||||||
|
// } else if actType == model.ActSkuSecKill {
|
||||||
|
// if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMax > minDiscount4SkuDirectDownMTWM {
|
||||||
|
// err = fmt.Errorf("美团平台%s活动折扣必须小于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM)
|
||||||
|
// } else if pricePercentageMax > maxDiscount4SkuSecKill {
|
||||||
|
// err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
|
||||||
|
func getActRule(vendorID, actType int) (actRule *tActRuleInfo, err error) {
|
||||||
|
if actRuleMap[vendorID] != nil {
|
||||||
|
actRule = actRuleMap[vendorID][actType]
|
||||||
|
}
|
||||||
|
if actRule == nil {
|
||||||
|
err = fmt.Errorf("%s不支持%s活动", model.VendorChineseNames[vendorID], model.ActTypeName[actType])
|
||||||
|
}
|
||||||
|
return actRule, err
|
||||||
|
}
|
||||||
|
|
||||||
func checkDiscountValidation(vendorIDs []int, actType int, pricePercentage float64) (err error) {
|
func checkDiscountValidation(vendorIDs []int, actType int, pricePercentage float64) (err error) {
|
||||||
pricePercentageMin := int(math.Floor(pricePercentage))
|
pricePercentageMin := int(math.Floor(pricePercentage))
|
||||||
pricePercentageMax := int(math.Ceil(pricePercentage))
|
pricePercentageMax := int(math.Ceil(pricePercentage))
|
||||||
if actType == model.ActSkuDirectDown && (pricePercentageMin < minDiscount4SkuDirectDown || pricePercentageMax > 99) {
|
errList := errlist.New()
|
||||||
if pricePercentageMin < minDiscount4SkuDirectDown {
|
for _, vendorID := range vendorIDs {
|
||||||
err = fmt.Errorf("%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDown)
|
actRule, err2 := getActRule(vendorID, actType)
|
||||||
} else if pricePercentageMax > maxDiscount4Sku {
|
if err2 == nil {
|
||||||
err = fmt.Errorf("%s活动必须至少有%d折扣", model.ActTypeName[actType], maxDiscount4Sku)
|
if pricePercentageMin < actRule.MinDiscount {
|
||||||
} else if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMin < minDiscount4SkuDirectDownMTWM {
|
errList.AddErr(fmt.Errorf("%s%s活动折扣必须大于:%d", model.VendorChineseNames[vendorID], model.ActTypeName[actType], actRule.MinDiscount))
|
||||||
err = fmt.Errorf("美团平台%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM)
|
} else if pricePercentageMax > actRule.MaxDiscount {
|
||||||
|
errList.AddErr(fmt.Errorf("%s%s活动折扣必须小于:%d", model.VendorChineseNames[vendorID], model.ActTypeName[actType], actRule.MaxDiscount))
|
||||||
}
|
}
|
||||||
} else if actType == model.ActSkuSecKill {
|
} else {
|
||||||
if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMax > minDiscount4SkuDirectDownMTWM {
|
errList.AddErr(err2)
|
||||||
err = fmt.Errorf("美团平台%s活动折扣必须小于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM)
|
|
||||||
} else if pricePercentageMax > maxDiscount4SkuSecKill {
|
|
||||||
err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return errList.GetErrListAsOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
|
func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user