同步银豹到京西商品,测试list
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/aliupcapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/datares"
|
||||
@@ -1976,7 +1975,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
}
|
||||
if v.SpecQuality != 0 {
|
||||
skuName.Skus[0].SpecQuality = v.SpecQuality
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(math.Round(float64(v.SpecQuality)))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
|
||||
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
|
||||
} else {
|
||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
|
||||
@@ -1985,7 +1984,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
if specUnit == model.SpecUnitNames[1] || specUnit == model.SpecUnitNames[2] {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(specQuality) * 1000)))
|
||||
} else {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(math.Round(float64(specQuality)))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(specQuality)
|
||||
}
|
||||
} else {
|
||||
if getNetUpcInfo.SpecQuality != 0 {
|
||||
@@ -1993,7 +1992,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000)))
|
||||
} else {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(math.Round(float64(specQuality)))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
|
||||
}
|
||||
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||
} else {
|
||||
@@ -2061,7 +2060,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
}
|
||||
if v.SpecQuality != 0 {
|
||||
skuName.Skus[0].SpecQuality = v.SpecQuality
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(v.SpecQuality))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
|
||||
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
|
||||
} else {
|
||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
|
||||
@@ -2070,7 +2069,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
if specUnit == model.SpecUnitNames[1] || specUnit == model.SpecUnitNames[2] {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(specQuality) * 1000)))
|
||||
} else {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(specQuality))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(specQuality)
|
||||
}
|
||||
} else {
|
||||
if productInfo.SpecQuality == 0 {
|
||||
@@ -2079,7 +2078,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000)))
|
||||
} else {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
|
||||
}
|
||||
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||
} else {
|
||||
@@ -2090,7 +2089,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
if productInfo.Weight != 0 {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
||||
} else {
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.SpecQuality))))
|
||||
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
|
||||
}
|
||||
skuName.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||
}
|
||||
@@ -2168,11 +2167,6 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
skuName.CategoryID = categoryID
|
||||
}
|
||||
skuName.Skus[0].Status = model.SkuStatusNormal
|
||||
if resBinary, _, err := jxutils.DownloadFileByURL(skuName.Img); err == nil {
|
||||
if model.ValidMimeTypes[http.DetectContentType(resBinary)] == 0 {
|
||||
skuName.Img = model.NOSkuNameImg
|
||||
}
|
||||
}
|
||||
_, err = AddSkuName(ctx, skuName, ctx.GetUserName())
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
@@ -2326,8 +2320,8 @@ func AddSkuNameByUpc(ctx *jxcontext.Context, upc string, store *dao.StoreDetail,
|
||||
}
|
||||
//我们商品库中有这个商品,但是upc没有填,则尝试用upc去查一下
|
||||
productInfos, err2 := GetJdUpcCodeByName(ctx, "", upc)
|
||||
getNetUpcInfo, err2 := api.AliUpcAPI.GetNetUpcInfo(upc)
|
||||
err = err2
|
||||
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(upc)
|
||||
//表示用upc也没有找到这个商品
|
||||
if len(productInfos) == 0 {
|
||||
if getNetUpcInfo == nil || getNetUpcInfo.SpecQuality == 0 || getNetUpcInfo.Unit == "" {
|
||||
@@ -2336,18 +2330,9 @@ func AddSkuNameByUpc(ctx *jxcontext.Context, upc string, store *dao.StoreDetail,
|
||||
if len(v.PictureList) > 0 {
|
||||
skuNameExt.Img = v.PictureList[0]
|
||||
} else {
|
||||
var result *aliupcapi.GetAliUpcInfoResult
|
||||
upcDepot, err := dao.GetUpcDepot(db, upc)
|
||||
if upcDepot == nil {
|
||||
result, err = api.AliUpcAPI.GetAliUpcInfo(upc)
|
||||
if err == nil {
|
||||
err = dao.InsertUpcDepot(db, result)
|
||||
}
|
||||
} else {
|
||||
result = upcDepot
|
||||
}
|
||||
if result.Img != "" {
|
||||
skuNameExt.Img = result.Img
|
||||
img := getImgFromNet(db, upc)
|
||||
if img != "" {
|
||||
skuNameExt.Img = img
|
||||
} else {
|
||||
skuNameExt.Img = model.NOSkuNameImg
|
||||
}
|
||||
@@ -2356,40 +2341,95 @@ func AddSkuNameByUpc(ctx *jxcontext.Context, upc string, store *dao.StoreDetail,
|
||||
skuNameExt.Unit = getNetUpcInfo.Unit
|
||||
skuNameExt.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||
skuNameExt.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit
|
||||
skuNameExt.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality))))
|
||||
skuNameExt.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
|
||||
} else {
|
||||
productInfo := productInfos[0]
|
||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, productInfo.Name, false)
|
||||
if (productInfo.SpecQuality == 0 || productInfo.Unit == "") && (getNetUpcInfo == nil || getNetUpcInfo.SpecQuality == 0 || getNetUpcInfo.Unit == "") {
|
||||
return fmt.Errorf("此商品无规格无法创建,upc :[%s] , unit: [%s], specQuality : [%v]", upc, getNetUpcInfo.Unit, getNetUpcInfo.SpecQuality)
|
||||
}
|
||||
if productInfo.SpecQuality == 0 {
|
||||
skuNameExt.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||
skuNameExt.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
|
||||
} else {
|
||||
skuNameExt.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||
skuNameExt.Skus[0].Weight = utils.Float32ToInt(productInfo.SpecQuality)
|
||||
}
|
||||
if productInfo.SpecUnit == "" {
|
||||
skuNameExt.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit
|
||||
} else {
|
||||
skuNameExt.Skus[0].SpecUnit = productInfo.SpecUnit
|
||||
}
|
||||
if len(productInfo.ImgList) > 0 {
|
||||
skuNameExt.Img = productInfo.ImgList[0]
|
||||
} else {
|
||||
img := getImgFromNet(db, upc)
|
||||
if img != "" {
|
||||
skuNameExt.Img = img
|
||||
} else {
|
||||
skuNameExt.Img = model.NOSkuNameImg
|
||||
}
|
||||
}
|
||||
}
|
||||
if flag := checkAndUpdateUpc(ctx, db, skuNameExt, v, store); !flag {
|
||||
if !strings.Contains(skuNameExt.Img, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuNameExt.Img)
|
||||
if err != nil {
|
||||
skuNameExt.Img = model.NOSkuNameImg
|
||||
} else {
|
||||
skuNameExt.Img = downloadURL
|
||||
}
|
||||
}
|
||||
if resBinary, _, err := jxutils.DownloadFileByURL(skuNameExt.Img); err == nil {
|
||||
if model.ValidMimeTypes[http.DetectContentType(resBinary)] == 0 {
|
||||
skuNameExt.Img = model.NOSkuNameImg
|
||||
}
|
||||
}
|
||||
if skuNameExt.SpecUnit == model.SpecUnitNames[1] || skuNameExt.SpecUnit == model.SpecUnitNames[2] ||
|
||||
skuNameExt.SpecUnit == "KG" || skuNameExt.SpecUnit == "l" {
|
||||
skuNameExt.Skus[0].Weight = skuNameExt.Skus[0].Weight * 1000
|
||||
}
|
||||
outSkuNameExt, err := AddSkuName(ctx, skuNameExt, ctx.GetUserName())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(skuNames2) > 1 {
|
||||
return fmt.Errorf("此商品名在京西库中查询出了大于1个商品,[%v]", productInfo.Name)
|
||||
}
|
||||
//表示查到了,需要把upc更新上去,没查到就要新建
|
||||
if len(skuNames2) == 1 && (productInfo.SpecQuality == skuNames2[0].SpecQuality && productInfo.SpecUnit == skuNames2[0].SpecUnit) {
|
||||
skuNames2[0].Upc = &upc
|
||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames2[0].ID)
|
||||
} else {
|
||||
if len(v.SkuList) > 0 {
|
||||
skuNameExt.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||
skuNameExt.Skus[0].SpecUnit = productInfo.SpecUnit
|
||||
skuNameExt.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
||||
}
|
||||
if len(productInfo.ImgList) > 0 {
|
||||
skuNameExt.Img = productInfo.ImgList[0]
|
||||
}
|
||||
}
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, outSkuNameExt.ID)
|
||||
}
|
||||
outSkuNameExt, err := AddSkuName(ctx, skuNameExt, ctx.GetUserName())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, outSkuNameExt.ID)
|
||||
} else {
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames[0].ID)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//该商品名,规格在库中能查询出则更新upc不插入
|
||||
func checkAndUpdateUpc(ctx *jxcontext.Context, db *dao.DaoDB, skuNameExt *model.SkuNameExt, v *partner.SkuNameInfo, store *dao.StoreDetail) (flag bool) {
|
||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, skuNameExt.Name, false)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if len(skuNames2) == 0 {
|
||||
return false
|
||||
}
|
||||
//表示查到了,需要把upc更新上去,没查到就要新建
|
||||
if skuNameExt.SpecQuality == skuNames2[0].SpecQuality {
|
||||
skuNames2[0].Upc = skuNameExt.Upc
|
||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames2[0].ID)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getImgFromNet(db *dao.DaoDB, upc string) (img string) {
|
||||
var result *aliupcapi.GetAliUpcInfoResult
|
||||
upcDepot, err := dao.GetUpcDepot(db, upc)
|
||||
if upcDepot == nil {
|
||||
result, err = api.AliUpcAPI.GetAliUpcInfo(upc)
|
||||
if err == nil {
|
||||
err = dao.InsertUpcDepot(db, result)
|
||||
}
|
||||
} else {
|
||||
result = upcDepot
|
||||
}
|
||||
img = result.Img
|
||||
return img
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user