+ QueryPromotionSku
This commit is contained in:
@@ -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{})
|
||||
|
||||
Reference in New Issue
Block a user