京东商城依稀下列
This commit is contained in:
@@ -120,16 +120,22 @@ type CreateSkuParamAttrs struct {
|
||||
AttrValues []string `json:"attrValues"` //是 无 下沉到sku属性值 单选或者多选 通过接口jingdong.category.read.findValuesByAttrIdUnlimit获取 输入类型请手动输入
|
||||
}
|
||||
|
||||
type CreateSkuParam struct {
|
||||
Ware *CreateSkuParamWare `json:"ware"`
|
||||
Skus []*CreateSkuParamSkus `json:"skus"`
|
||||
}
|
||||
|
||||
type CreateSkuResult struct {
|
||||
WareID int `json:"wareId"`
|
||||
skus []struct {
|
||||
SkuID int `json:"skuId"`
|
||||
saleAttrs []struct {
|
||||
AttrValueAlias []string `json:"attrValueAlias"`
|
||||
AttrID string `json:"attrId"`
|
||||
AttrValues []string `json:"attrValues"`
|
||||
}
|
||||
}
|
||||
WareID int64 `json:"wareId"`
|
||||
Skus []struct {
|
||||
WareID int64 `json:"wareId"`
|
||||
SkuID int64 `json:"skuId"`
|
||||
SaleAttrs []struct {
|
||||
// AttrValueAlias []string `json:"attrValueAlias"`
|
||||
AttrID string `json:"attrId"`
|
||||
AttrValues []string `json:"attrValues"`
|
||||
} `json:"saleAttrs"`
|
||||
} `json:"skus"`
|
||||
}
|
||||
|
||||
type UpdateWareParam struct {
|
||||
@@ -176,11 +182,13 @@ func (a *API) FindVendorCategories() (findVendorCategoriesResult []*FindVendorCa
|
||||
//京东商城发布商品(创建商品)
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=48&apiId=1379&apiName=jingdong.ware.write.add
|
||||
func (a *API) CreateWare(createSkuParamWare *CreateSkuParamWare, createSkuParamSkus []*CreateSkuParamSkus) (createSkuResult *CreateSkuResult, err error) {
|
||||
wares, _ := json.Marshal(createSkuParamWare)
|
||||
skus, _ := json.Marshal(createSkuParamSkus)
|
||||
c := &CreateSkuParam{
|
||||
Ware: createSkuParamWare,
|
||||
Skus: createSkuParamSkus,
|
||||
}
|
||||
cc, _ := json.Marshal(c)
|
||||
result, err := a.AccessAPI2("jingdong.ware.write.add", prodURL, map[string]interface{}{
|
||||
"ware": string(wares),
|
||||
"skus": string(skus),
|
||||
"360buy_param_json": string(cc),
|
||||
})
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["jingdong_ware_write_add_responce"].(map[string]interface{})["ware"], &createSkuResult, false)
|
||||
@@ -249,34 +257,69 @@ func (a *API) DeleteWare(wareId int) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
type FindAttrsResult struct {
|
||||
ID int `json:"id"`
|
||||
OrderSort int `json:"orderSort"`
|
||||
InputType int `json:"inputType"`
|
||||
Name string `json:"name"`
|
||||
Features []struct {
|
||||
Fvalue string `json:"fvalue"`
|
||||
Key string `json:"key"`
|
||||
} `json:"features"`
|
||||
CatID int `json:"catId"`
|
||||
AttributeType int `json:"attributeType"`
|
||||
IsRequired bool `json:"isRequired"`
|
||||
}
|
||||
|
||||
//获取类目属性ID
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=2809&apiName=jingdong.category.read.findAttrsByCategoryIdUnlimitCate
|
||||
func (a *API) FindAttrs(cid int) (err error) {
|
||||
_, err = a.AccessAPI("jingdong.category.read.findAttrsByCategoryIdUnlimitCate", prodURL, map[string]interface{}{
|
||||
func (a *API) FindAttrs(cid int) (findAttrsResult []*FindAttrsResult, err error) {
|
||||
result, err := a.AccessAPI("jingdong.category.read.findAttrsByCategoryIdUnlimitCate", prodURL, map[string]interface{}{
|
||||
"cid": cid,
|
||||
// "attributeType": 4,
|
||||
})
|
||||
return err
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"].(map[string]interface{})["findattrsbycategoryidunlimitcate_result"], &findAttrsResult, false)
|
||||
}
|
||||
return findAttrsResult, err
|
||||
}
|
||||
|
||||
type FindValuesByAttrIdResult struct {
|
||||
ID int64 `json:"id"`
|
||||
OrderSort int `json:"orderSort"`
|
||||
Name string `json:"name"`
|
||||
CatID int `json:"catId"`
|
||||
AttID int `json:"attId"`
|
||||
}
|
||||
|
||||
//获取类目属性值
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=2821&apiName=jingdong.category.read.findValuesByAttrIdUnlimit
|
||||
func (a *API) FindValuesByAttrId(categoryAttrId int) (err error) {
|
||||
_, err = a.AccessAPI("jingdong.category.read.findValuesByAttrIdUnlimit", prodURL, map[string]interface{}{
|
||||
func (a *API) FindValuesByAttrId(categoryAttrId int) (findValuesByAttrIdResult []*FindValuesByAttrIdResult, maxOrder int, err error) {
|
||||
result, err := a.AccessAPI("jingdong.category.read.findValuesByAttrIdUnlimit", prodURL, map[string]interface{}{
|
||||
"categoryAttrId": categoryAttrId,
|
||||
})
|
||||
return err
|
||||
if err == nil {
|
||||
utils.Map2StructByJson(result["jingdong_category_read_findValuesByAttrIdUnlimit_responce"].(map[string]interface{})["findvaluesbyattridunlimit_result"], &findValuesByAttrIdResult, false)
|
||||
}
|
||||
return findValuesByAttrIdResult, findValuesByAttrIdResult[len(findValuesByAttrIdResult)-1].OrderSort, err
|
||||
}
|
||||
|
||||
//新增类目属性值
|
||||
//https://open.jd.com/home/home#/doc/api?apiCateId=62&apiId=1262&apiName=jingdong.category.write.saveVenderAttrValue
|
||||
func (a *API) SaveVenderAttrValue(attValue string, attributeId, categoryId, indexId int) (err error) {
|
||||
func (a *API) SaveVenderAttrValue(attValue string, attributeId, categoryId, indexId int) (categoryAttrId int64, err error) {
|
||||
_, err = a.AccessAPI("jingdong.category.write.saveVenderAttrValue", prodURL, map[string]interface{}{
|
||||
"attValue": attValue,
|
||||
"attributeId": attributeId,
|
||||
"categoryId": categoryId,
|
||||
"indexId": indexId,
|
||||
})
|
||||
return err
|
||||
result, _, err := a.FindValuesByAttrId(attributeId)
|
||||
for _, v := range result {
|
||||
if v.OrderSort == indexId {
|
||||
categoryAttrId = v.ID
|
||||
}
|
||||
}
|
||||
return categoryAttrId, err
|
||||
}
|
||||
|
||||
//设置sku库存
|
||||
|
||||
Reference in New Issue
Block a user