根据excel创建标品

This commit is contained in:
苏尹岚
2020-04-14 10:41:45 +08:00
parent 4444d0efaf
commit 3313d52f39
2 changed files with 28 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"mime/multipart" "mime/multipart"
"net/http"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@@ -1410,6 +1411,21 @@ func SortCategorySkus(ctx *jxcontext.Context, catID int, skuIDList []int) (err e
return err return err
} }
func GetJdUpcCodeByCode(ctx *jxcontext.Context, upcCode string) (productInfos []*jdapi.ProductInfo, err error) {
productInfo, err := api.JdAPI.GetJdUpcCodeByName("", upcCode, 1, 30)
if err != nil {
return nil, 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
}
return productInfo, err
}
func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) { func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productInfos []*jdapi.ProductInfo, err error) {
var ( var (
pageNo = 5 pageNo = 5
@@ -1853,7 +1869,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (hint stri
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品在京西库中已存在!")) createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品在京西库中已存在!"))
continue continue
} }
productInfos, err := GetJdUpcCodeByName(ctx, "", *v.Upc) productInfos, err := GetJdUpcCodeByCode(ctx, *v.Upc)
if err != nil { if err != nil {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, err.Error())) createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, err.Error()))
continue continue
@@ -1985,11 +2001,17 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (hint stri
if !strings.Contains(skuName.Img, "image.jxc4.com") { if !strings.Contains(skuName.Img, "image.jxc4.com") {
if resBinary, _, err := jxutils.DownloadFileByURL(skuName.Img); err == nil { 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 { if downloadURL, err := jxutils.UploadExportContent(resBinary, skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
if img, _, err := datares.Binary2Image(resBinary, http.DetectContentType(resBinary)); err == nil {
if img.Bounds().Dx() != datares.MainImgWidth || img.Bounds().Dy() != datares.MainImgHeight {
if resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard); err == nil { if resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard); err == nil {
if downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil { if downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
skuName.Img = downloadURL2 skuName.Img = downloadURL2
} }
} }
} else {
skuName.Img = downloadURL
}
}
} }
} }
} }

View File

@@ -1233,12 +1233,14 @@ func GetOrdersForJxPay(db *DaoDB, finishTimeBegin, finishTimeEnd time.Time) (goo
AND a.order_finished_at <= ? AND a.order_finished_at <= ?
AND a.status = ? AND a.status = ?
AND c.parent_mobile <> '' AND c.parent_mobile <> ''
AND a.store_id <> ?
` `
sqlParams := []interface{}{ sqlParams := []interface{}{
model.VendorIDJX, model.VendorIDJX,
finishTimeBegin, finishTimeBegin,
finishTimeEnd, finishTimeEnd,
model.OrderStatusFinished, model.OrderStatusFinished,
model.MatterStoreID,
} }
err = GetRows(db, &goods, sql, sqlParams...) err = GetRows(db, &goods, sql, sqlParams...)
return goods, err return goods, err