From 63f54f12053742aef9457fbaabc2799475addd71 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 8 Nov 2018 11:03:58 +0800 Subject: [PATCH] - QueryPromotionInfo --- platformapi/jdapi/callback.go | 1 + platformapi/jdapi/jdapi.go | 2 +- platformapi/jdapi/promotion.go | 64 +++++++++++++++++++++++++++++ platformapi/jdapi/promotion_test.go | 10 +++++ 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/platformapi/jdapi/callback.go b/platformapi/jdapi/callback.go index b0e5f724..80941339 100644 --- a/platformapi/jdapi/callback.go +++ b/platformapi/jdapi/callback.go @@ -18,6 +18,7 @@ type CallbackResponse struct { type CallbackOrderMsg struct { ID int `json:"-"` // 用于传递Jdorder的主键值,减少一次读库操作 BillID string `json:"billId"` + OutBillID string `json:"outBillId"` StatusID string `json:"statusId"` Timestamp string `json:"timestamp"` Remark string `json:"remark"` diff --git a/platformapi/jdapi/jdapi.go b/platformapi/jdapi/jdapi.go index 2a9ec26b..be686c3d 100644 --- a/platformapi/jdapi/jdapi.go +++ b/platformapi/jdapi/jdapi.go @@ -208,7 +208,7 @@ func genNoPageResultParser(codeKey, msgKey, resultKey, okCode string) func(data if innerData, ok := data[resultKey]; ok { return innerData, nil } - baseapi.SugarLogger.Warnf("genNoPageResultParser resultKey %s can not be found in result:%v", resultKey, data) + baseapi.SugarLogger.Warnf("genNoPageResultParser resultKey %s can not be found in result:%v", resultKey, utils.Format4Output(data, false)) return nil, nil // 容错 // panic(fmt.Sprintf("genNoPageResultParser resultKey %s can not be found in result:%v", resultKey, data)) } diff --git a/platformapi/jdapi/promotion.go b/platformapi/jdapi/promotion.go index e8af6e06..81afc888 100644 --- a/platformapi/jdapi/promotion.go +++ b/platformapi/jdapi/promotion.go @@ -22,6 +22,34 @@ const ( MaxPromotionSkuCount = 200 ) +const ( + PromotionStateNotConfirm = 1 + PromotionStateConfirmed = 5 + PromotionStateCanceled = 6 + PromotionStateEnded = 9 +) + +type PromotionSkuResult struct { + LimitDaily int + LimitDevice int + LimitPin int + PlatformRatio int + PromotionPrice int + SkuId int64 + StationNo int64 + StoreRatio int +} + +type PromotionInfo struct { + BeginTime time.Time + EndTime time.Time + PromotionInfoId int64 + PromotionState int + PromotionType int + Source string + SkuResultList []*PromotionSkuResult +} + // 单品直降添加主活动信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=178&apiid=ee8685c9be9b4aa5bdc41468c5ebc33b func (a *API) CreatePromotionInfosSingle(name string, beginDate, endDate time.Time, outInfoId, advertising string) (infoId int64, err error) { @@ -183,3 +211,39 @@ func (a *API) cancelPromotion(promotionType int, infoId int64, outInfoId string) _, err = a.AccessAPINoPage(cmd, jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "", "0")) return err } + +func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *PromotionInfo, err error) { + jdParams := map[string]interface{}{ + "promotionInfoId": promotionInfoId, + } + result, err := a.AccessAPINoPage("orderdiscount/queryPromotionInfo", jdParams, nil, nil, genNoPageResultParser("errorCode", "errorInfos", "data", "0")) + if err == nil { + data := result.(map[string]interface{}) + // baseapi.SugarLogger.Debug(utils.Format4Output(data, false)) + promotionInfo = &PromotionInfo{ + BeginTime: utils.Timestamp2Time(utils.MustInterface2Int64(data["beginTime"].(map[string]interface{})["time"]) / 1000), + EndTime: utils.Timestamp2Time(utils.MustInterface2Int64(data["endTime"].(map[string]interface{})["time"]) / 1000), + PromotionInfoId: utils.MustInterface2Int64(data["promotionInfoId"]), + PromotionState: int(utils.MustInterface2Int64(data["promotionState"])), + PromotionType: int(utils.MustInterface2Int64(data["promotionType"])), + Source: utils.Interface2String(data["source"]), + } + skuResultList := data["skuResultList"].([]interface{}) + promotionInfo.SkuResultList = make([]*PromotionSkuResult, len(skuResultList)) + for k, v := range skuResultList { + skuResult := v.(map[string]interface{}) + promotionInfo.SkuResultList[k] = &PromotionSkuResult{ + LimitDaily: int(utils.MustInterface2Int64(skuResult["limitDaily"])), + LimitDevice: int(utils.MustInterface2Int64(skuResult["limitDevice"])), + LimitPin: int(utils.MustInterface2Int64(skuResult["limitPin"])), + PlatformRatio: int(utils.MustInterface2Int64(skuResult["platformRatio"])), + PromotionPrice: int(utils.MustInterface2Int64(skuResult["promotionPrice"])), + SkuId: utils.MustInterface2Int64(skuResult["skuId"]), + StationNo: utils.MustInterface2Int64(skuResult["stationNo"]), + StoreRatio: int(utils.MustInterface2Int64(skuResult["storeRatio"])), + } + } + return promotionInfo, nil + } + return nil, err +} diff --git a/platformapi/jdapi/promotion_test.go b/platformapi/jdapi/promotion_test.go index c8a53a09..e478a54a 100644 --- a/platformapi/jdapi/promotion_test.go +++ b/platformapi/jdapi/promotion_test.go @@ -60,3 +60,13 @@ func TestCreatePromotionLimitTime(t *testing.T) { t.Fatal(err) } } + +func TestQueryPromotionInfo(t *testing.T) { + result, err := jdapi.QueryPromotionInfo(14885272) + if err != nil { + t.Fatal(err) + } + if len(result.SkuResultList) == 0 { + t.Fatal("should have SkuResultList") + } +}