|
|
|
|
@@ -65,12 +65,12 @@ func jdSkuActStatus2Jx(jdActState int) int {
|
|
|
|
|
return jdSkuActStatusMap[jdActState]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreatePromotionInfos(promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
|
|
|
|
func CreatePromotionInfos(vendorOrgCode string, promotionType int, name string, beginDate, endDate time.Time, outInfoId, advertising, traceId string) (infoId int64, err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
infoId, err = getAPI("").CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
|
|
|
|
infoId, err = getAPI(vendorOrgCode).CreatePromotionInfosSingle(name, beginDate, endDate, outInfoId, advertising, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
infoId, err = getAPI("").CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
|
|
|
|
infoId, err = getAPI(vendorOrgCode).CreatePromotionInfosLimitTime(name, beginDate, endDate, outInfoId, advertising, traceId)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
infoId = jxutils.GenFakeID()
|
|
|
|
|
@@ -81,26 +81,26 @@ func CreatePromotionInfos(promotionType int, name string, beginDate, endDate tim
|
|
|
|
|
return infoId, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreatePromotionRules(promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
|
|
|
|
func CreatePromotionRules(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int, traceId string) (err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
err = getAPI("").CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
|
|
|
|
err = getAPI(vendorOrgCode).CreatePromotionRulesSingle(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
err = getAPI("").CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
|
|
|
|
err = getAPI(vendorOrgCode).CreatePromotionRulesLimitTime(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily, traceId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreatePromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
|
|
|
|
func CreatePromotionSku(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
for _, batchSkus := range splitPromotionSku(skus, jdapi.MaxPromotionSkuCount) {
|
|
|
|
|
var tmpSkusResult []*jdapi.PromotionSku
|
|
|
|
|
var tmpErr error
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
tmpSkusResult, tmpErr = getAPI("").CreatePromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
tmpSkusResult, tmpErr = getAPI(vendorOrgCode).CreatePromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
tmpSkusResult, tmpErr = getAPI("").CreatePromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
tmpSkusResult, tmpErr = getAPI(vendorOrgCode).CreatePromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
}
|
|
|
|
|
if err = tmpErr; err != nil {
|
|
|
|
|
break
|
|
|
|
|
@@ -111,14 +111,14 @@ func CreatePromotionSku(promotionType int, infoId int64, outInfoId string, skus
|
|
|
|
|
return skusResult, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CancelPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (err error) {
|
|
|
|
|
func CancelPromotionSku(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
for _, batchSkus := range splitPromotionSku(skus, jdapi.MaxPromotionSkuCount) {
|
|
|
|
|
var tmpErr error
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
tmpErr = getAPI("").CancelPromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
tmpErr = getAPI(vendorOrgCode).CancelPromotionSkuSingle(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
tmpErr = getAPI("").CancelPromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
tmpErr = getAPI(vendorOrgCode).CancelPromotionSkuLimitTime(infoId, outInfoId, batchSkus, traceId)
|
|
|
|
|
}
|
|
|
|
|
if err = tmpErr; err != nil {
|
|
|
|
|
break
|
|
|
|
|
@@ -128,45 +128,45 @@ func CancelPromotionSku(promotionType int, infoId int64, outInfoId string, skus
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ConfirmPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
|
|
|
|
func ConfirmPromotion(vendorOrgCode string, promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
return getAPI("").ConfirmPromotionSingle(infoId, outInfoId, traceId)
|
|
|
|
|
return getAPI(vendorOrgCode).ConfirmPromotionSingle(infoId, outInfoId, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
return getAPI("").ConfirmPromotionLimitTime(infoId, outInfoId, traceId)
|
|
|
|
|
return getAPI(vendorOrgCode).ConfirmPromotionLimitTime(infoId, outInfoId, traceId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CancelPromotion(promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
|
|
|
|
func CancelPromotion(vendorOrgCode string, promotionType int, infoId int64, outInfoId, traceId string) (err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
err = getAPI("").CancelPromotionSingle(infoId, outInfoId, traceId)
|
|
|
|
|
err = getAPI(vendorOrgCode).CancelPromotionSingle(infoId, outInfoId, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
err = getAPI("").CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
|
|
|
|
err = getAPI(vendorOrgCode).CancelPromotionLimitTime(infoId, outInfoId, traceId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AdjustPromotionTime(promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
|
|
|
|
func AdjustPromotionTime(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, endDate time.Time, traceId string) (err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
err = getAPI("").AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
|
|
|
|
err = getAPI(vendorOrgCode).AdjustPromotionTimeSingle(infoId, outInfoId, endDate, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
err = getAPI("").AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
|
|
|
|
err = getAPI(vendorOrgCode).AdjustPromotionTimeLimitTime(infoId, outInfoId, endDate, traceId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func AdjustPromotionSku(promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
|
|
|
|
func AdjustPromotionSku(vendorOrgCode string, promotionType int, infoId int64, outInfoId string, skus []*jdapi.PromotionSku, traceId string) (skusResult []*jdapi.PromotionSku, err error) {
|
|
|
|
|
if globals.EnableJdStoreWrite {
|
|
|
|
|
if promotionType == model.ActSkuDirectDown {
|
|
|
|
|
skusResult, err = getAPI("").AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
|
|
|
|
skusResult, err = getAPI(vendorOrgCode).AdjustPromotionSkuSingle(infoId, outInfoId, skus, traceId)
|
|
|
|
|
} else {
|
|
|
|
|
skusResult, err = getAPI("").AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
|
|
|
|
skusResult, err = getAPI(vendorOrgCode).AdjustPromotionSkuLimitTime(infoId, outInfoId, skus, traceId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return skusResult, err
|
|
|
|
|
@@ -194,12 +194,12 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
|
|
|
|
if act.VendorActID == "" {
|
|
|
|
|
outInfoID = utils.Int2Str(act.ID)
|
|
|
|
|
}
|
|
|
|
|
infoID, err2 := CreatePromotionInfos(act.Type, act.GetRealActName(), act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceInfo)
|
|
|
|
|
infoID, err2 := CreatePromotionInfos(act.VendorOrgCode, act.Type, act.GetRealActName(), act.BeginAt, act.EndAt, outInfoID, act.Advertising, traceInfo)
|
|
|
|
|
if err = err2; err == nil {
|
|
|
|
|
vendorActID = utils.Int64ToStr(infoID)
|
|
|
|
|
if err = CreatePromotionRules(act.Type, infoID, "", act.LimitUser, act.LimitUser, act.LimitCount, 1, traceInfo); err == nil {
|
|
|
|
|
if _, err = CreatePromotionSku(act.Type, infoID, utils.Int2Str(act.ID), storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
|
|
|
|
if err = ConfirmPromotion(act.Type, infoID, "", traceInfo); err == nil {
|
|
|
|
|
if err = CreatePromotionRules(act.VendorOrgCode, act.Type, infoID, "", act.LimitUser, act.LimitUser, act.LimitCount, 1, traceInfo); err == nil {
|
|
|
|
|
if _, err = CreatePromotionSku(act.VendorOrgCode, act.Type, infoID, utils.Int2Str(act.ID), storeSku2Jd(actStoreSku, model.IsSyncStatusNeedCreate), traceInfo); err == nil {
|
|
|
|
|
if err = ConfirmPromotion(act.VendorOrgCode, act.Type, infoID, "", traceInfo); err == nil {
|
|
|
|
|
for _, v := range actStoreSku {
|
|
|
|
|
v.VendorActID = vendorActID
|
|
|
|
|
}
|
|
|
|
|
@@ -207,24 +207,24 @@ func createSkuAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
CancelPromotion(act.Type, infoID, "", traceInfo)
|
|
|
|
|
CancelPromotion(act.VendorOrgCode, act.Type, infoID, "", traceInfo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return vendorActID, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func cancelSkuActSkus(ctx *jxcontext.Context, actType int, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
|
|
|
|
func cancelSkuActSkus(ctx *jxcontext.Context, vendorOrgCode string, actType int, vendorActID string, actStoreSku []*model.ActStoreSku2) (err error) {
|
|
|
|
|
if vendorActID != "" {
|
|
|
|
|
if skuList := storeSku2Jd(actStoreSku, model.IsSyncStatusNeedDelete); len(skuList) > 0 {
|
|
|
|
|
err = CancelPromotionSku(actType, utils.Str2Int64(vendorActID), "", skuList, ctx.GetTrackInfo())
|
|
|
|
|
err = CancelPromotionSku(vendorOrgCode, actType, utils.Str2Int64(vendorActID), "", skuList, ctx.GetTrackInfo())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func cancelSkuAct(ctx *jxcontext.Context, actType int, vendorActID string) (err error) {
|
|
|
|
|
func cancelSkuAct(ctx *jxcontext.Context, vendorOrgCode string, actType int, vendorActID string) (err error) {
|
|
|
|
|
if vendorActID != "" {
|
|
|
|
|
err = CancelPromotion(actType, utils.Str2Int64(vendorActID), "", ctx.GetTrackInfo())
|
|
|
|
|
err = CancelPromotion(vendorOrgCode, actType, utils.Str2Int64(vendorActID), "", ctx.GetTrackInfo())
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
@@ -256,7 +256,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
|
|
|
|
if model.IsSyncStatusDelete(act.SyncStatus) {
|
|
|
|
|
for vendorActID := range vendorActInfoMap {
|
|
|
|
|
if vendorActID != "" {
|
|
|
|
|
if err = cancelSkuAct(ctx, act.Type, vendorActID); err != nil {
|
|
|
|
|
if err = cancelSkuAct(ctx, act.VendorOrgCode, act.Type, vendorActID); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -287,9 +287,9 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa
|
|
|
|
|
if vendorActID != "" {
|
|
|
|
|
if len(vendorActInfoMap[vendorActID]) == len(deleteActInfoMap[vendorActID]) {
|
|
|
|
|
// todo 如果这个取消导致了整活动被取消的话,怎么设置京西活动的状态
|
|
|
|
|
err = cancelSkuAct(ctx, act.Type, vendorActID)
|
|
|
|
|
err = cancelSkuAct(ctx, act.VendorOrgCode, act.Type, vendorActID)
|
|
|
|
|
} else {
|
|
|
|
|
err = cancelSkuActSkus(ctx, act.Type, vendorActID, deleteActInfoMap[vendorActID])
|
|
|
|
|
err = cancelSkuActSkus(ctx, act.VendorOrgCode, act.Type, vendorActID, deleteActInfoMap[vendorActID])
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
@@ -325,7 +325,7 @@ func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.C
|
|
|
|
|
if _, ok := actMap.Load(intPromotionID); !ok {
|
|
|
|
|
utils.CallFuncAsync(func() {
|
|
|
|
|
if !partner.CurActManager.IsVendorActExist(jxcontext.AdminCtx, promotionID, model.VendorIDJD) {
|
|
|
|
|
act, actStoreSkuList, err := getActFromJD(promotionID)
|
|
|
|
|
act, actStoreSkuList, err := getActFromJD(appKey2OrgCode(msg.AppKey), promotionID)
|
|
|
|
|
if err == nil && len(actStoreSkuList) > 0 {
|
|
|
|
|
_, err = partner.CurActManager.CreateActFromVendor(jxcontext.AdminCtx, act, actStoreSkuList)
|
|
|
|
|
}
|
|
|
|
|
@@ -341,8 +341,8 @@ func (c *PurchaseHandler) onActMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi.C
|
|
|
|
|
return retVal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getActFromJD(promotionID string) (act *model.Act2, actStoreSkuList []*model.ActStoreSku2, err error) {
|
|
|
|
|
result, err := getAPI("").QueryPromotionInfo(utils.Str2Int64(promotionID))
|
|
|
|
|
func getActFromJD(vendorOrgCode, promotionID string) (act *model.Act2, actStoreSkuList []*model.ActStoreSku2, err error) {
|
|
|
|
|
result, err := getAPI(vendorOrgCode).QueryPromotionInfo(utils.Str2Int64(promotionID))
|
|
|
|
|
if err == nil && len(result.SkuResultList) > 0 {
|
|
|
|
|
act = &model.Act2{
|
|
|
|
|
Act: model.Act{
|
|
|
|
|
@@ -357,8 +357,9 @@ func getActFromJD(promotionID string) (act *model.Act2, actStoreSkuList []*model
|
|
|
|
|
LimitDaily: result.SkuResultList[0].LimitDaily,
|
|
|
|
|
LimitCount: 1,
|
|
|
|
|
},
|
|
|
|
|
VendorID: model.VendorIDJD,
|
|
|
|
|
VendorActID: promotionID,
|
|
|
|
|
VendorID: model.VendorIDJD,
|
|
|
|
|
VendorOrgCode: vendorOrgCode,
|
|
|
|
|
VendorActID: promotionID,
|
|
|
|
|
}
|
|
|
|
|
if utils.IsTimeZero(act.BeginAt) {
|
|
|
|
|
act.BeginAt = result.BeginTime.GoTime()
|
|
|
|
|
|