Merge remote-tracking branch 'origin/mark' into yonghui
This commit is contained in:
@@ -21,11 +21,6 @@ import (
|
||||
|
||||
const (
|
||||
DefActSkuStock = 200 // 缺省活动库存
|
||||
|
||||
maxDiscount4SkuSecKill = 80
|
||||
maxDiscount4Sku = 98
|
||||
minDiscount4SkuDirectDown = 0
|
||||
minDiscount4SkuDirectDownMTWM = 30
|
||||
)
|
||||
|
||||
type ActOrderRuleParam struct {
|
||||
@@ -64,11 +59,71 @@ type tPreCreateActInfo struct {
|
||||
ActStoreSku []*tPreCreateActStoreSku `json:"actStoreSku"`
|
||||
}
|
||||
|
||||
type tActRuleInfo struct {
|
||||
MinDiscount int
|
||||
MaxDiscount int
|
||||
}
|
||||
|
||||
type ActManager struct {
|
||||
}
|
||||
|
||||
var (
|
||||
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() {
|
||||
@@ -256,11 +311,28 @@ func addActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actStoreSkuList [
|
||||
return err
|
||||
}
|
||||
|
||||
func checkActUpdate(actID int, actMap map[int]*model.Act2) (err error) {
|
||||
if len(actMap) == 0 {
|
||||
return fmt.Errorf("活动%d不存在或已被取消", actID)
|
||||
}
|
||||
errList := errlist.New()
|
||||
for vendorID, act := range actMap {
|
||||
if vendorID == model.VendorIDEBAI && act.CreateType != model.ActCreateTypeAPI {
|
||||
errList.AddErr(fmt.Errorf("饿百平台不支持修改或取消网页活动"))
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actStoreSku []*ActStoreSkuParam) (err error) {
|
||||
actMap, err := dao.GetActVendorInfo(db, actID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = checkActUpdate(actID, actMap); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
vendorIDs := partner.GetVendorIDsFromActMap(actMap)
|
||||
|
||||
var act *model.Act
|
||||
@@ -309,25 +381,33 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
|
||||
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) {
|
||||
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)
|
||||
errList := errlist.New()
|
||||
for _, vendorID := range vendorIDs {
|
||||
actRule, err2 := getActRule(vendorID, actType)
|
||||
if err2 == nil {
|
||||
if pricePercentageMin < actRule.MinDiscount {
|
||||
errList.AddErr(fmt.Errorf("%s%s活动折扣必须大于:%d", model.VendorChineseNames[vendorID], model.ActTypeName[actType], actRule.MinDiscount))
|
||||
} else if pricePercentageMax > actRule.MaxDiscount {
|
||||
errList.AddErr(fmt.Errorf("%s%s活动折扣必须小于:%d", model.VendorChineseNames[vendorID], model.ActTypeName[actType], actRule.MaxDiscount))
|
||||
}
|
||||
} else {
|
||||
errList.AddErr(err2)
|
||||
}
|
||||
}
|
||||
return err
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
|
||||
@@ -644,8 +724,8 @@ func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, act
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(actMap) == 0 {
|
||||
return 0, fmt.Errorf("找不到活动:%d,或已被取消", actID)
|
||||
if err = checkActUpdate(actID, actMap); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
actStoreSkuMap, err := dao.GetActStoreSkuVendorInfo(db, actID, nil, nil, nil)
|
||||
@@ -958,6 +1038,7 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
|
||||
var wrongSkuList []*ActStoreSkuParam
|
||||
var storeSkuBindList []*model.StoreSkuBind
|
||||
|
||||
actRule, _ := getActRule(vendorID, actType)
|
||||
db := dao.GetDB()
|
||||
errList := errlist.New()
|
||||
for _, v := range storeSkuList {
|
||||
@@ -978,11 +1059,7 @@ func ForceUpdateVendorPrice(ctx *jxcontext.Context, vendorID int, actType int, s
|
||||
} else {
|
||||
vendorPrice = dao.GetStoreSkuBindVendorPrice(storeSkuBind, vendorID)
|
||||
if checkDiscountValidation([]int{vendorID}, actType, float64(v.ActPrice)*100/float64(vendorPrice)) != nil {
|
||||
if actType == model.ActSkuSecKill {
|
||||
vendorPrice = int(v.ActPrice)*100/maxDiscount4SkuSecKill + 10
|
||||
} else if actType == model.ActSkuDirectDown {
|
||||
vendorPrice = int(v.ActPrice) + 10
|
||||
}
|
||||
vendorPrice = int(v.ActPrice)*100/actRule.MaxDiscount + 10
|
||||
} else {
|
||||
storeSkuBind = nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user