创建标品优化
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -1975,7 +1976,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
|||||||
}
|
}
|
||||||
if v.SpecQuality != 0 {
|
if v.SpecQuality != 0 {
|
||||||
skuName.Skus[0].SpecQuality = v.SpecQuality
|
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]
|
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
|
||||||
} else {
|
} else {
|
||||||
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
|
_, _, _, 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] {
|
if specUnit == model.SpecUnitNames[1] || specUnit == model.SpecUnitNames[2] {
|
||||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(specQuality) * 1000)))
|
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(specQuality) * 1000)))
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
if getNetUpcInfo.SpecQuality != 0 {
|
if getNetUpcInfo.SpecQuality != 0 {
|
||||||
@@ -1992,7 +1993,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
|||||||
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
|
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
|
||||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000)))
|
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000)))
|
||||||
} else {
|
} 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
|
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||||
} else {
|
} else {
|
||||||
@@ -2224,6 +2225,7 @@ func writeToExcel(excelTitle []string, dataList interface{}, ctx *jxcontext.Cont
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//恢复京东回收站,修改京西的京东id
|
||||||
func RefreshJdDepot(ctx *jxcontext.Context) (err error) {
|
func RefreshJdDepot(ctx *jxcontext.Context) (err error) {
|
||||||
var (
|
var (
|
||||||
pageSize = 20
|
pageSize = 20
|
||||||
@@ -2295,3 +2297,99 @@ func uploadImgStandard(imgUrl string) (downloadResult string, err error) {
|
|||||||
}
|
}
|
||||||
return downloadResult, err
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -4058,7 +4058,8 @@ func RefreshMatterStock(ctx *jxcontext.Context, skuID int) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildStoreSkuBindInfosAndFocus(ctx *jxcontext.Context, db *dao.DaoDB, store *dao.StoreDetail, v *partner.SkuNameInfo, nameID int, pricePercentagePack []*model.PricePercentageItem) (err error) {
|
func buildStoreSkuBindInfosAndFocus(ctx *jxcontext.Context, db *dao.DaoDB, store *dao.StoreDetail, v *partner.SkuNameInfo, nameID int) (err error) {
|
||||||
|
var pricePercentagePack []*model.PricePercentageItem
|
||||||
skus, _ := dao.GetSkus(db, nil, []int{nameID}, nil, nil, nil)
|
skus, _ := dao.GetSkus(db, nil, []int{nameID}, nil, nil, nil)
|
||||||
err = jxutils.Strings2Objs(store.PricePercentagePackStr, &pricePercentagePack)
|
err = jxutils.Strings2Objs(store.PricePercentagePackStr, &pricePercentagePack)
|
||||||
price := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, int(v.SkuList[0].VendorPrice))
|
price := jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, int(v.SkuList[0].VendorPrice))
|
||||||
|
|||||||
@@ -952,95 +952,22 @@ func syncStoreSkusFromYb(ctx *jxcontext.Context, storeID, vendorID int, vendorSt
|
|||||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
|
if len(addList) > 0 {
|
||||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
var (
|
var (
|
||||||
v = batchItemList[0].(*partner.SkuNameInfo)
|
v = batchItemList[0].(*partner.SkuNameInfo)
|
||||||
pricePercentagePack []*model.PricePercentageItem
|
|
||||||
upc = v.YbBarCode
|
upc = v.YbBarCode
|
||||||
)
|
)
|
||||||
skuNames, err := dao.GetSkuNames(db, nil, []string{upc}, "", false)
|
err = AddSkuNameByUpc(ctx, upc, store, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return retVal, err
|
task.AddFailedList(putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorChineseNames[vendorID], "根据upc创建京西商品"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//表示我们商品库中没有这个upc商品,如果有就直接关注上
|
|
||||||
if len(skuNames) == 0 {
|
|
||||||
//我们商品库中有这个商品,但是upc没有填,则尝试用upc去查一下
|
|
||||||
productInfos, err2 := GetJdUpcCodeByName(ctx, "", upc)
|
|
||||||
err = err2
|
|
||||||
//表示用upc也没有找到这个商品,则再尝试用银豹上的名字去查
|
|
||||||
if len(productInfos) == 0 {
|
|
||||||
var skuNames []string
|
|
||||||
skuNames = append(skuNames, v.Name) //银豹上的名字
|
|
||||||
for _, name := range skuNames {
|
|
||||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, name, false)
|
|
||||||
if err != nil {
|
|
||||||
return retVal, err
|
|
||||||
}
|
|
||||||
//表示查到了,需要把upc更新上去,没查到就要新建
|
|
||||||
if len(skuNames2) == 1 {
|
|
||||||
skuNames2[0].Upc = &v.YbBarCode
|
|
||||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
|
||||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames2[0].ID, pricePercentagePack)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
productInfo := productInfos[0]
|
|
||||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, productInfo.Name, false)
|
|
||||||
if err != nil {
|
|
||||||
return retVal, err
|
|
||||||
}
|
|
||||||
if len(skuNames2) > 1 {
|
|
||||||
return retVal, fmt.Errorf("此商品名在京西库中查询出了大于1个商品,[%v]", productInfo.Name)
|
|
||||||
}
|
|
||||||
//表示查到了,需要把upc更新上去,没查到就要新建
|
|
||||||
if len(skuNames2) == 1 && (productInfo.SpecQuality == skuNames2[0].SpecQuality && productInfo.SpecUnit == skuNames2[0].SpecUnit) {
|
|
||||||
skuNames2[0].Upc = &v.YbBarCode
|
|
||||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
|
||||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames2[0].ID, pricePercentagePack)
|
|
||||||
} else {
|
|
||||||
skuNameExt := &model.SkuNameExt{
|
|
||||||
SkuName: model.SkuName{
|
|
||||||
Name: productInfo.Name,
|
|
||||||
Upc: &productInfo.UpcCode,
|
|
||||||
Status: model.SkuStatusNormal,
|
|
||||||
CategoryID: model.NoCatCatgoryID,
|
|
||||||
IsGlobal: model.YES,
|
|
||||||
Unit: productInfo.Unit,
|
|
||||||
},
|
|
||||||
Skus: []*model.SkuWithVendor{
|
|
||||||
&model.SkuWithVendor{
|
|
||||||
Sku: &model.Sku{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// Places: []int{510100}, //默认成都
|
|
||||||
}
|
|
||||||
if len(v.SkuList) > 0 {
|
|
||||||
skuNameExt.Price = int(v.SkuList[0].VendorPrice)
|
|
||||||
skuNameExt.Skus[0].SpecQuality = productInfo.SpecQuality
|
|
||||||
skuNameExt.Skus[0].SpecUnit = productInfo.SpecUnit
|
|
||||||
skuNameExt.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
|
||||||
skuNameExt.Skus[0].Status = model.SkuStatusNormal
|
|
||||||
}
|
|
||||||
if len(productInfo.ImgList) > 0 {
|
|
||||||
skuNameExt.Img = productInfo.ImgList[0]
|
|
||||||
}
|
|
||||||
outSkuNameExt, err := AddSkuName(ctx, skuNameExt, ctx.GetUserName())
|
|
||||||
if err != nil {
|
|
||||||
return retVal, err
|
|
||||||
}
|
|
||||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, outSkuNameExt.ID, pricePercentagePack)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames[0].ID, pricePercentagePack)
|
|
||||||
}
|
|
||||||
|
|
||||||
return retVal, err
|
return retVal, err
|
||||||
}
|
}
|
||||||
taskParallel := tasksch.NewParallelTask("创建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, taskFunc, addList)
|
taskParallel := tasksch.NewParallelTask("创建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, taskFunc, addList)
|
||||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||||
_, err = taskParallel.GetResult(0)
|
_, err = taskParallel.GetResult(0)
|
||||||
|
}
|
||||||
case 1:
|
case 1:
|
||||||
}
|
}
|
||||||
return result, err
|
return result, err
|
||||||
|
|||||||
Reference in New Issue
Block a user