This commit is contained in:
苏尹岚
2021-03-26 16:11:37 +08:00
parent 9aa44c38d1
commit 8e561af698
2 changed files with 79 additions and 172 deletions

View File

@@ -2088,75 +2088,86 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
return retVal, err
}
var productInfo = &jdapi.ProductInfo{}
if len(productInfos) == 0 {
var result *aliupcapi.GetAliUpcInfoResult
upcDepot, err := dao.GetUpcDepot(db, *v.Upc)
if upcDepot == nil {
result, err = api.AliUpcAPI.GetAliUpcInfo(*v.Upc)
if err == nil {
err = dao.InsertUpcDepot(db, result)
}
} else {
result = upcDepot
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtwmCookieStr", model.ConfigTypeCookie, ""); err == nil {
api.MtwmAPI.SetCookieWithStr(configs[0].Value)
}
if result == nil {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未在标品库查到此商品,请手动创建!")}
result, _ := api.MtwmAPI.GetStandardProductListWithCond(*skuName.Upc)
if result != nil {
productInfo.OriginalName = result.Name
productInfo.OriginalSpec = result.Spec
productInfo.Name = result.Name
productInfo.SpecUnit = result.SpecUnit
productInfo.Unit = result.Unit
productInfo.SpecQuality = float32(result.SpecNew)
productInfo.ImgList = strings.Split(result.Pic, ",")
productInfo.Weight = float32(result.Weight)
productInfo.BrandName = result.BrandNamePath
setImgs(skuName, productInfo.ImgList)
} else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "美团cookie过期了吧")}
return retVal, err
}
if result.Img != "" {
downloadURL, err := uploadImgStandard(skuName.Img)
if err != nil {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
return retVal, err
}
skuName.Img = downloadURL
} else {
skuName.Img = model.NOSkuNameImg
}
} else {
productInfo = productInfos[0]
}
if productInfo.Name == "" {
if v.Name != "" {
skuName.Name = v.Name
productInfo.Name = v.Name
} else if productInfo.OriginalName != "" {
productInfo.Name = productInfo.OriginalName
} else {
skuName.Name = result.GoodsName
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "需要填上一个合适的商品名!")}
return retVal, err
}
if v.Price == 0 {
if result.Price == "" {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品的售价!")}
return retVal, err
} else {
skuName.Price = int(utils.Str2Int64(result.Price) * 100)
}
} else {
skuName.Price = v.Price
}
if v.Price == 0 {
result, err := api.AliUpcAPI.GetAliUpcInfo(*v.Upc)
if err != nil {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
return retVal, err
}
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(*v.Upc)
if v.Unit != "" {
if v.Unit == model.UnitNames[0] {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "标品的单位不能为份!")}
return retVal, err
}
skuName.Unit = v.Unit
if result.Price == "" {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品售价!")}
return retVal, err
} else {
skuName.Price = int(utils.Str2Int64(result.Price) * 100)
}
} else {
skuName.Price = v.Price
}
skuName.Name = productInfo.Name
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(*v.Upc)
if v.Unit != "" {
skuName.Unit = v.Unit
} else {
if productInfo.Unit == "" {
if getNetUpcInfo.Unit != "" {
skuName.Unit = getNetUpcInfo.Unit
} else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品单位,请补充商品单位!")}
return retVal, err
}
}
if v.SpecQuality != 0 {
skuName.Skus[0].SpecQuality = v.SpecQuality
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
} else {
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
if specQuality != 0 {
skuName.Skus[0].SpecQuality = specQuality
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 = utils.Float32ToInt(specQuality)
}
skuName.Unit = productInfo.Unit
}
}
if v.SpecQuality != 0 {
skuName.Skus[0].SpecQuality = v.SpecQuality
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
} else {
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
if specQuality != 0 {
skuName.Skus[0].SpecQuality = specQuality
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 = utils.Float32ToInt(specQuality)
}
} else {
if productInfo.SpecQuality == 0 {
if getNetUpcInfo.SpecQuality != 0 {
if getNetUpcInfo.SpecUnit == model.SpecUnitNames[1] || getNetUpcInfo.SpecUnit == model.SpecUnitNames[2] ||
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
@@ -2169,120 +2180,32 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品重量,请补充商品重量!")}
return retVal, err
}
} else {
if productInfo.Weight != 0 {
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
} else {
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
}
skuName.Skus[0].SpecQuality = productInfo.SpecQuality
}
}
if productInfo.SpecUnit == "" {
if getNetUpcInfo.SpecUnit != "" {
skuName.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit
} else {
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
}
}
} else {
productInfo := productInfos[0]
if productInfo.Name == "" {
if v.Name != "" {
productInfo.Name = v.Name
} else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "需要填上一个合适的商品名!")}
return retVal, err
}
}
skuNames2, _ := dao.GetSkuNames(db, nil, nil, productInfo.Name, false)
if len(skuNames2) > 1 {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "此商品名在京西库中查询出了大于1个商品")}
return retVal, err
}
//表示查到了需要把upc更新上去没查到就要新建
if len(skuNames2) == 1 && (productInfo.SpecQuality == skuNames2[0].SpecQuality && productInfo.SpecUnit == skuNames2[0].SpecUnit) {
skuNames2[0].Upc = v.Upc
dao.UpdateEntity(db, skuNames2[0], "Upc")
return retVal, err
} else {
if v.Price == 0 {
result, err := api.AliUpcAPI.GetAliUpcInfo(*v.Upc)
if err != nil {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
return retVal, err
}
if result.Price == "" {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品售价!")}
return retVal, err
} else {
skuName.Price = int(utils.Str2Int64(result.Price) * 100)
}
} else {
skuName.Price = v.Price
}
skuName.Name = productInfo.Name
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(*v.Upc)
if v.Unit != "" {
skuName.Unit = v.Unit
} else {
if productInfo.Unit == "" {
if getNetUpcInfo.Unit != "" {
skuName.Unit = getNetUpcInfo.Unit
} else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品单位,请补充商品单位!")}
return retVal, err
}
} else {
skuName.Unit = productInfo.Unit
}
}
if v.SpecQuality != 0 {
skuName.Skus[0].SpecQuality = v.SpecQuality
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
} else {
_, _, _, specUnit, _, specQuality := jxutils.SplitSkuName(v.Name)
if specQuality != 0 {
skuName.Skus[0].SpecQuality = specQuality
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 = utils.Float32ToInt(specQuality)
}
} else {
if productInfo.SpecQuality == 0 {
if getNetUpcInfo.SpecQuality != 0 {
if getNetUpcInfo.SpecUnit == model.SpecUnitNames[1] || getNetUpcInfo.SpecUnit == model.SpecUnitNames[2] ||
getNetUpcInfo.SpecUnit == "KG" || getNetUpcInfo.SpecUnit == "l" {
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(getNetUpcInfo.SpecQuality) * 1000)))
} else {
skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
}
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
} else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品重量,请补充商品重量!")}
return retVal, err
}
} else {
if productInfo.Weight != 0 {
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
} else {
skuName.Skus[0].Weight = utils.Float32ToInt(v.SpecQuality)
}
skuName.Skus[0].SpecQuality = productInfo.SpecQuality
}
}
if productInfo.SpecUnit == "" {
if getNetUpcInfo.SpecUnit != "" {
skuName.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit
} else {
skuName.Skus[0].SpecUnit = model.SpecUnitNames[0]
}
} else {
skuName.Skus[0].SpecUnit = productInfo.SpecUnit
}
}
if len(productInfo.ImgList) > 0 {
setImgs(skuName, productInfo.ImgList)
} else {
skuName.Img = model.NOSkuNameImg
}
skuName.Skus[0].SpecUnit = productInfo.SpecUnit
}
}
if len(productInfo.ImgList) > 0 {
setImgs(skuName, productInfo.ImgList)
} else {
skuName.Img = model.NOSkuNameImg
}
if skuName.Img == "" {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品图片请联系开发!")}
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "未查询到商品图片请联系开发!")}
return retVal, err
}
suffix := skuName.Img[strings.LastIndex(skuName.Img, "."):]
@@ -2298,19 +2221,6 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
skuName.CategoryID = categoryID
}
skuName.Skus[0].Status = model.SkuStatusNormal
if skuName.Img == model.NOSkuNameImg {
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtwmCookieStr", model.ConfigTypeCookie, ""); err == nil {
api.MtwmAPI.SetCookieWithStr(configs[0].Value)
}
result, _ := api.MtwmAPI.GetStandardProductListWithCond(*skuName.Upc)
if result != nil {
imgs := strings.Split(result.Pic, ",")
setImgs(skuName, imgs)
} else {
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "美团cookie过期了吧")}
return retVal, err
}
}
//需要把图片传到七牛云上, 很难受
if !strings.Contains(skuName.Img, "image.jxc4.com") {
downloadURL, err := uploadImgStandard(skuName.Img)

View File

@@ -1274,7 +1274,6 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
if err != nil || storeDetail == nil {
continue
}
globals.SugarLogger.Debugf("updateStoresSkusWithoutSync, step 0")
if beego.BConfig.RunMode == "prod" || beego.BConfig.RunMode == "beta" {
if len(storeIDs) > 1 {
if storeDetail.StoreLevel == "D" || storeDetail.StoreLevel == "E" {
@@ -1282,12 +1281,10 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
}
}
}
globals.SugarLogger.Debugf("updateStoresSkusWithoutSync, step 1")
scaleFactor := float64(1)
if isScale {
scaleFactor = 100 / float64(jxutils.ConstrainPayPercentage(storeDetail.PayPercentage))
}
globals.SugarLogger.Debugf("updateStoresSkusWithoutSync, step 2")
for _, skuBindInfo := range skuBindInfos {
// 关注且没有给价时需要尝试从store_sku_bind中得到已有的单价
needGetExistingUnitPrice := skuBindInfo.UnitPrice == 0 && skuBindInfo.IsFocus == 1