- 标准化jdapi.QuerySkuInfos和QueryListBySkuIds
This commit is contained in:
@@ -68,9 +68,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SkuFixedStatusOnline = 1
|
SkuFixedStatusOnline = 1 // 上架
|
||||||
SkuFixedStatusOffline = 2
|
SkuFixedStatusOffline = 2 // 下架
|
||||||
SkuFixedStatusDeleted = 4
|
SkuFixedStatusDeleted = 4 // 删除
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -79,6 +79,10 @@ const (
|
|||||||
CreateSpuResultFailed = 3
|
CreateSpuResultFailed = 3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
IsFilterDelTrue = "0" // 0代表不查已删除商品
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MaxSkuNameCharCount = 45 // skuname最长字符数
|
MaxSkuNameCharCount = 45 // skuname最长字符数
|
||||||
SaleAttrIDBase = 1001
|
SaleAttrIDBase = 1001
|
||||||
@@ -131,13 +135,57 @@ type CreateByUpcPair struct {
|
|||||||
SkuId int64
|
SkuId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type QuerySkuParam struct {
|
||||||
|
SkuName string `json:"skuName,omitempty"`
|
||||||
|
UpcCode string `json:"upcCode,omitempty"`
|
||||||
|
SkuID int64 `json:"skuId,omitempty"`
|
||||||
|
IsFilterDel string `json:"isFilterDel,omitempty"` // 是否查询出已删除的上传商品(0代表不查已删除商品,不填则查出全部商品)
|
||||||
|
PageNo int `json:"pageNo,omitempty"`
|
||||||
|
PageSize int `json:"pageSize,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SkuMain struct {
|
||||||
|
SuperID int64 `json:"superId"`
|
||||||
|
SkuID int64 `json:"skuId"`
|
||||||
|
OutSkuID string `json:"outSkuId"`
|
||||||
|
CategoryID int64 `json:"categoryId"`
|
||||||
|
BrandID int64 `json:"brandId"`
|
||||||
|
ShopCategories []int64 `json:"shopCategories"`
|
||||||
|
SkuName string `json:"skuName"`
|
||||||
|
FixedStatus int `json:"fixedStatus"` // 商家商品上下架状态(1:上架;2:下架;4:删除;)
|
||||||
|
FixedUpTime string `json:"fixedUpTime"`
|
||||||
|
OrgCode int `json:"orgCode"`
|
||||||
|
SellCities []int64 `json:"sellCities"`
|
||||||
|
SkuPrice int `json:"skuPrice"`
|
||||||
|
Weight float64 `json:"weight"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryListBySkuIdsParam struct {
|
||||||
|
SkuIDs []int64 `json:"skuIds"`
|
||||||
|
ImgType int `json:"imgType,omitempty"`
|
||||||
|
HandleStatus []int `json:"handleStatus,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImgHandleQueryResult struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
SkuID int64 `json:"skuId"`
|
||||||
|
IsMain int `json:"isMain"`
|
||||||
|
ImgType int `json:"imgType"`
|
||||||
|
SourceImgURL string `json:"sourceImgUrl"`
|
||||||
|
SkuImgSort int `json:"skuImgSort"`
|
||||||
|
HandleStatus int `json:"handleStatus"`
|
||||||
|
HandleStatusStr string `json:"handleStatusStr"`
|
||||||
|
HandleRemark string `json:"handleRemark"`
|
||||||
|
HandleErrLog string `json:"handleErrLog"`
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
skuExistReg = regexp.MustCompile(`商家skuId已存在:(\d+)`)
|
skuExistReg = regexp.MustCompile(`商家skuId已存在:(\d+)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// 分页查询商品品牌信息接口
|
// 分页查询商品品牌信息接口
|
||||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=1ca07a3e767649a7a44fc6ea7e9ed8dd
|
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=1ca07a3e767649a7a44fc6ea7e9ed8dd
|
||||||
func (a *API) QueryPageBrandInfo(pageNo, pageSize, brandId int, brandName string) (brandList []*BrandInfo, totalCount int, err error) {
|
func (a *API) QueryPageBrandInfo(pageNo, pageSize int, brandId int64, brandName string) (brandList []*BrandInfo, totalCount int, err error) {
|
||||||
if pageNo <= 0 {
|
if pageNo <= 0 {
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
}
|
}
|
||||||
@@ -320,44 +368,28 @@ func (a *API) BatchUpdateOutSkuId(skuInfoList []*SkuIDPair) (retVal interface{},
|
|||||||
// 查询商家已上传商品信息列表接口
|
// 查询商家已上传商品信息列表接口
|
||||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=e433b95f74524dab91718432c0358977
|
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=e433b95f74524dab91718432c0358977
|
||||||
// pageNo 从1开始
|
// pageNo 从1开始
|
||||||
func (a *API) QuerySkuInfos(skuName string, skuId int64, pageNo, pageSize int, isFilterDel bool) (retVal []map[string]interface{}, totalCount int, err error) {
|
func (a *API) QuerySkuInfos(queryParam *QuerySkuParam) (skuList []*SkuMain, totalCount int, err error) {
|
||||||
if pageNo <= 0 {
|
if queryParam.PageNo <= 0 {
|
||||||
pageNo = 1
|
queryParam.PageNo = 1
|
||||||
}
|
}
|
||||||
if pageSize == 0 {
|
if queryParam.PageSize == 0 {
|
||||||
pageSize = 50
|
queryParam.PageSize = 50
|
||||||
}
|
}
|
||||||
params := map[string]interface{}{
|
result, totalCount, err := a.AccessAPIHavePage("pms/querySkuInfos", utils.Struct2MapByJson(queryParam), nil, nil, nil)
|
||||||
KeyPageNo: pageNo, // pageNo好像必须要有值,否则一直不返回
|
|
||||||
KeyPageSize: pageSize,
|
|
||||||
}
|
|
||||||
if skuName != "" {
|
|
||||||
params[KeySkuName] = skuName
|
|
||||||
}
|
|
||||||
if skuId != 0 {
|
|
||||||
params[KeySkuId] = skuId
|
|
||||||
}
|
|
||||||
if isFilterDel {
|
|
||||||
params[KeyIsFilterDel] = "1"
|
|
||||||
} else {
|
|
||||||
params[KeyIsFilterDel] = "0"
|
|
||||||
}
|
|
||||||
result, totalCount, err := a.AccessAPIHavePage("pms/querySkuInfos", params, nil, nil, nil)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return utils.Slice2MapSlice(result), totalCount, nil
|
err = utils.Map2StructByJson(result, &skuList, false)
|
||||||
}
|
}
|
||||||
return nil, 0, err
|
return skuList, totalCount, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询商品图片处理结果接口
|
// 查询商品图片处理结果接口
|
||||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=17506653e03542f9a49023711780c30d
|
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=17506653e03542f9a49023711780c30d
|
||||||
func (a *API) QueryListBySkuIds(skuIds []int64, addParams map[string]interface{}) (retVal []map[string]interface{}, err error) {
|
func (a *API) QueryListBySkuIds(queryParam *QueryListBySkuIdsParam) (imgList []*ImgHandleQueryResult, err error) {
|
||||||
result, err := a.AccessAPINoPage("order/queryListBySkuIds", utils.MergeMaps(addParams, utils.Params2Map("skuIds", skuIds)), nil, nil, nil)
|
result, err := a.AccessAPINoPage("order/queryListBySkuIds", utils.Struct2MapByJson(queryParam), nil, nil, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
err = utils.Map2StructByJson(result, &imgList, false)
|
||||||
}
|
}
|
||||||
return nil, err
|
return imgList, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分页查询京东到家商品前缀库接口
|
// 分页查询京东到家商品前缀库接口
|
||||||
|
|||||||
@@ -58,7 +58,11 @@ func TestBatchUpdateOutSkuId(t *testing.T) {
|
|||||||
|
|
||||||
func TestQuerySkuInfos(t *testing.T) {
|
func TestQuerySkuInfos(t *testing.T) {
|
||||||
pageSize := 20
|
pageSize := 20
|
||||||
result, totalCount, err := api.QuerySkuInfos("一个高级商品", 0, 0, pageSize, true)
|
result, totalCount, err := api.QuerySkuInfos(&QuerySkuParam{
|
||||||
|
IsFilterDel: IsFilterDelTrue,
|
||||||
|
})
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
|
t.Log(totalCount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -73,7 +77,10 @@ func TestQueryListBySkuIds(t *testing.T) {
|
|||||||
2018806493,
|
2018806493,
|
||||||
2018805873,
|
2018805873,
|
||||||
}
|
}
|
||||||
result, err := api.QueryListBySkuIds(ids, nil)
|
result, err := api.QueryListBySkuIds(&QueryListBySkuIdsParam{
|
||||||
|
SkuIDs: ids,
|
||||||
|
})
|
||||||
|
t.Log(utils.Format4Output(result, false))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user