根据名字查京东商品upc

This commit is contained in:
苏尹岚
2019-12-16 14:20:03 +08:00
parent 1ec3724e34
commit 81b1f9d861
2 changed files with 44 additions and 15 deletions

View File

@@ -227,6 +227,23 @@ type StoreUserInfo struct {
UserCode string `json:"userCode"`
}
type ProductInfo struct {
OriginalName string `json:"originalName"`
OriginalSpec string `json:"originalSpec"`
Name string `json:"name"`
Img string `json:"img"`
ImgList []string `json:"imgList"`
SpecQuality int `json:"specQuality"`
SpecUnit string `json:"specUnit"`
Unit string `json:"unit"`
Weight float32 `json:"weight"`
Price int `json:"price"`
Categories []string `json:"categories"`
ManName string `json:"manName"` // 生产商
BrandName string `json:"brandName"`
UpcCode string `json:"upcCode"`
}
const (
QualifyTypeCompany = "25" // 营业执照
QualifyTypePerson = "22" // 身份证,个体工商户要求填
@@ -366,6 +383,9 @@ func (a *API) AccessStorePage2(fullURL string, params map[string]interface{}, is
code, ok := jsonResult1["code"].(string)
if !ok {
if statusMap, ok := jsonResult1["status"].(map[string]interface{}); !ok {
if jsonResult1["operTag"] != nil {
return platformapi.ErrLevelSuccess, nil
}
return platformapi.ErrLevelGeneralFail, utils.NewErrorCode(utils.Format4Output(jsonResult1, true), "999")
} else {
code = utils.Int64ToStr(utils.ForceInterface2Int64(statusMap["errorCode"]))
@@ -761,31 +781,40 @@ func (a *API) GetJdStoreLevel(vendorOrgCode, vendorStoreID string) (level string
// 根据商品名查找京东商品upc编码
// https://pms-store.jddj.com/product/searchProductStd
func (a *API) GetJdUpcCodeByName(name string, pageNo, pageSize int) (jdSkus []*JdSkus, totalCount int, err error) {
func (a *API) GetJdUpcCodeByName(name, upcCode string, pageNo, pageSize int) (productInfos []*ProductInfo, err error) {
jdParams := map[string]interface{}{
"searchType": 1,
"firstCategoryId": 0,
"currentPage": pageNo,
"pageSize": pageSize,
"productName": name,
"upcCode": upcCode,
}
result, err := a.AccessStorePage2("https://pms-store.jddj.com/product/searchProductStd", jdParams, true, "")
if err != nil {
return nil, err
}
result, _ := a.AccessStorePage2("https://pms-store.jddj.com/product/searchProductStd", jdParams, true, "")
data := result.(map[string]interface{})
totalCount = int(utils.Interface2Int64WithDefault(data["total"], 0))
// totalCount = int(utils.Interface2Int64WithDefault(data["total"], 0))
if data["rows"] == nil {
return productInfos, err
}
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,
var ImgList []string
ImgStr := v.(map[string]interface{})["productImageList"].([]interface{})
for _, vv := range ImgStr {
ImgList = append(ImgList, "http://img20.360buyimg.com/vc/"+vv.(string))
}
jdSkus = append(jdSkus, jdSku)
productInfo := &ProductInfo{
OriginalName: v.(map[string]interface{})["name"].(string),
Name: v.(map[string]interface{})["name"].(string),
UpcCode: v.(map[string]interface{})["upcCode"].(string),
Weight: float32(utils.Interface2Float64WithDefault(v.(map[string]interface{})["weight"], 0)),
ImgList: ImgList,
}
productInfos = append(productInfos, productInfo)
}
}
return jdSkus, totalCount, err
return productInfos, err
}

View File

@@ -232,5 +232,5 @@ func TestGetJdStoreLevel(t *testing.T) {
}
func TestGetJdUpcCodeByName(t *testing.T) {
api.GetJdUpcCodeByName("大米", 1, 5)
api.GetJdUpcCodeByName("", "6952395700895", 2, 5)
}