- 同步门店商品时,修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
This commit is contained in:
@@ -2,9 +2,10 @@ package cms
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
|
||||||
@@ -215,14 +216,17 @@ func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyn
|
|||||||
func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item *dao.KVUpdateItem) {
|
func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item *dao.KVUpdateItem) {
|
||||||
kvs := map[string]interface{}{}
|
kvs := map[string]interface{}{}
|
||||||
if syncStatus&(model.SyncFlagDeletedMask|model.SyncFlagNewMask|model.SyncFlagModifiedMask) != 0 {
|
if syncStatus&(model.SyncFlagDeletedMask|model.SyncFlagNewMask|model.SyncFlagModifiedMask) != 0 {
|
||||||
sku.StoreSkuSyncStatus = 0
|
|
||||||
if model.IsSyncStatusNew(syncStatus) {
|
if model.IsSyncStatusNew(syncStatus) {
|
||||||
|
sku.StoreSkuSyncStatus = 0
|
||||||
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = utils.Str2Int64WithDefault(sku.VendorSkuID, 0)
|
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = utils.Str2Int64WithDefault(sku.VendorSkuID, 0)
|
||||||
} else if model.IsSyncStatusDelete(syncStatus) {
|
} else if model.IsSyncStatusDelete(syncStatus) {
|
||||||
|
sku.StoreSkuSyncStatus = 0
|
||||||
if utils.IsTimeZero(sku.BindDeletedAt) {
|
if utils.IsTimeZero(sku.BindDeletedAt) {
|
||||||
kvs[model.FieldDeletedAt] = time.Now()
|
kvs[model.FieldDeletedAt] = time.Now()
|
||||||
}
|
}
|
||||||
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = 0
|
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = 0
|
||||||
|
} else {
|
||||||
|
sku.StoreSkuSyncStatus = sku.StoreSkuSyncStatus & model.SyncFlagPriceMask
|
||||||
}
|
}
|
||||||
} else if syncStatus&model.SyncFlagStockMask != 0 {
|
} else if syncStatus&model.SyncFlagStockMask != 0 {
|
||||||
if isStoreSkuSyncNeedDelete(sku) {
|
if isStoreSkuSyncNeedDelete(sku) {
|
||||||
@@ -334,13 +338,17 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
|||||||
}
|
}
|
||||||
parentTask.AddBatchErr(err)
|
parentTask.AddBatchErr(err)
|
||||||
} else {
|
} else {
|
||||||
|
isAdded2Update := false
|
||||||
|
// 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
|
||||||
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler != nil {
|
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler != nil {
|
||||||
|
isAdded2Update = true
|
||||||
updateList = append(updateList, calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
updateList = append(updateList, calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
||||||
} else {
|
}
|
||||||
if model.IsSyncStatusPrice(sku.StoreSkuSyncStatus) {
|
if model.IsSyncStatusPrice(sku.StoreSkuSyncStatus) {
|
||||||
bareSku = storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
bareSku = storeSkuSyncInfo2Bare(calVendorPrice4StoreSku(sku, storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage)))
|
||||||
priceList = append(priceList, bareSku)
|
priceList = append(priceList, bareSku)
|
||||||
}
|
}
|
||||||
|
if !isAdded2Update {
|
||||||
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler == nil { // 正常就不应该进到这里
|
if model.IsSyncStatusUpdate(sku.StoreSkuSyncStatus) && singleStoreHandler == nil { // 正常就不应该进到这里
|
||||||
if bareSku == nil {
|
if bareSku == nil {
|
||||||
bareSku = storeSkuSyncInfo2Bare(sku)
|
bareSku = storeSkuSyncInfo2Bare(sku)
|
||||||
@@ -652,4 +660,4 @@ func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package ebai
|
package ebai
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
@@ -109,7 +110,7 @@ func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
storeSku := storeSkuList[0]
|
storeSku := storeSkuList[0]
|
||||||
strStoreID := utils.Int2Str(storeID)
|
strStoreID := utils.Int2Str(storeID)
|
||||||
if globals.EnableEbaiStoreWrite {
|
if globals.EnableEbaiStoreWrite {
|
||||||
_, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, utils.Str2Int64(storeSku.VendorSkuID), genSkuParamsFromStoreSkuInfo2(storeSku))
|
_, err = api.EbaiAPI.SkuUpdate(ctx.GetTrackInfo(), strStoreID, utils.Str2Int64(storeSku.VendorSkuID), genSkuParamsFromStoreSkuInfo2(storeSku, false))
|
||||||
utils.CallFuncAsync(func() {
|
utils.CallFuncAsync(func() {
|
||||||
api.EbaiAPI.SkuShopCategoryMap(strStoreID, utils.Str2Int64(storeSku.VendorSkuID), "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
|
api.EbaiAPI.SkuShopCategoryMap(strStoreID, utils.Str2Int64(storeSku.VendorSkuID), "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
|
||||||
})
|
})
|
||||||
@@ -123,7 +124,7 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
var vendorSkuID int64
|
var vendorSkuID int64
|
||||||
if globals.EnableEbaiStoreWrite {
|
if globals.EnableEbaiStoreWrite {
|
||||||
strStoreID := utils.Int2Str(storeID)
|
strStoreID := utils.Int2Str(storeID)
|
||||||
if vendorSkuID, err = api.EbaiAPI.SkuCreate(ctx.GetTrackInfo(), strStoreID, storeSku.SkuID, genSkuParamsFromStoreSkuInfo2(storeSku)); err == nil {
|
if vendorSkuID, err = api.EbaiAPI.SkuCreate(ctx.GetTrackInfo(), strStoreID, storeSku.SkuID, genSkuParamsFromStoreSkuInfo2(storeSku, true)); err == nil {
|
||||||
utils.AfterFuncWithRecover(5*time.Second, func() {
|
utils.AfterFuncWithRecover(5*time.Second, func() {
|
||||||
api.EbaiAPI.SkuShopCategoryMap(strStoreID, vendorSkuID, "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
|
api.EbaiAPI.SkuShopCategoryMap(strStoreID, vendorSkuID, "", utils.Str2Int64(storeSku.VendorCatID), genSkuCatRank(storeSku))
|
||||||
})
|
})
|
||||||
@@ -223,7 +224,7 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, storeID i
|
|||||||
return successList, err
|
return successList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[string]interface{}) {
|
func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo, isCreate bool) (params map[string]interface{}) {
|
||||||
params = map[string]interface{}{
|
params = map[string]interface{}{
|
||||||
"name": utils.LimitMixedStringLen(storeSku.SkuName, ebaiapi.MaxSkuNameByteCount),
|
"name": utils.LimitMixedStringLen(storeSku.SkuName, ebaiapi.MaxSkuNameByteCount),
|
||||||
"left_num": model.MaxStoreSkuStockQty,
|
"left_num": model.MaxStoreSkuStockQty,
|
||||||
@@ -243,7 +244,7 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[s
|
|||||||
if storeSku.DescImg != "" {
|
if storeSku.DescImg != "" {
|
||||||
params["rtf"] = storeSku.DescImg
|
params["rtf"] = storeSku.DescImg
|
||||||
}
|
}
|
||||||
if storeSku.StoreSkuSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 {
|
if isCreate /*storeSku.StoreSkuSyncStatus&(model.SyncFlagPriceMask| model.SyncFlagNewMask) != 0 */ {
|
||||||
params["sale_price"] = storeSku.VendorPrice
|
params["sale_price"] = storeSku.VendorPrice
|
||||||
}
|
}
|
||||||
if storeSku.StoreSkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 {
|
if storeSku.StoreSkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 {
|
||||||
@@ -391,4 +392,4 @@ func vendorSkuList2Jx(vendorSkuList []*ebaiapi.SkuInfo) (skuNameList []*partner.
|
|||||||
|
|
||||||
func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp {
|
func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp {
|
||||||
return sensitiveWordRegexp
|
return sensitiveWordRegexp
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package mtwm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
@@ -134,13 +135,18 @@ func (p *PurchaseHandler) IsErrSkuNotExist(err error) (isNotExist bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) {
|
func (p *PurchaseHandler) UpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) {
|
||||||
return p.CreateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList)
|
return p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) {
|
||||||
|
return p.createOrUpdateStoreSkus(ctx, storeID, vendorStoreID, storeSkuList, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义
|
// 对于多门店平台来说,storeSkuList中只有SkuID与VendorSkuID有意义
|
||||||
func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo) (successList []*dao.StoreSkuSyncInfo, err error) {
|
func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeSkuList []*dao.StoreSkuSyncInfo, isCreate bool) (successList []*dao.StoreSkuSyncInfo, err error) {
|
||||||
foodDataList := make([]map[string]interface{}, len(storeSkuList))
|
foodDataList := make([]map[string]interface{}, len(storeSkuList))
|
||||||
for i, storeSku := range storeSkuList {
|
for i, storeSku := range storeSkuList {
|
||||||
|
isNeedUpdatePrice := isCreate //storeSku.StoreSkuSyncStatus&( model.SyncFlagPriceMask| model.SyncFlagNewMask) != 0
|
||||||
foodData := make(map[string]interface{})
|
foodData := make(map[string]interface{})
|
||||||
foodDataList[i] = foodData
|
foodDataList[i] = foodData
|
||||||
foodData[mtwmapi.KeyAppFoodCode] = utils.Int2Str(storeSku.SkuID)
|
foodData[mtwmapi.KeyAppFoodCode] = utils.Int2Str(storeSku.SkuID)
|
||||||
@@ -152,7 +158,9 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
foodData["skus"] = skus
|
foodData["skus"] = skus
|
||||||
foodData["name"] = utils.LimitUTF8StringLen(storeSku.SkuName, mtwmapi.MaxSkuNameCharCount)
|
foodData["name"] = utils.LimitUTF8StringLen(storeSku.SkuName, mtwmapi.MaxSkuNameCharCount)
|
||||||
foodData["description"] = storeSku.Comment
|
foodData["description"] = storeSku.Comment
|
||||||
foodData["price"] = jxutils.IntPrice2Standard(storeSku.VendorPrice)
|
if isNeedUpdatePrice {
|
||||||
|
foodData["price"] = jxutils.IntPrice2Standard(storeSku.VendorPrice)
|
||||||
|
}
|
||||||
foodData["min_order_count"] = 1
|
foodData["min_order_count"] = 1
|
||||||
foodData["unit"] = storeSku.Unit
|
foodData["unit"] = storeSku.Unit
|
||||||
foodData["box_num"] = 0
|
foodData["box_num"] = 0
|
||||||
@@ -170,7 +178,9 @@ func (p *PurchaseHandler) CreateStoreSkus(ctx *jxcontext.Context, storeID int, v
|
|||||||
// foodData["tag_id"] = utils.Int64ToStr(defVendorCatID)
|
// foodData["tag_id"] = utils.Int64ToStr(defVendorCatID)
|
||||||
}
|
}
|
||||||
skus[0]["spec"] = jxutils.ComposeSkuSpec(storeSku.SpecQuality, storeSku.SpecUnit)
|
skus[0]["spec"] = jxutils.ComposeSkuSpec(storeSku.SpecQuality, storeSku.SpecUnit)
|
||||||
skus[0]["price"] = foodData["price"]
|
if isNeedUpdatePrice {
|
||||||
|
skus[0]["price"] = foodData["price"]
|
||||||
|
}
|
||||||
skus[0]["stock"] = stockCount2Mtwm(model.MaxStoreSkuStockQty)
|
skus[0]["stock"] = stockCount2Mtwm(model.MaxStoreSkuStockQty)
|
||||||
skus[0]["upc"] = storeSku.Upc
|
skus[0]["upc"] = storeSku.Upc
|
||||||
if foodData["tag_id"] != nil {
|
if foodData["tag_id"] != nil {
|
||||||
@@ -373,4 +383,4 @@ func vendorSkuList2Jx(appFoodList []*mtwmapi.AppFood) (skuNameList []*partner.Sk
|
|||||||
|
|
||||||
func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp {
|
func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp {
|
||||||
return sensitiveWordRegexp
|
return sensitiveWordRegexp
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user