+ QueryPromotionSku

This commit is contained in:
gazebo
2019-08-08 22:03:28 +08:00
parent 6840508339
commit c81c9110bb
4 changed files with 83 additions and 46 deletions

View File

@@ -267,12 +267,12 @@ func (a *API) AccessAPINoPage2(apiStr string, jdParams map[string]interface{}, k
func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, resultParser func(data map[string]interface{}) (interface{}, error)) (interface{}, error) { func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, resultParser func(data map[string]interface{}) (interface{}, error)) (interface{}, error) {
return a.AccessAPINoPage2(apiStr, jdParams, keyToRemove, keyToKeep, resultParser, "") return a.AccessAPINoPage2(apiStr, jdParams, keyToRemove, keyToKeep, resultParser, "")
} }
func genNormalHavePageResultParser(dataKey string) (handler PageResultParser) {
func normalHavePageResultParser(data map[string]interface{}, totalCount int) ([]interface{}, int, error) { return func(data map[string]interface{}, totalCount int) ([]interface{}, int, error) {
var result map[string]interface{} var result map[string]interface{}
var retVal []interface{} var retVal []interface{}
tempResult := data["result"] tempResult := data[dataKey]
if resultStr, ok := tempResult.(string); ok { if resultStr, ok := tempResult.(string); ok {
if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil { if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil {
return nil, 0, platformapi.ErrResponseDataFormatWrong return nil, 0, platformapi.ErrResponseDataFormatWrong
@@ -315,11 +315,12 @@ func normalHavePageResultParser(data map[string]interface{}, totalCount int) ([]
} }
baseapi.SugarLogger.Errorf("can not find result key, data:%v", result) baseapi.SugarLogger.Errorf("can not find result key, data:%v", result)
return nil, 0, platformapi.ErrResponseDataFormatWrong return nil, 0, platformapi.ErrResponseDataFormatWrong
}
} }
func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, pageResultParser PageResultParser) ([]interface{}, int, error) { func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, pageResultParser PageResultParser) ([]interface{}, int, error) {
if pageResultParser == nil { if pageResultParser == nil {
pageResultParser = normalHavePageResultParser pageResultParser = genNormalHavePageResultParser("result")
} }
localJdParams := make(map[string]interface{}) localJdParams := make(map[string]interface{})

View File

@@ -106,3 +106,18 @@ func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *Promotio
} }
return promotionInfo, err return promotionInfo, err
} }
// 根据到家商品ID查询单品级优惠活动列表接口
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=196&apiid=d73baba02c484109a3c3c1b1236ca13d
func (a *API) QueryPromotionSku(promotionType int, skuID int64, promotionState int /*, pageNo int64, pageSize int*/) (skuResultList []*PromotionLspQuerySkuResult, err error) {
jdParams := map[string]interface{}{
"promotionType": promotionType,
"skuId": skuID,
"promotionState": promotionState,
}
result, _, err := a.AccessAPIHavePage("singlePromote/queryPromotionSku", jdParams, nil, nil, genNormalHavePageResultParser("data"))
if err != nil {
err = utils.Map2StructByJson(result, &skuResultList, false)
}
return skuResultList, err
}

View File

@@ -21,3 +21,24 @@ func TestQueryPromotionInfo(t *testing.T) {
} }
t.Log(utils.Format4Output(result, false)) t.Log(utils.Format4Output(result, false))
} }
func TestQueryPromotionSku(t *testing.T) {
skuIDs := []int64{
2023335105,
// 2023335104,
// 2023335088,
// 2023335057,
// 2023335098,
// 2023335020,
}
for _, skuID := range skuIDs {
list, err := api.QueryPromotionSku(PromotionTypeDirectDown, skuID, PromotionStateConfirmed)
t.Log(utils.Format4Output(list, false))
if err != nil {
t.Fatal(err)
}
// for _, v := range list {
// CancelPromotionSkuSingle()
// }
}
}

View File

@@ -42,19 +42,19 @@ func TestRetrieveToken(t *testing.T) {
func TestAddPrinter(t *testing.T) { func TestAddPrinter(t *testing.T) {
// err := api.AddPrinter("4004600675", "fem2ukwvduik", "公司测试打印机1") // err := api.AddPrinter("4004600675", "fem2ukwvduik", "公司测试打印机1")
// 4004617180 公司测试打印机2 // 4004617180, 381870509796 公司测试打印机2
err := api.AddPrinter("4004600675", "fem2ukwvduik", "测试打印机1") err := api.AddPrinter("4004615546", "7nxsw668yqtk", "测试打印机1")
handleError(t, err) handleError(t, err)
} }
func TestDeletePrinter(t *testing.T) { func TestDeletePrinter(t *testing.T) {
err := api.DeletePrinter("4004611945") err := api.DeletePrinter("4004615546")
handleError(t, err) handleError(t, err)
} }
func TestPrintMsg(t *testing.T) { func TestPrintMsg(t *testing.T) {
// 4004606481 // 4004606481
err := api.PrintMsg("4004600675", utils.GetUUID(), "<FS2>饿百取货码</FS2>") err := api.PrintMsg("4004615546", utils.GetUUID(), "<FS2>饿百取货码</FS2>")
handleError(t, err) handleError(t, err)
} }
@@ -65,7 +65,7 @@ func TestPrintMsgWithToken(t *testing.T) {
} }
func TestGetPrintStatus(t *testing.T) { func TestGetPrintStatus(t *testing.T) {
state, err := api.GetPrintStatus("4004617180") state, err := api.GetPrintStatus("4004615546")
handleError(t, err) handleError(t, err)
baseapi.SugarLogger.Debug(state) baseapi.SugarLogger.Debug(state)
} }