同步银豹到京西商品,测试list
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -13,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/aliupcapi"
|
"git.rosy.net.cn/baseapi/platformapi/aliupcapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
"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/api"
|
||||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
"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/baseapi/utils/errlist"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/datares"
|
"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 {
|
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(math.Round(float64(v.SpecQuality)))))
|
skuName.Skus[0].Weight = utils.Float32ToInt(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)
|
||||||
@@ -1985,7 +1984,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(math.Round(float64(specQuality)))))
|
skuName.Skus[0].Weight = utils.Float32ToInt(specQuality)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if getNetUpcInfo.SpecQuality != 0 {
|
if getNetUpcInfo.SpecQuality != 0 {
|
||||||
@@ -1993,7 +1992,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(math.Round(float64(specQuality)))))
|
skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
|
||||||
}
|
}
|
||||||
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||||
} else {
|
} else {
|
||||||
@@ -2061,7 +2060,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 = utils.Float32ToInt(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)
|
||||||
@@ -2070,7 +2069,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 = utils.Float32ToInt(specQuality)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if productInfo.SpecQuality == 0 {
|
if productInfo.SpecQuality == 0 {
|
||||||
@@ -2079,7 +2078,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(getNetUpcInfo.SpecQuality))))
|
skuName.Skus[0].Weight = utils.Float32ToInt(getNetUpcInfo.SpecQuality)
|
||||||
}
|
}
|
||||||
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
skuName.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||||
} else {
|
} else {
|
||||||
@@ -2090,7 +2089,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
|||||||
if productInfo.Weight != 0 {
|
if productInfo.Weight != 0 {
|
||||||
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
skuName.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
||||||
} else {
|
} 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
|
skuName.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||||
}
|
}
|
||||||
@@ -2168,11 +2167,6 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
|||||||
skuName.CategoryID = categoryID
|
skuName.CategoryID = categoryID
|
||||||
}
|
}
|
||||||
skuName.Skus[0].Status = model.SkuStatusNormal
|
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())
|
_, err = AddSkuName(ctx, skuName, ctx.GetUserName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||||
@@ -2326,8 +2320,8 @@ func AddSkuNameByUpc(ctx *jxcontext.Context, upc string, store *dao.StoreDetail,
|
|||||||
}
|
}
|
||||||
//我们商品库中有这个商品,但是upc没有填,则尝试用upc去查一下
|
//我们商品库中有这个商品,但是upc没有填,则尝试用upc去查一下
|
||||||
productInfos, err2 := GetJdUpcCodeByName(ctx, "", upc)
|
productInfos, err2 := GetJdUpcCodeByName(ctx, "", upc)
|
||||||
|
getNetUpcInfo, err2 := api.AliUpcAPI.GetNetUpcInfo(upc)
|
||||||
err = err2
|
err = err2
|
||||||
getNetUpcInfo, err := api.AliUpcAPI.GetNetUpcInfo(upc)
|
|
||||||
//表示用upc也没有找到这个商品
|
//表示用upc也没有找到这个商品
|
||||||
if len(productInfos) == 0 {
|
if len(productInfos) == 0 {
|
||||||
if getNetUpcInfo == nil || getNetUpcInfo.SpecQuality == 0 || getNetUpcInfo.Unit == "" {
|
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 {
|
if len(v.PictureList) > 0 {
|
||||||
skuNameExt.Img = v.PictureList[0]
|
skuNameExt.Img = v.PictureList[0]
|
||||||
} else {
|
} else {
|
||||||
var result *aliupcapi.GetAliUpcInfoResult
|
img := getImgFromNet(db, upc)
|
||||||
upcDepot, err := dao.GetUpcDepot(db, upc)
|
if img != "" {
|
||||||
if upcDepot == nil {
|
skuNameExt.Img = img
|
||||||
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 {
|
} else {
|
||||||
skuNameExt.Img = model.NOSkuNameImg
|
skuNameExt.Img = model.NOSkuNameImg
|
||||||
}
|
}
|
||||||
@@ -2356,40 +2341,95 @@ func AddSkuNameByUpc(ctx *jxcontext.Context, upc string, store *dao.StoreDetail,
|
|||||||
skuNameExt.Unit = getNetUpcInfo.Unit
|
skuNameExt.Unit = getNetUpcInfo.Unit
|
||||||
skuNameExt.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
skuNameExt.Skus[0].SpecQuality = getNetUpcInfo.SpecQuality
|
||||||
skuNameExt.Skus[0].SpecUnit = getNetUpcInfo.SpecUnit
|
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 {
|
} else {
|
||||||
productInfo := productInfos[0]
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(skuNames2) > 1 {
|
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, outSkuNameExt.ID)
|
||||||
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 {
|
} else {
|
||||||
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames[0].ID)
|
buildStoreSkuBindInfosAndFocus(ctx, db, store, v, skuNames[0].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -916,12 +916,13 @@ func syncStoreSkusFromYb(ctx *jxcontext.Context, storeID, vendorID int, vendorSt
|
|||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
localSkuMap = make(map[string]*dao.StoreSkuSyncInfo)
|
localSkuMap = make(map[string]*dao.StoreSkuSyncInfo)
|
||||||
vendorSkuMap = make(map[string]*partner.SkuNameInfo)
|
vendorSkuMap = make(map[string]*partner.SkuNameInfo)
|
||||||
addList []*partner.SkuNameInfo
|
// skuBindInfosDel []*StoreSkuBindInfo
|
||||||
updateList []*partner.SkuNameInfo
|
// skuBindInfosUpt []*StoreSkuBindInfo
|
||||||
deleteList []*dao.StoreSkuSyncInfo
|
addList []*partner.SkuNameInfo
|
||||||
|
updateList []*partner.SkuNameInfo
|
||||||
|
deleteList []*dao.StoreSkuSyncInfo
|
||||||
)
|
)
|
||||||
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||||
store, _ := dao.GetStoreDetail(db, storeID, vendorID)
|
|
||||||
|
|
||||||
localSkuList, err := dao.GetStoreSkus2(db, vendorID, storeID, nil, false)
|
localSkuList, err := dao.GetStoreSkus2(db, vendorID, storeID, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -949,31 +950,97 @@ func syncStoreSkusFromYb(ctx *jxcontext.Context, storeID, vendorID int, vendorSt
|
|||||||
deleteList = append(deleteList, v)
|
deleteList = append(deleteList, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
fmt.Println("test111111111111111", storeID, vendorStoreID)
|
||||||
switch step {
|
fmt.Println("addList", utils.Format4Output(addList, false))
|
||||||
case 0:
|
fmt.Println("updateList", utils.Format4Output(updateList, false))
|
||||||
if len(addList) > 0 {
|
fmt.Println("deleteList", utils.Format4Output(deleteList, false))
|
||||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
// taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {\
|
||||||
var (
|
// store, _ := dao.GetStoreDetail(db, storeID, vendorID)
|
||||||
v = batchItemList[0].(*partner.SkuNameInfo)
|
// switch step {
|
||||||
upc = v.YbBarCode
|
// case 0:
|
||||||
)
|
// if len(addList) > 0 {
|
||||||
err = AddSkuNameByUpc(ctx, upc, store, v)
|
// taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
if err != nil {
|
// var (
|
||||||
task.AddFailedList(putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorChineseNames[vendorID], "根据upc创建京西商品"))
|
// v = batchItemList[0].(*partner.SkuNameInfo)
|
||||||
}
|
// upc = v.YbBarCode
|
||||||
return retVal, err
|
// )
|
||||||
}
|
// err = AddSkuNameByUpc(ctx, upc, store, v)
|
||||||
taskParallel := tasksch.NewParallelTask("创建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, taskFunc, addList)
|
// if err != nil {
|
||||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
// task.AddFailedList(putils.GetErrMsg2FailedSingleList(nil, err, storeID, model.VendorChineseNames[vendorID], "根据upc创建京西商品"))
|
||||||
_, err = taskParallel.GetResult(0)
|
// }
|
||||||
}
|
// return retVal, err
|
||||||
case 1:
|
// }
|
||||||
}
|
// taskParallel := tasksch.NewParallelTask("创建商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, taskFunc, addList)
|
||||||
return result, err
|
// tasksch.HandleTask(taskParallel, task, true).Run()
|
||||||
}
|
// _, err = taskParallel.GetResult(0)
|
||||||
taskSeq := tasksch.NewSeqTask2("同步银豹商品到京西", ctx, true, taskSeqFunc, 3)
|
// }
|
||||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
// case 1:
|
||||||
hint = taskSeq.GetID()
|
// if len(deleteList) > 0 {
|
||||||
|
// taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
// var (
|
||||||
|
// v = batchItemList[0].(*dao.StoreSkuSyncInfo)
|
||||||
|
// )
|
||||||
|
// skuBindInfo := &StoreSkuBindInfo{
|
||||||
|
// NameID: v.NameID,
|
||||||
|
// IsFocus: -1,
|
||||||
|
// }
|
||||||
|
// retVal = []*StoreSkuBindInfo{skuBindInfo}
|
||||||
|
// return retVal, err
|
||||||
|
// }
|
||||||
|
// taskParallel := tasksch.NewParallelTask("删除商品", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, taskFunc, deleteList)
|
||||||
|
// tasksch.HandleTask(taskParallel, task, true).Run()
|
||||||
|
// resultDel, _ := taskParallel.GetResult(0)
|
||||||
|
// for _, v := range resultDel {
|
||||||
|
// skuBindInfosDel = append(skuBindInfosDel, v.(*StoreSkuBindInfo))
|
||||||
|
// }
|
||||||
|
// _, err = updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosDel, false)
|
||||||
|
// }
|
||||||
|
// case 2:
|
||||||
|
// if len(updateList) > 0 {
|
||||||
|
// taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
// var (
|
||||||
|
// v = batchItemList[0].(*partner.SkuNameInfo)
|
||||||
|
// skuBindInfo = &StoreSkuBindInfo{}
|
||||||
|
// storeSkus []*dao.StoreSkuExt
|
||||||
|
// pricePercentagePack []*model.PricePercentageItem
|
||||||
|
// )
|
||||||
|
// sql := `
|
||||||
|
// SELECT a.*, c.id name_id
|
||||||
|
// FROM store_sku_bind a
|
||||||
|
// JOIN sku b ON a.sku_id = b.id
|
||||||
|
// JOIN sku_name c ON c.id = b.name_id
|
||||||
|
// WHERE a.store_id = ? AND a.yb_id = ? AND a.deleted_at = ?
|
||||||
|
// `
|
||||||
|
// sqlParams := []interface{}{storeID, v.SkuList[0].VendorSkuID, utils.DefaultTimeValue}
|
||||||
|
// err = dao.GetRows(db, &storeSkus, sql, sqlParams)
|
||||||
|
// if len(storeSkus) > 0 {
|
||||||
|
// if storeSkus[0].YbPrice != int(v.SkuList[0].VendorPrice) {
|
||||||
|
// err = jxutils.Strings2Objs(store.PricePercentagePackStr, &pricePercentagePack)
|
||||||
|
// skuBindInfo.UnitPrice = jxutils.CaculateJxPriceByPricePack(pricePercentagePack, 0, int(v.SkuList[0].VendorPrice))
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// return retVal, fmt.Errorf("未查询到门店商品,yb_id [%v]", v.SkuList[0].VendorSkuID)
|
||||||
|
// }
|
||||||
|
// if v.SkuList[0].Stock < 1 {
|
||||||
|
// skuBindInfo.IsSale = model.DISABLED
|
||||||
|
// }
|
||||||
|
// skuBindInfo.NameID = storeSkus[0].NameID
|
||||||
|
// retVal = []*StoreSkuBindInfo{skuBindInfo}
|
||||||
|
// return retVal, err
|
||||||
|
// }
|
||||||
|
// taskParallel := tasksch.NewParallelTask("更新商品价格和库存", tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, taskFunc, deleteList)
|
||||||
|
// tasksch.HandleTask(taskParallel, task, true).Run()
|
||||||
|
// resultUpt, _ := taskParallel.GetResult(0)
|
||||||
|
// for _, v := range resultUpt {
|
||||||
|
// skuBindInfosUpt = append(skuBindInfosUpt, v.(*StoreSkuBindInfo))
|
||||||
|
// }
|
||||||
|
// _, err = updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosUpt, false)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return result, err
|
||||||
|
// }
|
||||||
|
// taskSeq := tasksch.NewSeqTask2("同步银豹商品到京西", ctx, true, taskSeqFunc, 3)
|
||||||
|
// tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||||
|
// hint = taskSeq.GetID()
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -347,3 +347,22 @@ func (c *SyncController) UploadFakeJdThingMap() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 同步银豹到京西商品
|
||||||
|
// @Description 同步银豹到京西商品
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeIDs formData string true "门店ID列表"
|
||||||
|
// @Param isAsync formData bool true "是否异步操作"
|
||||||
|
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /SyncStoreSkusFromYb [put]
|
||||||
|
func (c *SyncController) SyncStoreSkusFromYb() {
|
||||||
|
c.callSyncStoreSkusFromYb(func(params *tSyncSyncStoreSkusFromYbParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var storeIDs []int
|
||||||
|
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err == nil {
|
||||||
|
cms.CurVendorSync.SyncStoreSkusFromYb(params.Ctx, storeIDs, params.IsAsync, params.IsContinueWhenError)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -2223,6 +2223,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "SyncStoreSkusFromYb",
|
||||||
|
Router: `/SyncStoreSkusFromYb`,
|
||||||
|
AllowHTTPMethods: []string{"put"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:SyncController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "SyncStores",
|
Method: "SyncStores",
|
||||||
|
|||||||
Reference in New Issue
Block a user