根据excel创建标品优化

This commit is contained in:
苏尹岚
2020-04-09 08:58:42 +08:00
parent 2a0f6fafe7
commit 649e7a98da

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"mime/multipart"
"regexp"
"strconv"
"strings"
"time"
@@ -1759,10 +1760,11 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
"商品条码",
"商品名称",
"单位",
"规格",
"重量(g)",
"售价",
"错误原因",
}
upcRegexp = regexp.MustCompile(`/^\d{12,13}$/`)
)
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
@@ -1799,7 +1801,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
specQuality = float32(utils.Str2Float64(cell))
}
if k == 4 {
price = int(utils.Str2Float64(cell) * 100)
price = int(utils.Str2Float64(cell))
}
}
}
@@ -1821,9 +1823,15 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
},
}
if v.Upc != nil {
upc := upcRegexp.FindString(*v.Upc)
if upc == "" {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "请输入正确的商品条码!"))
continue
}
skuName.Upc = v.Upc
} else {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品的条码不能为空!"))
continue
}
skuNames, _ := dao.GetSkuNames(db, nil, []string{*v.Upc}, "")
if len(skuNames) > 0 {
@@ -1838,7 +1846,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
if len(productInfos) == 0 {
result, _ := api.AliUpcAPI.GetAliUpcInfo(*v.Upc)
if result == nil {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "暂不支持创建此商品"))
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "未在标品库查到此商品,请手动创建"))
continue
}
if result.Img != "" {
@@ -1870,7 +1878,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
}
if v.Price == 0 {
if result.Price == "" {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品的售价不能为空"))
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品的售价!"))
continue
} else {
skuName.Price = int(utils.Str2Int64(result.Price) * 100)
@@ -1881,14 +1889,14 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
if v.Unit != "" {
skuName.Unit = v.Unit
} else {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品的单位不能为空"))
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "未查询到商品单位,请补充商品单位"))
continue
}
if v.SpecQuality != 0 {
skuName.Skus[0].SpecQuality = v.SpecQuality
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(v.SpecQuality))))
} else {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品的重量不能为空"))
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "未查询到商品重量,请补充商品重量"))
continue
}
skuName.Skus[0].SpecUnit = model.SpecialSpecUnit
@@ -1911,7 +1919,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader) (err error
continue
}
if result.Price == "" {
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "商品的售价不能为空"))
createUpcSkuByExcelErrList = append(createUpcSkuByExcelErrList, buildCreateUpcSkuByExcelErr(v, "未查询到商品售价,请补充商品售价"))
continue
} else {
skuName.Price = int(utils.Str2Int64(result.Price) * 100)