根据名字查询京东upc

This commit is contained in:
苏尹岚
2019-12-16 14:21:19 +08:00
parent f5166d59b6
commit 1f1835fa2d
4 changed files with 49 additions and 14 deletions

View File

@@ -7,6 +7,10 @@ import (
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/baseapi/utils"
@@ -1292,16 +1296,29 @@ func SortCategorySkus(ctx *jxcontext.Context, catID int, skuIDList []int) (err e
return err
}
func GetJdUpcCodeByName(ctx *jxcontext.Context, name string) (pagedInfo *model.PagedInfo, err error) {
pageNo := 1
pageSize := 30
jdSkus, totalCount, err := api.JdAPI.GetJdUpcCodeByName(name, pageNo, pageSize)
for _, v := range jdSkus {
fmt.Println(v)
func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) {
var (
pageNo = 5
pageSize = 30
pageNoList []int
)
for i := 1; i < pageNo+1; i++ {
pageNoList = append(pageNoList, i)
}
pagedInfo = &model.PagedInfo{
Data: jdSkus,
TotalCount: totalCount,
task := tasksch.NewParallelTask("获取京东商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
pageNum := batchItemList[0].(int)
productInfo, err := api.JdAPI.GetJdUpcCodeByName(name, upcCode, pageNum, pageSize)
if err != nil {
return retVal, err
}
retVal = productInfo
return retVal, err
}, pageNoList)
tasksch.HandleTask(task, nil, true).Run()
productInfoInterface, err := task.GetResult(0)
for _, v := range productInfoInterface {
productInfos = append(productInfos, v.(*jdapi.ProductInfo))
}
return pagedInfo, err
return productInfos, err
}

View File

@@ -83,3 +83,20 @@ type OrderFinancialSkuExt struct {
OrderSkuFinancial
Image string `json:"image"`
}
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"`
}

View File

@@ -379,13 +379,14 @@ func (c *SkuController) GetStoreSkuSalesInfo() {
// @Title 根据名字查询京东商品UPC信息
// @Description 根据名字查询京东商品UPC信息
// @Param token header string true "认证token"
// @Param name formData string true "商品名"
// @Param name query string false "商品名"
// @Param upcCode query string false "upcCode,不支持模糊"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /GetJdUpcCodeByName [post]
// @router /GetJdUpcCodeByName [get]
func (c *SkuController) GetJdUpcCodeByName() {
c.callGetJdUpcCodeByName(func(params *tSkuGetJdUpcCodeByNameParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.GetJdUpcCodeByName(params.Ctx, params.Name)
retVal, err = cms.GetJdUpcCodeByName(params.Ctx, params.Name, params.UpcCode)
return retVal, "", err
})
}

View File

@@ -1174,7 +1174,7 @@ func init() {
beego.ControllerComments{
Method: "GetJdUpcCodeByName",
Router: `/GetJdUpcCodeByName`,
AllowHTTPMethods: []string{"post"},
AllowHTTPMethods: []string{"get"},
MethodParams: param.Make(),
Filters: nil,
Params: nil})