- 京东活动API重构

This commit is contained in:
gazebo
2019-05-14 18:30:24 +08:00
parent 3f7146ce62
commit 638142ef58

View File

@@ -131,7 +131,7 @@ var (
type JdPromotionHandler interface { type JdPromotionHandler interface {
CreatePromotionInfos(name string, beginDate, endDate time.Time, outInfoId, advertising string) (infoId int64, err error) CreatePromotionInfos(name string, beginDate, endDate time.Time, outInfoId, advertising string) (infoId int64, err error)
CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error)
CreatePromotionSku(infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) CreatePromotionSku(infoId int64, outInfoId string, skus []*jdapi.PromotionSku) (skusResult []*jdapi.PromotionSku, err error)
ConfirmPromotion(infoId int64, outInfoId string) (err error) ConfirmPromotion(infoId int64, outInfoId string) (err error)
CancelPromotion(infoId int64, outInfoId string) (err error) CancelPromotion(infoId int64, outInfoId string) (err error)
} }
@@ -145,7 +145,7 @@ func (p *JdDirectDownHandler) CreatePromotionInfos(name string, beginDate, endDa
func (p *JdDirectDownHandler) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) { func (p *JdDirectDownHandler) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) {
return api.JdAPI.CreatePromotionRules(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily) return api.JdAPI.CreatePromotionRules(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily)
} }
func (p *JdDirectDownHandler) CreatePromotionSku(infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) { func (p *JdDirectDownHandler) CreatePromotionSku(infoId int64, outInfoId string, skus []*jdapi.PromotionSku) (skusResult []*jdapi.PromotionSku, err error) {
return api.JdAPI.CreatePromotionSkuSingle(infoId, outInfoId, skus) return api.JdAPI.CreatePromotionSkuSingle(infoId, outInfoId, skus)
} }
func (p *JdDirectDownHandler) ConfirmPromotion(infoId int64, outInfoId string) (err error) { func (p *JdDirectDownHandler) ConfirmPromotion(infoId int64, outInfoId string) (err error) {
@@ -164,7 +164,7 @@ func (p *JdLimitedTimeHandler) CreatePromotionInfos(name string, beginDate, endD
func (p *JdLimitedTimeHandler) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) { func (p *JdLimitedTimeHandler) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) {
return api.JdAPI.CreatePromotionRules(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily) return api.JdAPI.CreatePromotionRules(infoId, outInfoId, limitDevice, limitPin, limitCount, limitDaily)
} }
func (p *JdLimitedTimeHandler) CreatePromotionSku(infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) { func (p *JdLimitedTimeHandler) CreatePromotionSku(infoId int64, outInfoId string, skus []*jdapi.PromotionSku) (skusResult []*jdapi.PromotionSku, err error) {
return api.JdAPI.CreatePromotionSkuLimitTime(infoId, outInfoId, skus) return api.JdAPI.CreatePromotionSkuLimitTime(infoId, outInfoId, skus)
} }
func (p *JdLimitedTimeHandler) ConfirmPromotion(infoId int64, outInfoId string) (err error) { func (p *JdLimitedTimeHandler) ConfirmPromotion(infoId int64, outInfoId string) (err error) {
@@ -183,7 +183,7 @@ func (p *JdNullHandler) CreatePromotionInfos(name string, beginDate, endDate tim
func (p *JdNullHandler) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) { func (p *JdNullHandler) CreatePromotionRules(infoId int64, outInfoId string, limitDevice, limitPin, limitCount, limitDaily int) (err error) {
return nil return nil
} }
func (p *JdNullHandler) CreatePromotionSku(infoId int64, outInfoId string, skus []map[string]interface{}) (skusResult []map[string]interface{}, err error) { func (p *JdNullHandler) CreatePromotionSku(infoId int64, outInfoId string, skus []*jdapi.PromotionSku) (skusResult []*jdapi.PromotionSku, err error) {
return nil, nil return nil, nil
} }
func (p *JdNullHandler) ConfirmPromotion(infoId int64, outInfoId string) (err error) { func (p *JdNullHandler) ConfirmPromotion(infoId int64, outInfoId string) (err error) {
@@ -260,7 +260,7 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
userName := ctx.GetUserName() userName := ctx.GetUserName()
db := dao.GetDB() db := dao.GetDB()
modifyPricesList := make(map[int][]*jdapi.SkuPriceInfo) modifyPricesList := make(map[int][]*jdapi.SkuPriceInfo)
promotionPrices := make([]map[string]interface{}, len(params.StoreIDs)*len(params.SkuPrices)) promotionPrices := make([]*jdapi.PromotionSku, len(params.StoreIDs)*len(params.SkuPrices))
var jxStoreIDs []int var jxStoreIDs []int
promotion := &model.Promotion{ promotion := &model.Promotion{
Name: params.Name, Name: params.Name,
@@ -338,13 +338,11 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
}) })
} }
} }
promotionPrices[index] = map[string]interface{}{ promotionPrices[index] = &jdapi.PromotionSku{
jdapi.KeyStationNo: utils.Str2Int64(skuBind.VendorStoreID), StationNo: utils.Str2Int64(skuBind.VendorStoreID),
jdapi.KeySkuId: skuBind.JdSkuID, SkuID: skuBind.JdSkuID,
// jdapi.KeyOutStationNo: utils.Int2Str(skuBind.StoreID), PromotionPrice: int64(promotionSkuPrice.Price),
// jdapi.KeyOutSkuId: utils.Int2Str(skuBind.SkuID), LimitSkuCount: promotionSkuPrice.LimitSkuCount,
jdapi.KeyPromotionPrice: promotionSkuPrice.Price,
jdapi.KeyLimitSkuCount: promotionSkuPrice.LimitSkuCount,
} }
index++ index++
} }
@@ -451,9 +449,9 @@ func CreateJdPromotion(ctx *jxcontext.Context, isIDJd bool, isAsync, isContinueW
} else if step == 2 { } else if step == 2 {
task2 := tasksch.NewParallelTask("CreateJdPromotion CreatePromotionSku", tasksch.NewParallelConfig().SetBatchSize(MaxPromotionSkuCount).SetIsContinueWhenError(isContinueWhenError), ctx, task2 := tasksch.NewParallelTask("CreateJdPromotion CreatePromotionSku", tasksch.NewParallelConfig().SetBatchSize(MaxPromotionSkuCount).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params2 ...interface{}) (retVal interface{}, err error) { func(task *tasksch.ParallelTask, batchItemList []interface{}, params2 ...interface{}) (retVal interface{}, err error) {
skus := make([]map[string]interface{}, len(batchItemList)) skus := make([]*jdapi.PromotionSku, len(batchItemList))
for k, v := range batchItemList { for k, v := range batchItemList {
skus[k] = v.(map[string]interface{}) skus[k] = v.(*jdapi.PromotionSku)
} }
_, err = promotionHandler.CreatePromotionSku(infoId, "", skus) _, err = promotionHandler.CreatePromotionSku(infoId, "", skus)
return nil, err return nil, err
@@ -930,12 +928,12 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
if err = dao.GetEntity(db, promotion, "VendorPromotionID"); dao.IsNoRowsError(err) { if err = dao.GetEntity(db, promotion, "VendorPromotionID"); dao.IsNoRowsError(err) {
storeIDMap := make(map[int64]int) storeIDMap := make(map[int64]int)
skuIDMap := make(map[int64]int) skuIDMap := make(map[int64]int)
skuMap := make(map[int64]*jdapi.PromotionSkuResult) skuMap := make(map[int64]*jdapi.PromotionLspQuerySkuResult)
// 注意这样处理可能是有问题我们假定的是门店信息与SKU信息的叉乘 // 注意这样处理可能是有问题我们假定的是门店信息与SKU信息的叉乘
for _, v := range result.SkuResultList { for _, v := range result.SkuResultList {
storeIDMap[v.StationNo] = 1 storeIDMap[v.StationNo] = 1
skuIDMap[v.SkuId] = 1 skuIDMap[v.SkuID] = 1
skuMap[v.SkuId] = v skuMap[v.SkuID] = v
} }
jdStoreIDs := make([]string, len(storeIDMap)) jdStoreIDs := make([]string, len(storeIDMap))
index := 0 index := 0
@@ -970,7 +968,7 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
jxStoreIDs[k] = v.StoreID jxStoreIDs[k] = v.StoreID
} }
priceList := make([]*SkuPrice, len(skuList)) priceList := make([]*SkuPrice, len(skuList))
var skuResult *jdapi.PromotionSkuResult var skuResult *jdapi.PromotionLspQuerySkuResult
for k, v := range skuList { for k, v := range skuList {
skuResult = skuMap[v.JdID] skuResult = skuMap[v.JdID]
priceList[k] = &SkuPrice{ priceList[k] = &SkuPrice{
@@ -985,11 +983,11 @@ func createLocalPromotionFromRemote(promotionInfoId int64) (retVal *jdapi.Callba
// globals.SugarLogger.Debugf("priceList:%s", utils.Format4Output(priceList, false)) // globals.SugarLogger.Debugf("priceList:%s", utils.Format4Output(priceList, false))
source := strings.Trim(result.Source, "来源") source := strings.Trim(result.Source, "来源")
promotionParams := &PromotionParams{ promotionParams := &PromotionParams{
Name: source + "-" + utils.Int64ToStr(result.PromotionInfoId), Name: source + "-" + utils.Int64ToStr(result.PromotionInfoID),
Advertising: "", Advertising: "",
Type: result.PromotionType, Type: result.PromotionType,
BeginAt: result.BeginTime, BeginAt: result.BeginTime.GoTime(),
EndAt: result.EndTime, EndAt: result.EndTime.GoTime(),
StoreIDs: jxStoreIDs, StoreIDs: jxStoreIDs,
SkuPrices: priceList, SkuPrices: priceList,
} }