diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 082cabe58..8a1a203e6 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -1427,38 +1427,43 @@ func GetJdUpcCodeByCode(ctx *jxcontext.Context, upcCode string) (productInfos [] } func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) { - var ( - pageNo = 5 - pageSize = 30 - pageNoList []int - ) - if name == "" && upcCode == "" { - return nil, fmt.Errorf("至少输入一个条件查询,商品名或者upc码!") - } - for i := 1; i < pageNo+1; i++ { - pageNoList = append(pageNoList, i) - } - 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 { + if name != "" { + var ( + pageNo = 5 + pageSize = 30 + pageNoList []int + ) + if name == "" && upcCode == "" { + return nil, fmt.Errorf("至少输入一个条件查询,商品名或者upc码!") + } + for i := 1; i < pageNo+1; i++ { + pageNoList = append(pageNoList, i) + } + 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 + } + for _, v := range productInfo { + _, name, _, specUnit, unit, specQuality := jxutils.SplitSkuName(v.OriginalName) + v.Name = name + v.SpecQuality = specQuality + v.SpecUnit = specUnit + v.Unit = unit + } + retVal = productInfo return retVal, err - } - for _, v := range productInfo { - _, name, _, specUnit, unit, specQuality := jxutils.SplitSkuName(v.OriginalName) - v.Name = name - v.SpecQuality = specQuality - v.SpecUnit = specUnit - v.Unit = unit - } - 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)) + }, pageNoList) + tasksch.HandleTask(task, nil, true).Run() + productInfoInterface, err2 := task.GetResult(0) + err = err2 + for _, v := range productInfoInterface { + productInfos = append(productInfos, v.(*jdapi.ProductInfo)) + } + } else { + productInfos, err = GetJdUpcCodeByCode(ctx, upcCode) } return productInfos, err } @@ -1998,6 +2003,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (hint stri createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, fmt.Sprintf("暂不支持的图片格式:[%v]", skuName.Img))) continue } + //需要把图片传到七牛云上 if !strings.Contains(skuName.Img, "image.jxc4.com") { if resBinary, _, err := jxutils.DownloadFileByURL(skuName.Img); err == nil { if downloadURL, err := jxutils.UploadExportContent(resBinary, skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {