创建标品优化
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@@ -1975,7 +1976,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 = int(utils.Str2Int64(utils.Float64ToStr(math.Round(float64(v.SpecQuality)))))
|
||||
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
|
||||
} else {
|
||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
|
||||
@@ -1984,7 +1985,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 = int(utils.Str2Int64(utils.Float64ToStr(math.Round(float64(specQuality)))))
|
||||
}
|
||||
} else {
|
||||
if getNetUpcInfo.SpecQuality != 0 {
|
||||
@@ -1992,7 +1993,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(specQuality))))
|
||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(math.Round(float64(specQuality)))))
|
||||
}
|
||||
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||
} else {
|
||||
@@ -2224,6 +2225,7 @@ func writeToExcel(excelTitle []string, dataList interface{}, ctx *jxcontext.Cont
|
||||
return err
|
||||
}
|
||||
|
||||
//恢复京东回收站,修改京西的京东id
|
||||
func RefreshJdDepot(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
pageSize = 20
|
||||
@@ -2295,3 +2297,99 @@ func uploadImgStandard(imgUrl string) (downloadResult string, err error) {
|
||||
}
|
||||
return downloadResult, err
|
||||
}
|
||||
|
||||
func AddSkuNameByUpc(ctx *jxcontext.Context, upc string, store *dao.StoreDetail, v *partner.SkuNameInfo) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
skuNames, err := dao.GetSkuNames(db, nil, []string{upc}, "", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//表示我们商品库中没有这个upc商品,如果有就直接关注上
|
||||
if len(skuNames) == 0 {
|
||||
skuNameExt := &model.SkuNameExt{
|
||||
SkuName: model.SkuName{
|
||||
Upc: &upc,
|
||||
Status: model.SkuStatusNormal,
|
||||
CategoryID: model.NoCatCatgoryID,
|
||||
IsGlobal: model.YES,
|
||||
Price: int(v.SkuList[0].VendorPrice),
|
||||
},
|
||||
Skus: []*model.SkuWithVendor{
|
||||
&model.SkuWithVendor{
|
||||
Sku: &model.Sku{
|
||||
Status: model.SkuStatusNormal,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
//我们商品库中有这个商品,但是upc没有填,则尝试用upc去查一下
|
||||
productInfos, err2 := GetJdUpcCodeByName(ctx, "", upc)
|
||||
err = err2
|
||||
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(upc)
|
||||
//表示用upc也没有找到这个商品
|
||||
if len(productInfos) == 0 {
|
||||
if getNetUpcInfo == nil || getNetUpcInfo.SpecQuality == 0 || getNetUpcInfo.Unit == "" {
|
||||
return fmt.Errorf("此商品无规格无法创建,upc :[%s] , unit: [%s], specQuality : [%v]", upc, getNetUpcInfo.Unit, getNetUpcInfo.SpecQuality)
|
||||
}
|
||||
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
|
||||
} else {
|
||||
skuNameExt.Img = model.NOSkuNameImg
|
||||
}
|
||||
}
|
||||
skuNameExt.Name = v.Name
|
||||
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))))
|
||||
} else {
|
||||
productInfo := productInfos[0]
|
||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, productInfo.Name, false)
|
||||
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]
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user