tijiao
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
const (
|
||||
DefActSkuStock = 200 // 缺省活动库存
|
||||
|
||||
maxDiscount4SkuSecKill = 99
|
||||
maxDiscount4SkuSecKill = 80
|
||||
minDiscount4SkuDirectDown = 0
|
||||
)
|
||||
|
||||
|
||||
@@ -298,14 +298,22 @@ func CompareJxAndVendor(vendorID int, storeIDStr, vendorStoreID, storeName strin
|
||||
}
|
||||
}
|
||||
for skuID, vendorSkuInfo := range filterVendorSkuInfoMap {
|
||||
skuIDStr := utils.Int2Str(skuID)
|
||||
vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName
|
||||
vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status)
|
||||
if vendorSkuInfo != nil {
|
||||
if len(vendorSkuInfo.SkuList) > 0 {
|
||||
skuIDStr := utils.Int2Str(skuID)
|
||||
vendorSkuDetailName := vendorSkuInfo.SkuList[0].SkuName
|
||||
vendorSkuSaleStatusName := GetSkuSaleStatusName(vendorSkuInfo.SkuList[0].Status)
|
||||
|
||||
jxSkuInfo := filterJxSkuInfoMap[skuID]
|
||||
if jxSkuInfo == nil {
|
||||
outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName, DatAanalyse1}
|
||||
diffData.AppendData(vendorID, outPutData)
|
||||
jxSkuInfo := filterJxSkuInfoMap[skuID]
|
||||
if jxSkuInfo == nil {
|
||||
outPutData := DiffData{storeIDStr, vendorStoreID, storeName, skuIDStr, "", "", "", "", vendorSkuDetailName, "", vendorSkuSaleStatusName, DatAanalyse1}
|
||||
diffData.AppendData(vendorID, outPutData)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("CompareJxAndVendor vendorSkuInfo.SkuList:%d is nil", skuID)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("CompareJxAndVendor skuID:%d is nil", skuID)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -364,7 +372,7 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int,
|
||||
allSkuInfoList := GetMultiStoreAllSkuInfoList(vendorID)
|
||||
skuBareInfoList, err := singleStoreHandler.GetStoreSkusBareInfo(ctx, task, storeID, vendorStoreID, allSkuInfoList)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err)
|
||||
baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusBareInfo error:%v", err)
|
||||
} else if len(skuBareInfoList) > 0 {
|
||||
filterSkuInfoMap := GetFilterMultiStoreSkuInfoMap(vendorID, skuBareInfoList) //map[京东商品ID:SkuNameInfo]
|
||||
CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterSkuInfoMap)
|
||||
@@ -373,7 +381,7 @@ func CheckSkuDiffBetweenJxAndVendor(ctx *jxcontext.Context, vendorIDList []int,
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
vendorSkuInfoList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err)
|
||||
baseapi.SugarLogger.Infof("CheckSkuDiffBetweenJxAndVendor GetStoreSkusFullInfo error:%v", err)
|
||||
} else if len(vendorSkuInfoList) > 0 {
|
||||
filterVendorSkuInfoMap := GetFilterVendorSkuInfoMap(vendorSkuInfoList) //map[平台商品ID:SkuNameInfo]
|
||||
CompareJxAndVendor(vendorID, storeIDStr, vendorStoreID, storeName, filterJxSkuInfoMap, filterVendorSkuInfoMap)
|
||||
|
||||
@@ -232,7 +232,7 @@ func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuI
|
||||
|
||||
func (v *VendorSync) SyncSkus(ctx *jxcontext.Context, db *dao.DaoDB, nameIDs []int, skuIDs []int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncSku trackInfo:%s, nameIDs:%v, skuIDs:%v, userName:%s", ctx.GetTrackInfo(), nameIDs, skuIDs, userName)
|
||||
isManagedIt := len(nameIDs) > 1 || len(nameIDs) == 0 || len(skuIDs) > 1 || len(skuIDs) == 0
|
||||
isManagedIt := !(len(nameIDs) > 0 && len(nameIDs) <= 2 || len(skuIDs) > 0 && len(skuIDs) < 8)
|
||||
return v.LoopMultiStoresVendors(ctx, db, fmt.Sprintf("同步商品信息, nameIDs:%v, skuIDs:%v", nameIDs, skuIDs), isAsync, isManagedIt,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
var resultList []interface{}
|
||||
@@ -358,7 +358,7 @@ func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, v
|
||||
}
|
||||
|
||||
//
|
||||
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debug("SyncStoresSkus2")
|
||||
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
|
||||
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs,
|
||||
@@ -373,11 +373,13 @@ func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vend
|
||||
tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if setSyncStatus != 0 {
|
||||
dao.SetStoreSkuSyncStatus(db, storeMap.VendorID, []int{storeMap.StoreID}, skuIDs, setSyncStatus)
|
||||
}
|
||||
if _, err = v.proxySyncStoreSku(ctx, task, storeMap, nil, skuIDs, excludeSkuIDs, false, isContinueWhenError); err != nil {
|
||||
globals.SugarLogger.Debugf("SyncStoresSkus2 failed2 store:%d failed with error:%v", storeMap.StoreID, err)
|
||||
if syncDisabled || storeMap.Status > model.StoreStatusDisabled {
|
||||
if setSyncStatus != 0 {
|
||||
dao.SetStoreSkuSyncStatus(db, storeMap.VendorID, []int{storeMap.StoreID}, skuIDs, setSyncStatus)
|
||||
}
|
||||
if _, err = v.proxySyncStoreSku(ctx, task, storeMap, nil, skuIDs, excludeSkuIDs, false, isContinueWhenError); err != nil {
|
||||
globals.SugarLogger.Debugf("SyncStoresSkus2 failed2 store:%d failed with error:%v", storeMap.StoreID, err)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, loopMapInfo.StoreMapList)
|
||||
@@ -387,18 +389,6 @@ func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vend
|
||||
return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID)
|
||||
}, isContinueWhenError)
|
||||
if task != nil {
|
||||
// if vendorErr := partner.IsErrChangePriceFailed(task.GetOriginalErr()); vendorErr != nil {
|
||||
// platformList := make([]string, len(task.GetDetailErrList()))
|
||||
// for k, v := range task.GetDetailErrList() {
|
||||
// if vendorErr := partner.IsErrVendorError(v); vendorErr != nil {
|
||||
// platformList[k] = model.VendorChineseNames[vendorErr.VendorID()]
|
||||
// } else {
|
||||
// platformList[k] = "未知"
|
||||
// }
|
||||
// }
|
||||
// err = fmt.Errorf("同步价格失败\n失败平台:%s", strings.Join(platformList, ","))
|
||||
// } else {
|
||||
// }
|
||||
err = makeSyncError(err)
|
||||
}
|
||||
return hint, err
|
||||
@@ -409,36 +399,22 @@ func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendo
|
||||
if isForce {
|
||||
setSyncStatus = model.SyncFlagStoreSkuModifiedMask
|
||||
}
|
||||
return v.SyncStoresSkus2(ctx, db, vendorIDs, storeIDs, skuIDs, nil, setSyncStatus, isAsync, isContinueWhenError)
|
||||
return v.SyncStoresSkus2(ctx, db, vendorIDs, storeIDs, true, skuIDs, nil, setSyncStatus, isAsync, isContinueWhenError)
|
||||
}
|
||||
|
||||
// func isUseOldSyncLogic(storeMap *model.StoreMap) bool {
|
||||
// return false
|
||||
// return globals.IsProductEnv() && storeMap.StoreID != 102652 // 绿城四季鲜店
|
||||
// }
|
||||
|
||||
func (v *VendorSync) proxySyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, nameIDs, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// if isUseOldSyncLogic(storeMap) {
|
||||
// return v.GetStoreHandler(storeMap.VendorID).(partner.ISingleStoreHandler).SyncStoreCategory(ctx, parentTask, storeMap.StoreID, isAsync)
|
||||
// }
|
||||
return SyncStorCategories(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, nil, skuIDs, isAsync, isContinueWhenError)
|
||||
}
|
||||
|
||||
func (v *VendorSync) proxySyncStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, nameIDs, skuIDs, excludeSkuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// if isUseOldSyncLogic(storeMap) {
|
||||
// return v.GetStoreHandler(storeMap.VendorID).SyncStoreSkus(ctx, parentTask, storeMap.StoreID, skuIDs, isAsync, isContinueWhenError)
|
||||
// }
|
||||
return SyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, nil, skuIDs, excludeSkuIDs, isAsync, isContinueWhenError)
|
||||
}
|
||||
|
||||
func (v *VendorSync) proxyFullSyncStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// if isUseOldSyncLogic(storeMap) {
|
||||
// return v.GetStoreHandler(storeMap.VendorID).FullSyncStoreSkus(ctx, parentTask, storeMap.StoreID, isAsync, isContinueWhenError)
|
||||
// }
|
||||
return FullSyncStoreSkuNew(ctx, parentTask, storeMap.VendorID, storeMap.StoreID, storeMap.VendorStoreID, isAsync, isContinueWhenError)
|
||||
}
|
||||
|
||||
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debug("FullSyncStoresSkus")
|
||||
hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("初始化门店商品信息:%v", storeIDs), isAsync, true, vendorIDs, storeIDs,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
@@ -452,8 +428,10 @@ func (v *VendorSync) FullSyncStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, v
|
||||
tasksch.NewParallelConfig().SetParallelCount(parallelCount).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
if _, err = v.proxyFullSyncStoreSku(ctx, task, storeMap, false, isContinueWhenError); err != nil {
|
||||
globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err)
|
||||
if syncDisabled || storeMap.Status > model.StoreStatusDisabled {
|
||||
if _, err = v.proxyFullSyncStoreSku(ctx, task, storeMap, false, isContinueWhenError); err != nil {
|
||||
globals.SugarLogger.Debugf("FullSyncStoresSkus failed2 store:%d failed with error:%v", storeMap.StoreID, err)
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}, loopMapInfo.StoreMapList)
|
||||
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
AmmendPruneOnlyAmend = 1
|
||||
AmmendPruneOnlyPrune = 2
|
||||
AmmendPruneAll = 3
|
||||
AmendPruneOnlyAmend = 1
|
||||
AmendPruneOnlyPrune = 2
|
||||
AmendPruneAll = 3
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -82,7 +82,7 @@ func SyncStorCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
|
||||
storeCatMap.ID = catInfo.MapID
|
||||
if model.IsSyncStatusDelete(catInfo.StoreCatSyncStatus) { // 删除
|
||||
if model.IsSyncStatusDelete(catInfo.StoreCatSyncStatus) && !dao.IsVendorThingIDEmpty(catInfo.VendorCatID) {
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID)
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, catInfo.VendorCatID, level)
|
||||
if err != nil && handler.IsErrCategoryNotExist(err) {
|
||||
err = nil
|
||||
}
|
||||
@@ -97,6 +97,10 @@ func SyncStorCategories(ctx *jxcontext.Context, parentTask tasksch.ITask, vendor
|
||||
}
|
||||
if err == nil {
|
||||
updateFields = append(updateFields, idFieldName)
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
storeCatMap.LastOperator = utils.Time2Str(time.Now())
|
||||
updateFields = append(updateFields, model.FieldLastOperator)
|
||||
}
|
||||
}
|
||||
} else if model.IsSyncStatusUpdate(catInfo.StoreCatSyncStatus) { // 修改
|
||||
if err = handler.UpdateStoreCategory(ctx, storeID, vendorStoreID, catInfo); err == nil {
|
||||
@@ -163,7 +167,8 @@ func FullSyncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendo
|
||||
switch step {
|
||||
case 0:
|
||||
if singleStoreHandler != nil {
|
||||
_, err = ClearRemoteStoreStuffAndSetNew(ctx, task, vendorID, storeID, vendorStoreID, false, isContinueWhenError)
|
||||
// _, err = ClearRemoteStoreStuffAndSetNew(ctx, task, vendorID, storeID, vendorStoreID, false, isContinueWhenError)
|
||||
_, err = amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, false, isContinueWhenError, AmendPruneAll, true)
|
||||
} else {
|
||||
_, err = dao.SetStoreSkuSyncStatus(dao.GetDB(), vendorID, []int{storeID}, nil, model.SyncFlagStoreSkuOnlyMask)
|
||||
}
|
||||
@@ -568,30 +573,29 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo
|
||||
return err
|
||||
}
|
||||
|
||||
func checkRemoteCatExist(localCatMap map[string]*dao.SkuStoreCatInfo, catList []*partner.BareCategoryInfo) (cat2Delete []*partner.BareCategoryInfo) {
|
||||
for _, v := range catList {
|
||||
if localCatMap[v.VendorCatID] == nil && localCatMap[v.Name] == nil {
|
||||
func checkRemoteCatExist(outRemoteCatMap map[string]int, localCatMap map[string]*dao.SkuStoreCatInfo, remoteCatList []*partner.BareCategoryInfo) (cat2Delete []*partner.BareCategoryInfo) {
|
||||
for _, v := range remoteCatList {
|
||||
localCat := localCatMap[v.VendorCatID]
|
||||
// if localCat == nil {
|
||||
// localCat = localCatMap[v.Name]
|
||||
// }
|
||||
if localCat == nil || v.Level != int(localCat.Level) {
|
||||
cat2Delete = append(cat2Delete, v)
|
||||
} else {
|
||||
outRemoteCatMap[v.VendorCatID] = 1
|
||||
}
|
||||
cat2Delete = append(cat2Delete, checkRemoteCatExist(localCatMap, v.Children)...)
|
||||
cat2Delete = append(cat2Delete, checkRemoteCatExist(outRemoteCatMap, localCatMap, v.Children)...)
|
||||
}
|
||||
return cat2Delete
|
||||
}
|
||||
|
||||
func fillRemoteCatMap(catList []*partner.BareCategoryInfo, catMap map[string]int) {
|
||||
for _, v := range catList {
|
||||
catMap[v.VendorCatID] = 1
|
||||
fillRemoteCatMap(v.Children, catMap)
|
||||
}
|
||||
}
|
||||
|
||||
// 清除京西没有,平台有的商品与商家分类
|
||||
// todo !!!,因为美团外卖分类当前是用的名字关联的,所以改名后如果没有及时同步,这个函数会导致美团平台的分类被误删
|
||||
func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return ammendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmmendPruneOnlyPrune)
|
||||
return amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmendPruneOnlyPrune, false)
|
||||
}
|
||||
|
||||
func ammendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool, opType int) (hint string, err error) {
|
||||
func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) {
|
||||
handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
if handler == nil {
|
||||
return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID])
|
||||
@@ -600,8 +604,7 @@ func ammendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
|
||||
var sku2Delete []*partner.StoreSkuInfo
|
||||
var cat2Delete []*partner.BareCategoryInfo
|
||||
var storeSkuBindIDs, storeCatBindIDs []int
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("修补平台:%s上的门店商品与分类", model.VendorChineseNames[vendorID]),
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("修补门店:%d,平台:%s上的商品与商家分类", storeID, model.VendorChineseNames[vendorID]),
|
||||
tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
@@ -611,41 +614,50 @@ func ammendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localSkuMap := make(map[int]*dao.StoreSkuSyncInfo)
|
||||
localSkuMap := make(map[string]*dao.StoreSkuSyncInfo)
|
||||
for _, v := range localSkuList {
|
||||
localSkuMap[v.SkuID] = v
|
||||
localSkuMap[v.VendorSkuID] = v
|
||||
}
|
||||
|
||||
remoteSkuList, err2 := handler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil)
|
||||
if err = err2; err == nil {
|
||||
remoteSkuMap := make(map[int]int)
|
||||
remoteSkuMap := make(map[string]int)
|
||||
for _, v := range remoteSkuList {
|
||||
remoteSkuMap[v.SkuList[0].SkuID] = 1
|
||||
if localSkuMap[v.SkuList[0].SkuID] == nil {
|
||||
sku2Delete = append(sku2Delete, &partner.StoreSkuInfo{
|
||||
SkuID: v.SkuList[0].SkuID,
|
||||
VendorSkuID: v.SkuList[0].VendorSkuID,
|
||||
})
|
||||
if vendorSkuID := v.SkuList[0].VendorSkuID; vendorSkuID != "" {
|
||||
if localSkuMap[vendorSkuID] == nil ||
|
||||
remoteSkuMap[vendorSkuID] == 1 /*skuID在平台重复,典型的是美团可能会出现此类情况*/ {
|
||||
sku2Delete = append(sku2Delete, &partner.StoreSkuInfo{
|
||||
SkuID: v.SkuList[0].SkuID,
|
||||
VendorSkuID: vendorSkuID,
|
||||
})
|
||||
} else {
|
||||
remoteSkuMap[vendorSkuID] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, v := range localSkuList {
|
||||
if remoteSkuMap[v.SkuID] == 0 && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 {
|
||||
storeSkuBindIDs = append(storeSkuBindIDs, v.BindID)
|
||||
if opType == AmendPruneOnlyAmend || opType == AmendPruneAll {
|
||||
for _, v := range localSkuList {
|
||||
if !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 {
|
||||
syncStatus := 0
|
||||
if remoteSkuMap[v.VendorSkuID] == 0 {
|
||||
if !model.IsSyncStatusNew(v.StoreSkuSyncStatus) {
|
||||
syncStatus = model.SyncFlagNewMask
|
||||
}
|
||||
} else if isForceUpdate {
|
||||
syncStatus = model.SyncFlagStoreSkuModifiedMask
|
||||
}
|
||||
if syncStatus != 0 {
|
||||
skuBind := &model.StoreSkuBind{}
|
||||
skuBind.ID = v.BindID
|
||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), syncStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
if (opType == AmmendPruneOnlyAmend || opType == AmmendPruneAll) && len(storeSkuBindIDs) > 0 {
|
||||
for _, bindID := range storeSkuBindIDs {
|
||||
fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
|
||||
skuBind := &model.StoreSkuBind{}
|
||||
skuBind.ID = bindID
|
||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask)
|
||||
}
|
||||
}
|
||||
|
||||
if (opType == AmmendPruneOnlyPrune || opType == AmmendPruneAll) && len(sku2Delete) > 0 {
|
||||
if (opType == AmendPruneOnlyPrune || opType == AmendPruneAll) && len(sku2Delete) > 0 {
|
||||
_, err = putils.FreeBatchStoreSkuInfo("删除门店商品", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
|
||||
_, err = handler.DeleteStoreSkus(ctx, storeID, vendorStoreID, batchedStoreSkuList)
|
||||
return nil, 0, err
|
||||
@@ -666,27 +678,29 @@ func ammendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
|
||||
remoteCatList, err2 := handler.GetStoreAllCategories(ctx, storeID, vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
cat2Delete = checkRemoteCatExist(localCatMap, remoteCatList)
|
||||
|
||||
remoteCatMap := make(map[string]int)
|
||||
fillRemoteCatMap(remoteCatList, remoteCatMap)
|
||||
cat2Delete = checkRemoteCatExist(remoteCatMap, localCatMap, remoteCatList)
|
||||
|
||||
for _, v := range localCatList {
|
||||
if remoteCatMap[v.VendorCatID] == 0 && !model.IsSyncStatusNew(v.StoreCatSyncStatus) && !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 {
|
||||
storeCatBindIDs = append(storeCatBindIDs, v.MapID)
|
||||
if !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 {
|
||||
syncStatus := 0
|
||||
if remoteCatMap[v.VendorCatID] == 0 {
|
||||
if !model.IsSyncStatusNew(v.StoreCatSyncStatus) {
|
||||
syncStatus = model.SyncFlagNewMask
|
||||
}
|
||||
} else if isForceUpdate && !model.IsSyncStatusUpdate(v.StoreCatSyncStatus) {
|
||||
syncStatus = model.SyncFlagModifiedMask
|
||||
}
|
||||
if syncStatus != 0 {
|
||||
catBind := &model.StoreSkuCategoryMap{}
|
||||
catBind.ID = v.MapID
|
||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, catBind, nil, ctx.GetUserName(), nil, dao.GetSyncStatusStructField(model.VendorNames[vendorID]), syncStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
if (opType == AmmendPruneOnlyAmend || opType == AmmendPruneAll) && len(storeCatBindIDs) > 0 {
|
||||
for _, bindID := range storeCatBindIDs {
|
||||
fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
|
||||
catBind := &model.StoreSkuCategoryMap{}
|
||||
catBind.ID = bindID
|
||||
dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, catBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask)
|
||||
}
|
||||
}
|
||||
|
||||
if (opType == AmmendPruneOnlyPrune || opType == AmmendPruneAll) && len(cat2Delete) > 0 {
|
||||
if (opType == AmendPruneOnlyPrune || opType == AmendPruneAll) && len(cat2Delete) > 0 {
|
||||
for i := 0; i < 2; i++ {
|
||||
level := 2 - i
|
||||
var levelCat2Delete []*partner.BareCategoryInfo
|
||||
@@ -696,10 +710,10 @@ func ammendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
}
|
||||
}
|
||||
if len(levelCat2Delete) > 0 {
|
||||
task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除本地不存在的远程分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
task4Delete := tasksch.NewParallelTask(fmt.Sprintf("删除商家分类,level:%d", level), tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
cat := batchItemList[0].(*partner.BareCategoryInfo)
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID)
|
||||
err = handler.DeleteStoreCategory(ctx, storeID, vendorStoreID, cat.VendorCatID, level)
|
||||
return nil, err
|
||||
}, levelCat2Delete)
|
||||
tasksch.HandleTask(task4Delete, task, true).Run()
|
||||
@@ -712,65 +726,18 @@ func ammendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
return nil, err
|
||||
}, []int{0, 1, 2, 3})
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = task.ID
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
// 把京西有,平台无且没有待创建标记的商品加上待创建标记
|
||||
func AddCreateFlagForJxStoreSku(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return ammendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmmendPruneOnlyAmend)
|
||||
// handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
// if handler == nil {
|
||||
// return "", fmt.Errorf("平台:%s不支持此操作", model.VendorChineseNames[vendorID])
|
||||
// }
|
||||
// db := dao.GetDB()
|
||||
|
||||
// var storeSkuBindIDs []int
|
||||
// seqTaskFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
// switch step {
|
||||
// case 0:
|
||||
// localSkuList, err2 := dao.GetStoreSkus2(db, vendorID, storeID, nil, false)
|
||||
// if err = err2; err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// remoteSkuList, err2 := handler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil)
|
||||
// if err = err2; err == nil {
|
||||
// remoteSkuMap := make(map[int]int)
|
||||
// for _, value := range remoteSkuList {
|
||||
// for _, skuInfo := range value.SkuList {
|
||||
// remoteSkuMap[skuInfo.SkuID] = 1
|
||||
// }
|
||||
// }
|
||||
// for _, v := range localSkuList {
|
||||
// if remoteSkuMap[v.SkuID] == 0 && !model.IsSyncStatusNew(v.StoreSkuSyncStatus) && !model.IsSyncStatusDelete(v.StoreSkuSyncStatus) && v.BindID != 0 {
|
||||
// storeSkuBindIDs = append(storeSkuBindIDs, v.BindID)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// case 1:
|
||||
// if len(storeSkuBindIDs) > 0 {
|
||||
// for _, bindID := range storeSkuBindIDs {
|
||||
// fieldStatus := dao.GetSyncStatusStructField(model.VendorNames[vendorID])
|
||||
// skuBind := &model.StoreSkuBind{}
|
||||
// skuBind.ID = bindID
|
||||
// dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, skuBind, nil, ctx.GetUserName(), nil, fieldStatus, model.SyncFlagNewMask)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return nil, err
|
||||
// }
|
||||
// task := tasksch.NewSeqTask(fmt.Sprintf("处理京西门店商品加待创建标记:%s", model.VendorChineseNames[vendorID]), ctx, seqTaskFunc, 2)
|
||||
// tasksch.HandleTask(task, parentTask, true).Run()
|
||||
// if isAsync {
|
||||
// hint = task.GetID()
|
||||
// } else {
|
||||
// _, err = task.GetResult(0)
|
||||
// }
|
||||
// return hint, err
|
||||
return amendAndPruneStoreStuff(ctx, parentTask, vendorID, storeID, vendorStoreID, isAsync, isContinueWhenError, AmendPruneOnlyAmend, false)
|
||||
}
|
||||
|
||||
func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
@@ -782,35 +749,30 @@ func ClearRemoteStoreStuffAndSetNew(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
}
|
||||
|
||||
db := dao.GetDB()
|
||||
var errDeleteSku error
|
||||
rootTask := tasksch.NewSeqTask(fmt.Sprintf("ClearRemoteStoreStuffAndSetNew:%s", model.VendorChineseNames[vendorID]), ctx,
|
||||
func(rootTask *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
task := tasksch.NewParallelTask(fmt.Sprintf("删除门店:%d,平台:%s上的商品与商家分类", storeID, model.VendorChineseNames[vendorID]),
|
||||
tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
step := batchItemList[0].(int)
|
||||
switch step {
|
||||
case 0:
|
||||
err = handler.DeleteStoreAllSkus(ctx, rootTask, storeID, vendorStoreID, isContinueWhenError)
|
||||
errDeleteSku = err
|
||||
// 强制忽略删除SKU错误
|
||||
if isContinueWhenError {
|
||||
err = nil
|
||||
}
|
||||
if err == nil {
|
||||
_, err = dao.SetStoreSkuSyncStatus(db, vendorID, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
}
|
||||
err = handler.DeleteStoreAllSkus(ctx, task, storeID, vendorStoreID, isContinueWhenError)
|
||||
case 1:
|
||||
if err = handler.DeleteStoreAllCategories(ctx, rootTask, storeID, vendorStoreID, isContinueWhenError); err == nil {
|
||||
_, err = dao.SetStoreCategorySyncStatus(db, vendorID, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
}
|
||||
_, err = dao.SetStoreSkuSyncStatus(db, vendorID, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
case 2:
|
||||
err = handler.DeleteStoreAllCategories(ctx, task, storeID, vendorStoreID, isContinueWhenError)
|
||||
case 3:
|
||||
_, err = dao.SetStoreCategorySyncStatus(db, vendorID, []int{storeID}, nil, model.SyncFlagNewMask)
|
||||
}
|
||||
return nil, err
|
||||
}, 2)
|
||||
tasksch.AddChild(parentTask, rootTask).Run()
|
||||
}, []int{0, 1, 2, 3})
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if !isAsync {
|
||||
_, err = rootTask.GetResult(0)
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = task.ID
|
||||
}
|
||||
if err == nil {
|
||||
err = errDeleteSku
|
||||
}
|
||||
return rootTask.ID, err
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func GetSensitiveWord(singleStoreHandler partner.ISingleStoreStoreSkuHandler, str string) string {
|
||||
|
||||
@@ -680,20 +680,25 @@ func SaveUserCart(ctx *jxcontext.Context, userID string, storeID int, cartItems
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = dao.CreateMultiEntities(dao.GetDB(), cartItems)
|
||||
if len(cartItems) > 0 {
|
||||
err = dao.CreateMultiEntities(db, cartItems)
|
||||
}
|
||||
if err == nil {
|
||||
dao.Commit(db)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func LoadUserCart(ctx *jxcontext.Context, userID string, storeID int) (cartItems []*model.UserCartItem, err error) {
|
||||
if userID == "" || storeID == 0 {
|
||||
func LoadUserCart(ctx *jxcontext.Context, userID string, storeIDs []int) (cartItems []*model.UserCartItem, err error) {
|
||||
if userID == "" || len(storeIDs) == 0 {
|
||||
return nil, fmt.Errorf("用户与门店必须要指定")
|
||||
}
|
||||
sql := `
|
||||
SELECT t1.*
|
||||
FROM user_cart_item t1
|
||||
WHERE t1.user_id = ? AND t1.store_id = ?
|
||||
WHERE t1.user_id = ? AND t1.store_id IN (` + dao.GenQuestionMarks(len(storeIDs)) + `)
|
||||
ORDER BY t1.sku_id
|
||||
`
|
||||
err = dao.GetRows(dao.GetDB(), &cartItems, sql, userID, storeID)
|
||||
err = dao.GetRows(dao.GetDB(), &cartItems, sql, userID, storeIDs)
|
||||
return cartItems, err
|
||||
}
|
||||
|
||||
@@ -243,42 +243,58 @@ func InitSkuName(ctx *jxcontext.Context, isForce, isAsync, isContinueWhenError b
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func InitVendorCategory(ctx *jxcontext.Context, vendorID int) (num int64, err error) {
|
||||
func InitVendorCategory(ctx *jxcontext.Context, vendorID int, isAsync bool) (hint string, err error) {
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(vendorID); handler != nil {
|
||||
cats, err2 := handler.GetVendorCategories(ctx)
|
||||
if err2 != nil {
|
||||
return num, err2
|
||||
}
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
var cats []*model.SkuVendorCategory
|
||||
rootTask := tasksch.NewSeqTask(fmt.Sprintf("创建%s的平台分类", model.VendorChineseNames[vendorID]), ctx,
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
cats, err = handler.GetVendorCategories(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case 1:
|
||||
db := dao.GetDB()
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil || err != nil {
|
||||
dao.Rollback(db)
|
||||
if r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}()
|
||||
sql := `
|
||||
DELETE
|
||||
FROM sku_vendor_category
|
||||
WHERE vendor_id = ?
|
||||
`
|
||||
if _, err = dao.ExecuteSQL(db, sql, vendorID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, cat := range cats {
|
||||
dao.WrapAddIDCULEntity(cat, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, cat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
return nil, err
|
||||
}, 2)
|
||||
tasksch.HandleTask(rootTask, nil, true).Run()
|
||||
if !isAsync {
|
||||
if _, err = rootTask.GetResult(0); err == nil {
|
||||
hint = utils.Int2Str(len(cats))
|
||||
}
|
||||
}()
|
||||
sql := `
|
||||
DELETE
|
||||
FROM sku_vendor_category
|
||||
WHERE vendor_id = ?
|
||||
`
|
||||
if _, err = dao.ExecuteSQL(db, sql, vendorID); err != nil {
|
||||
return num, err
|
||||
} else {
|
||||
hint = rootTask.ID
|
||||
}
|
||||
for _, cat := range cats {
|
||||
dao.WrapAddIDCULEntity(cat, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, cat); err != nil {
|
||||
return num, err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
num = int64(len(cats))
|
||||
} else {
|
||||
err = fmt.Errorf("找不到平台:%d", vendorID)
|
||||
}
|
||||
return num, err
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func UploadImg4Vendors(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
|
||||
@@ -124,12 +124,12 @@ func doDailyWork() {
|
||||
globals.SugarLogger.Debug("doDailyWork")
|
||||
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
|
||||
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
||||
// cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, true, true)
|
||||
// cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, true, true)
|
||||
|
||||
cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, nil, []int{27379}, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true)
|
||||
cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDJD}, nil, false, nil, []int{27379}, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true)
|
||||
|
||||
SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID)
|
||||
taskID, _ := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDEBAI, model.VendorIDMTWM}, nil, nil, nil, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true)
|
||||
taskID, _ := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDEBAI, model.VendorIDMTWM}, nil, false, nil, nil, model.SyncFlagSaleMask|model.SyncFlagPriceMask, true, true)
|
||||
SaveImportantTaskID(TaskNameSyncStoreSku, taskID)
|
||||
|
||||
InitEx()
|
||||
|
||||
Reference in New Issue
Block a user