- checkActValidation
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -68,6 +68,8 @@ type ActMap struct {
|
||||
|
||||
VendorActID string `orm:"column(vendor_act_id);size(48)" json:"vendorActID"`
|
||||
SyncStatus int `orm:"default(2)" json:"syncStatus"`
|
||||
|
||||
Remark string `orm:"size(1024)" json:"remark"`
|
||||
}
|
||||
|
||||
func (*ActMap) TableUnique() [][]string {
|
||||
|
||||
@@ -18,14 +18,14 @@ type ActController struct {
|
||||
// @Description 创建活动
|
||||
// @Param token header string true "认证token"
|
||||
// @Param name formData string true "活动名,必须唯一(所以名子上最好带上日期)"
|
||||
// @Param type formData int true "活动类型,3:直降,4:限时抢购"
|
||||
// @Param type formData int true "活动类型,3:直降,4:秒杀"
|
||||
// @Param vendorIDs formData string true "厂商ID,当前只支持,京东:0,京西(用于记录活动信息):99"
|
||||
// @Param beginAt formData string true "开始日期"
|
||||
// @Param endAt formData string true "结束日期"
|
||||
// @Param pricePercentage formData int true "活动价格比例"
|
||||
// @Param advertising formData string true "广告语"
|
||||
// @Param actStoreSkuList formData string true "活动门店商品信息"
|
||||
// @Param limitDaily formData int false "是否按日0-不限,>0限购单数(限时抢需填)"
|
||||
// @Param limitDaily formData int false "是否按日0-不限,>0限购单数(秒杀需填)"
|
||||
// @Param limitUser formData int false "是否用户限购0-不限,1-限购"
|
||||
// @Param limitCount formData int false "限购件数 0-不限,如账号限购、设备限购有一个为1,则限购件数必须大于0的整数"
|
||||
// @Param remark formData string false "备注"
|
||||
@@ -74,7 +74,7 @@ func (c *ActController) CreateAct() {
|
||||
// @Param cityCode query int false "活动门店所属城市code"
|
||||
// @Param beginAt query string false "开始日期,包括"
|
||||
// @Param endAt query string false "结束日期,包括"
|
||||
// @Param typeList query string false "活动类型列表,3:直降,4:限时抢购"
|
||||
// @Param typeList query string false "活动类型列表,3:直降,4:秒杀"
|
||||
// @Param statusList query string false "活动状态列表"
|
||||
// @Param storeID query int false "包含门店"
|
||||
// @Param skuID query int false "包含sku"
|
||||
|
||||
Reference in New Issue
Block a user