- checkActValidation

This commit is contained in:
gazebo
2019-07-04 17:49:49 +08:00
parent c3400dcc2c
commit 9eac3047d8
3 changed files with 45 additions and 5 deletions

View File

@@ -17,6 +17,9 @@ import (
const (
DefActSkuStock = 200 // 缺省活动库存
maxDiscount4SkuSecKill = 60
minDiscount4SkuDirectDown = 40
)
type ActOrderRuleParam struct {
@@ -205,9 +208,38 @@ func AddActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, actSto
return err
}
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam, isAsync bool) (hint string, err error) {
db := dao.GetDB()
func checkActValidation(act *model.Act, vendorIDs []int) (err error) {
vendorIDMap := make(map[int]int)
for _, vendorID := range vendorIDs {
vendorIDMap[vendorID] = 1
}
if act.Type == model.ActSkuDirectDown || act.Type == model.ActSkuSecKill {
if act.PricePercentage == 0 {
return fmt.Errorf("活动必须指定价格折扣")
}
if act.Type == model.ActSkuDirectDown {
if vendorIDMap[model.VendorIDMTWM] == 1 {
return fmt.Errorf("平台%s暂不支持%s活动", model.VendorChineseNames[model.VendorIDMTWM], model.ActTypeName[act.Type])
} else if act.PricePercentage <= minDiscount4SkuDirectDown || act.PricePercentage >= 100 {
return fmt.Errorf("%s活动折扣必须大于:%d, 且必须有折扣", model.ActTypeName[act.Type], minDiscount4SkuDirectDown)
}
}
if act.Type == model.ActSkuSecKill && act.PricePercentage >= maxDiscount4SkuSecKill {
return fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[act.Type], maxDiscount4SkuSecKill)
}
} else {
return fmt.Errorf("当前只支持直降与秒杀活动")
}
return nil
}
func CreateAct(ctx *jxcontext.Context, act *model.Act, vendorIDs []int, actRules []*ActOrderRuleParam, actStoreSku []*ActStoreSkuParam, isAsync bool) (hint string, err error) {
if err = checkActValidation(act, vendorIDs); err != nil {
return "", err
}
db := dao.GetDB()
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
@@ -426,9 +458,15 @@ func SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITask, actID int, vendor
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
vendorID := batchItemList[0].(int)
if handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformActHandler); handler != nil {
tmpActMap := &model.ActMap{}
tmpActMap.ID = actMap[vendorID].MapID
if err = handler.SyncAct(ctx, nil, actMap[vendorID], nil, actStoreSkuMap[vendorID]); err == nil {
retVal = []int{1}
} else {
tmpActMap.Remark = err.Error()
}
// 保存最后一次同步错误信息
dao.UpdateEntity(db, tmpActMap, "Remark")
}
return retVal, err
}, vendorIDs)