+ 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,59 +267,60 @@ 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) {
return a.AccessAPINoPage2(apiStr, jdParams, keyToRemove, keyToKeep, resultParser, "")
}
func genNormalHavePageResultParser(dataKey string) (handler PageResultParser) {
return func(data map[string]interface{}, totalCount int) ([]interface{}, int, error) {
var result map[string]interface{}
var retVal []interface{}
func normalHavePageResultParser(data map[string]interface{}, totalCount int) ([]interface{}, int, error) {
var result map[string]interface{}
var retVal []interface{}
tempResult := data["result"]
if resultStr, ok := tempResult.(string); ok {
if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil {
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
}
result = tempResult.(map[string]interface{})
if totalCount == 0 {
for _, totalCountKey := range havePageTotalCountKeys {
if totalCount2, ok := result[totalCountKey]; ok {
totalCountInt64, _ := totalCount2.(json.Number).Int64()
totalCount = int(totalCountInt64)
if totalCount == 0 {
return make([]interface{}, 0), 0, nil
}
break
tempResult := data[dataKey]
if resultStr, ok := tempResult.(string); ok {
if err := utils.UnmarshalUseNumber([]byte(resultStr), &tempResult); err != nil {
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
}
result = tempResult.(map[string]interface{})
if totalCount == 0 {
baseapi.SugarLogger.Errorf("can not find totalCount key, data:%v", result)
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
}
for _, inner2ResultKey := range havePageInner2DataKeys {
if inner2Result, ok := result[inner2ResultKey]; ok {
if inner2Result == nil {
retVal = nil
} else if inner2ResultStr, ok := inner2Result.(string); ok {
err := utils.UnmarshalUseNumber([]byte(inner2ResultStr), &retVal)
if err != nil {
return nil, 0, platformapi.ErrResponseDataFormatWrong
for _, totalCountKey := range havePageTotalCountKeys {
if totalCount2, ok := result[totalCountKey]; ok {
totalCountInt64, _ := totalCount2.(json.Number).Int64()
totalCount = int(totalCountInt64)
if totalCount == 0 {
return make([]interface{}, 0), 0, nil
}
break
}
} else {
retVal = inner2Result.([]interface{})
}
return retVal, totalCount, nil
if totalCount == 0 {
baseapi.SugarLogger.Errorf("can not find totalCount key, data:%v", result)
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
}
for _, inner2ResultKey := range havePageInner2DataKeys {
if inner2Result, ok := result[inner2ResultKey]; ok {
if inner2Result == nil {
retVal = nil
} else if inner2ResultStr, ok := inner2Result.(string); ok {
err := utils.UnmarshalUseNumber([]byte(inner2ResultStr), &retVal)
if err != nil {
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
} else {
retVal = inner2Result.([]interface{})
}
return retVal, totalCount, nil
}
}
baseapi.SugarLogger.Errorf("can not find result key, data:%v", result)
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
baseapi.SugarLogger.Errorf("can not find result key, data:%v", result)
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
func (a *API) AccessAPIHavePage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, pageResultParser PageResultParser) ([]interface{}, int, error) {
if pageResultParser == nil {
pageResultParser = normalHavePageResultParser
pageResultParser = genNormalHavePageResultParser("result")
}
localJdParams := make(map[string]interface{})

View File

@@ -106,3 +106,18 @@ func (a *API) QueryPromotionInfo(promotionInfoId int64) (promotionInfo *Promotio
}
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))
}
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) {
// err := api.AddPrinter("4004600675", "fem2ukwvduik", "公司测试打印机1")
// 4004617180 公司测试打印机2
err := api.AddPrinter("4004600675", "fem2ukwvduik", "测试打印机1")
// 4004617180, 381870509796 公司测试打印机2
err := api.AddPrinter("4004615546", "7nxsw668yqtk", "测试打印机1")
handleError(t, err)
}
func TestDeletePrinter(t *testing.T) {
err := api.DeletePrinter("4004611945")
err := api.DeletePrinter("4004615546")
handleError(t, err)
}
func TestPrintMsg(t *testing.T) {
// 4004606481
err := api.PrintMsg("4004600675", utils.GetUUID(), "<FS2>饿百取货码</FS2>")
err := api.PrintMsg("4004615546", utils.GetUUID(), "<FS2>饿百取货码</FS2>")
handleError(t, err)
}
@@ -65,7 +65,7 @@ func TestPrintMsgWithToken(t *testing.T) {
}
func TestGetPrintStatus(t *testing.T) {
state, err := api.GetPrintStatus("4004617180")
state, err := api.GetPrintStatus("4004615546")
handleError(t, err)
baseapi.SugarLogger.Debug(state)
}