diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 774dfc9d..a18269fe 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -264,6 +264,12 @@ type JdUserPostResult struct { } `json:"status"` } +type JdSkus struct { + Name string `json:name` + UpcCode string `json:upcCode` + ImgList []string `json:imgList` +} + var ( monthSaleNumReg = regexp.MustCompile(`(\d+)([千|万])`) pageExceedLimitCodes = map[string]int{ @@ -752,3 +758,34 @@ func (a *API) GetJdStoreLevel(vendorOrgCode, vendorStoreID string) (level string } return level, err } + +// 根据商品名,查找京东商品upc编码 +// https://pms-store.jddj.com/product/searchProductStd +func (a *API) GetJdUpcCodeByName(name string, pageNo, pageSize int) (jdSkus []*JdSkus, totalCount int, err error) { + jdParams := map[string]interface{}{ + "searchType": 1, + "firstCategoryId": 0, + "currentPage": pageNo, + "pageSize": pageSize, + "productName": name, + } + result, _ := a.AccessStorePage2("https://pms-store.jddj.com/product/searchProductStd", jdParams, true, "") + data := result.(map[string]interface{}) + totalCount = int(utils.Interface2Int64WithDefault(data["total"], 0)) + for _, v := range data["rows"].([]interface{}) { + var ImgList []string + ImgStr := v.(map[string]interface{})["productImageList"].([]interface{}) + for _, vv := range ImgStr { + ImgList = append(ImgList, "http://img20.360buyimg.com/vc/"+vv.(string)) + } + if v.(map[string]interface{})["upcCode"].(string) != "" { + jdSku := &JdSkus{ + Name: v.(map[string]interface{})["name"].(string), + UpcCode: v.(map[string]interface{})["upcCode"].(string), + ImgList: ImgList, + } + jdSkus = append(jdSkus, jdSku) + } + } + return jdSkus, totalCount, err +} diff --git a/platformapi/jdapi/store_page_test.go b/platformapi/jdapi/store_page_test.go index fdf41ce6..2f9609cb 100644 --- a/platformapi/jdapi/store_page_test.go +++ b/platformapi/jdapi/store_page_test.go @@ -230,3 +230,7 @@ func TestIsJdManagerUser(t *testing.T) { func TestGetJdStoreLevel(t *testing.T) { api.GetJdStoreLevel("320406", "11732427") } + +func TestGetJdUpcCodeByName(t *testing.T) { + api.GetJdUpcCodeByName("大米", 1, 5) +}