从银豹上拉标品到京西

This commit is contained in:
苏尹岚
2020-03-31 16:24:17 +08:00
parent 66045a103c
commit 41d957edcc
9 changed files with 224 additions and 24 deletions

View File

@@ -68,8 +68,8 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
if storeSkuList != nil {
if len(storeSkuList) == 1 {
storeSku := storeSkuList[0]
result, err := api.YinBaoAPI.QueryProductByBarcode(utils.Int2Str(storeSku.SkuID))
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(utils.Int2Str(storeSku.SkuID))
result, err := api.YinBaoAPI.QueryProductByBarcode(storeSku.VendorSkuID)
resultp, err := getProductImages(vendorStoreID, storeSku.VendorSkuID)
if err != nil {
return nil, err
}
@@ -79,14 +79,14 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
} else {
var barcodes []string
for _, v := range storeSkuList {
barcodes = append(barcodes, utils.Int2Str(v.SkuID))
barcodes = append(barcodes, v.VendorSkuID)
}
results, err := api.YinBaoAPI.QueryProductByBarcodes(barcodes)
if err != nil {
return nil, err
}
for _, v := range results {
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
resultp, err := getProductImages(vendorStoreID, v.Barcode)
if err != nil {
return nil, err
}
@@ -102,7 +102,7 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
}
if result.PostBackParameter.ParameterType == yinbaoapi.PageMaxID {
for _, v := range result.Result {
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
resultp, err := getProductImages(vendorStoreID, v.Barcode)
if err != nil {
return nil, err
}
@@ -113,12 +113,33 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas
}
}
} else {
loopPages(result.PostBackParameter.ParameterType, result.PostBackParameter.ParameterValue, skuNameList)
loopPages(result.PostBackParameter.ParameterType, result.PostBackParameter.ParameterValue, skuNameList, vendorStoreID)
}
}
return skuNameList, err
}
func getProductImages(vendorStoreID, barCode string) (findProductResult *yinbaoapi.FindProductResult, err error) {
for {
ybSkuID, err := api.YinBaoAPI.LoadProductsByPage(vendorStoreID, barCode)
findProductResult, err = api.YinBaoAPI.FindProduct(ybSkuID)
if err == nil {
break
} else {
if yinbaoapi.IsErrCookie(err) {
err = cms.ChangeYbCookie()
if err != nil {
break
}
findProductResult, err = getProductImages(vendorStoreID, barCode)
} else {
break
}
}
}
return findProductResult, err
}
func (p *PurchaseHandler) UpdateStoreSkusStatus(ctx *jxcontext.Context, vendorOrgCode string, storeID int, vendorStoreID string, storeSkuList []*partner.StoreSkuInfo, status int) (failedList []*partner.StoreSkuInfoWithErr, err error) {
if globals.EnableYbStoreWrite {
for _, v := range storeSkuList {
@@ -322,28 +343,27 @@ func ybSkuStatus2Jx(ybStatus int) (jxSkuStatus int) {
return jxSkuStatus
}
func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp []*yinbaoapi.QueryProductImagesByBarcodeResult) (skuName *partner.SkuNameInfo) {
func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp *yinbaoapi.FindProductResult) (skuName *partner.SkuNameInfo) {
var picList []string
if result == nil {
globals.SugarLogger.Warnf("vendorSku2Jx, strange result:%s", utils.Format4Output(result, true))
return nil
}
if len(resultp) > 0 {
for _, v := range resultp {
picList = append(picList, v.ImageURL)
if len(resultp.Productimages) > 0 {
for _, v := range resultp.Productimages {
picList = append(picList, yinbaoapi.ImageUrl+v.Path)
}
}
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(result.Name)
skuID := int(utils.Str2Int64WithDefault(result.Barcode, 0))
skuName = &partner.SkuNameInfo{
Prefix: prefix,
Name: name,
Unit: unit,
Prefix: prefix,
Name: name,
Unit: unit,
YbBarCode: result.Barcode,
SkuList: []*partner.SkuInfo{
&partner.SkuInfo{
StoreSkuInfo: partner.StoreSkuInfo{
VendorSkuID: utils.Int64ToStr(result.UID),
SkuID: skuID,
Stock: int(utils.Float64TwoInt64(result.Stock)),
VendorPrice: jxutils.StandardPrice2Int(result.SellPrice),
Status: ybSkuStatus2Jx(result.Enable),
@@ -360,7 +380,7 @@ func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp []*yinb
return skuName
}
func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuNameInfo) (err error) {
func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuNameInfo, vendorStoreID string) (err error) {
var postBackParameter = &yinbaoapi.PostBackParameter{
ParameterType: parameterType,
ParameterValue: parameterValue,
@@ -370,7 +390,7 @@ func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuN
return err
}
for _, v := range resultPages.Result {
resultp, err := api.YinBaoAPI.QueryProductImagesByBarcode(v.Barcode)
resultp, err := getProductImages(vendorStoreID, v.Barcode)
if err != nil {
return err
}
@@ -381,7 +401,7 @@ func loopPages(parameterType, parameterValue string, skuNameList []*partner.SkuN
}
}
if resultPages.PostBackParameter.ParameterType != yinbaoapi.PageMaxID {
err = loopPages(resultPages.PostBackParameter.ParameterType, resultPages.PostBackParameter.ParameterValue, skuNameList)
err = loopPages(resultPages.PostBackParameter.ParameterType, resultPages.PostBackParameter.ParameterValue, skuNameList, vendorStoreID)
}
return err
}