From 25dedce4f44466deb4d15f4606a8cb012c6ca348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 12 Jun 2020 16:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E5=9B=A2=E6=96=B0apisku=E9=94=80?= =?UTF-8?q?=E5=94=AE=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/jdshopapi/sku.go | 2 +- platformapi/jdshopapi/sku_test.go | 30 +++++------------- platformapi/mtwmapi/retail.go | 51 ++++++++++++++++++++++++++++++ platformapi/mtwmapi/retail_test.go | 16 ++++++++++ 4 files changed, 76 insertions(+), 23 deletions(-) diff --git a/platformapi/jdshopapi/sku.go b/platformapi/jdshopapi/sku.go index 88af991d..59d6151a 100644 --- a/platformapi/jdshopapi/sku.go +++ b/platformapi/jdshopapi/sku.go @@ -182,7 +182,7 @@ type UpdateSkusParamSkus struct { Capacity string `json:"capacity,omitempty"` //否 20L 容量,在有特殊要求的类目下必填!最多支持6位小数。 Type string `json:"type"` //"com.jd.pop.ware.ic.api.domain.sku" Type2 string `json:"@type"` - MultiCateProps []*CreateSkuParamAttrs `json:"multiCateProps"` // 否 无 类目属性列表,类目属性中有必填项时,此字段必填;若未设置或设置错误,会有“通用属性必填”等错误提示! + MultiCateProps []*CreateSkuParamAttrs `json:"multiCateProps,omitempty"` // 否 无 类目属性列表,类目属性中有必填项时,此字段必填;若未设置或设置错误,会有“通用属性必填”等错误提示! } //查询商家所有的店内分类 diff --git a/platformapi/jdshopapi/sku_test.go b/platformapi/jdshopapi/sku_test.go index 37810ad2..3fbe9703 100644 --- a/platformapi/jdshopapi/sku_test.go +++ b/platformapi/jdshopapi/sku_test.go @@ -328,31 +328,17 @@ func TestSearchWare4Valid(t *testing.T) { func TestUpdateSkus(t *testing.T) { _, err := api.UpdateSkus(&UpdateSkusParam{ - WareID: 14537944716, + WareID: 14600091031, Skus: []*UpdateSkusParamSkus{ &UpdateSkusParamSkus{ - WareID: 14537944716, - JdPrice: 1.5, - StockNum: "99", - OuterID: "11", + WareID: 14600091031, + SkuID: 70357447332, + JdPrice: 7.5, + StockNum: "9999", SaleAttrs: []*CreateSkuParamAttrs{ &CreateSkuParamAttrs{ AttrID: "1001027602", - AttrValues: []string{"2440977935"}, - }, - }, - Type: "com.jd.pop.ware.ic.api.domain.sku", - Type2: "com.jd.pop.ware.ic.api.domain.Sku", - }, - &UpdateSkusParamSkus{ - WareID: 14537944716, - JdPrice: 1.8, - StockNum: "99", - OuterID: "123", - SaleAttrs: []*CreateSkuParamAttrs{ - &CreateSkuParamAttrs{ - AttrID: "1001027602", - AttrValues: []string{"2441761921"}, + AttrValues: []string{"2441658643"}, }, }, Type: "com.jd.pop.ware.ic.api.domain.sku", @@ -436,10 +422,10 @@ func TestTransparentImageAdd(t *testing.T) { func TestUpdateWareSaleAttrvalueAlias(t *testing.T) { err := api.UpdateWareSaleAttrvalueAlias(&UpdateWareSaleAttrvalueAliasParam{ - WareID: 14566414324, + WareID: 14565234929, Props: []*CreateSkuParamAttrs2{ &CreateSkuParamAttrs2{ - AttrID: "1001038262", + AttrID: "1000021981", AttrValues: []string{"2453826609"}, AttrValueAlias: []string{"500g 下午易缺货"}, Type: "com.jd.pop.ware.ic.api.domain.prop", diff --git a/platformapi/mtwmapi/retail.go b/platformapi/mtwmapi/retail.go index 71c1e1a1..f316b3c4 100644 --- a/platformapi/mtwmapi/retail.go +++ b/platformapi/mtwmapi/retail.go @@ -20,6 +20,10 @@ const ( SellStatusOffline = 1 // 下架 ) +const ( + MtwmSkuAttr = `[{"attrId":1200000094,"attrName":"产地","valueList":[{"valueId":100000050,"value":"中国"}]},{"attrId":1200000132,"attrName":"国产/进口","valueList":[{"valueId":1300000003,"value":"国产"}]},{"attrId":1200000210,"attrName":"商品类别","valueList":[{"valueId":1300002991,"value":"水果混合切片"}]},{"attrId":1200000275,"attrName":"是否有机","valueList":[{"valueId":1300003874,"value":"无机"}]},{"attrId":1200000286,"attrName":"果品品牌","valueList":[{"valueId":1300003944,"value":"其他品牌"}]}]` +) + var ( retailBatchFailedSkuReg = regexp.MustCompile(`((?:\d+;)+)`) ) @@ -127,6 +131,21 @@ type Param4UpdateCat struct { Period string `json:"period,omitempty"` } +type CategoryAttrListResult struct { + AttrID string `json:"attr_id"` + AttrName string `json:"attr_name"` + AttrValueType string `json:"attr_value_type"` + Need string `json:"need"` + CharacterType string `json:"character_type"` + TextMaxLength string `json:"text_max_length"` + Sequence int `json:"sequence"` + SupportExtend string `json:"support_extend"` + ValueList []struct { + ValueID string `json:"value_id"` + Value string `json:"value"` + } `json:"value_list"` +} + // 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名 // name(和originName)的长度不能超过10个字符(字符,不是字节) // 创建一级分类,originName为空,name为新分类名,secondaryName为空 @@ -363,6 +382,38 @@ func (a *API) RetailSkuDelete(trackInfo, poiCode, foodCode, skuID string) (err e return err } +//category/attr/list 根据末级类目id获取类目属性列表 +//https://open-shangou.meituan.com/home/docDetail/386 +func (a *API) CategoryAttrList(tag_id int64) (categoryAttrListResult []*CategoryAttrListResult, err error) { + result, err := a.AccessAPI("gw/category/attr/list", true, map[string]interface{}{ + "tag_id": tag_id, + }) + if err == nil { + utils.Map2StructByJson(result.(map[string]interface{})["general_attrs"], &categoryAttrListResult, false) + } + return categoryAttrListResult, err +} + +type CategoryAttrValueListResult struct { + ValueID string `json:"value_id"` + Value string `json:"value"` +} + +//category/attr/value/list 查询特殊属性的属性值列表 +//https://open-shangou.meituan.com/home/docDetail/387 +func (a *API) CategoryAttrValueList(attr_id int64, keyword string, page_num, page_size int) (categoryAttrValueListResult []*CategoryAttrValueListResult, err error) { + result, err := a.AccessAPI("gw/category/attr/value/list", true, map[string]interface{}{ + "attr_id": attr_id, + "keyword": keyword, + "page_num": page_num, + "page_size": page_size, + }) + if err == nil { + utils.Map2StructByJson(result, &categoryAttrValueListResult, false) + } + return categoryAttrValueListResult, err +} + // 就是厂商商品类别 func (a *API) RetailGetSpTagIds() (tagIds []*RetailTag, err error) { result, err := a.AccessAPI("retail/getSpTagIds", true, nil) diff --git a/platformapi/mtwmapi/retail_test.go b/platformapi/mtwmapi/retail_test.go index ed562b76..fb98a2d3 100644 --- a/platformapi/mtwmapi/retail_test.go +++ b/platformapi/mtwmapi/retail_test.go @@ -284,3 +284,19 @@ func TestRetailSellStatus(t *testing.T) { } t.Log(utils.Format4Output(result, false)) } + +func TestCategoryAttrList(t *testing.T) { + result, err := api.CategoryAttrList(200002727) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(result, false)) +} + +func TestCategoryAttrValueList(t *testing.T) { + result, err := api.CategoryAttrValueList(1200000094, "中国", 1, 5) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(result, false)) +}