同步京东库存优化
This commit is contained in:
@@ -1098,8 +1098,8 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
storeSkus, _ := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
|
||||
_, hint, err = v.LoopStoresMap2(ctx, nil, db, fmt.Sprintf("同步京东商城库存商品信息:%v", storeIDs), isAsync, true, []int{model.VendorIDJDShop}, storeIDs, false,
|
||||
// storeSkus, _ := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
|
||||
_, hint, err = v.LoopStoresMap2(ctx, nil, db, fmt.Sprintf("同步京东商城门店的可售信息:%v", storeIDs), isAsync, true, []int{model.VendorIDJDShop}, storeIDs, false,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||
@@ -1107,7 +1107,7 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
|
||||
if storeMap.Status > model.StoreStatusDisabled && storeMap.StoreID != model.JdShopMainStoreID && storeMap.SyncRule != 0 {
|
||||
err = syncJdsStoresSkus(ctx, db, t, storeMap, isAsync, isContinueWhenError)
|
||||
}
|
||||
err = syncJdsStoreStock(ctx, db, t, storeSkus, storeMap, isAsync, isContinueWhenError)
|
||||
// err = syncJdsStoreStock(ctx, db, t, storeSkus, storeMap, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return nil, partner.AddVendorInfo2Err(err, loopMapInfo.VendorID)
|
||||
@@ -1115,44 +1115,36 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func syncJdsStoreStock(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeSkus []*model.StoreSkuBind, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (err error) {
|
||||
// for _, storeSku := range storeSkus {
|
||||
// stock := 0
|
||||
// storeSku2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{storeSku.SkuID})
|
||||
// if storeSku.JdsID != 0 {
|
||||
// if len(storeSku2) > 0 {
|
||||
// if storeSku2[0].Status == model.StoreSkuBindStatusNormal && storeSku.Status == model.StoreSkuBindStatusNormal {
|
||||
// stock = 9999
|
||||
// }
|
||||
// if storeMap.VendorStoreID != "" {
|
||||
// err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, stock, utils.Str2Int(storeMap.VendorStoreID))
|
||||
// }
|
||||
// } else {
|
||||
// err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, 0, utils.Str2Int(storeMap.VendorStoreID))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
task := tasksch.NewParallelTask("syncJdsStoreStock", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(1), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeSku := batchItemList[0].(*model.StoreSkuBind)
|
||||
stock := 0
|
||||
storeSku2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{storeSku.SkuID})
|
||||
if storeSku.JdsID != 0 {
|
||||
if len(storeSku2) > 0 {
|
||||
if storeSku2[0].Status == model.StoreSkuBindStatusNormal && storeSku.Status == model.StoreSkuBindStatusNormal {
|
||||
stock = 9999
|
||||
func SyncJdsStoreStock(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, isAsync, isContinueWhenError bool) (err error) {
|
||||
storeMaps, err := dao.GetStoresMapList(db, []int{model.VendorIDJDShop}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
storeSkus, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, storeMap := range storeMaps {
|
||||
task := tasksch.NewParallelTask("syncJdsStoreStock", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError).SetParallelCount(1), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeSku := batchItemList[0].(*model.StoreSkuBind)
|
||||
stock := 0
|
||||
storeSku2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{storeSku.SkuID})
|
||||
if storeSku.JdsID != 0 {
|
||||
if len(storeSku2) > 0 {
|
||||
if storeSku2[0].Status == model.StoreSkuBindStatusNormal && storeSku.Status == model.StoreSkuBindStatusNormal {
|
||||
stock = 9999
|
||||
}
|
||||
if storeMap.VendorStoreID != "" {
|
||||
err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, stock, utils.Str2Int(storeMap.VendorStoreID))
|
||||
}
|
||||
} else {
|
||||
err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, 0, utils.Str2Int(storeMap.VendorStoreID))
|
||||
}
|
||||
if storeMap.VendorStoreID != "" {
|
||||
err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, stock, utils.Str2Int(storeMap.VendorStoreID))
|
||||
}
|
||||
} else {
|
||||
err = api.JdShopAPI.UpdateSkuSiteStock(storeSku.JdsID, 0, utils.Str2Int(storeMap.VendorStoreID))
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, storeSkus)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
if !isAsync {
|
||||
return retVal, err
|
||||
}, storeSkus)
|
||||
tasksch.HandleTask(task, parentTask, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -46,7 +46,7 @@ var (
|
||||
"20:30:00",
|
||||
}
|
||||
dailyWorkTimeList2 = []string{
|
||||
"18:30:00",
|
||||
"02:00:00",
|
||||
}
|
||||
priceReferTimeList = []string{
|
||||
"03:00:00",
|
||||
@@ -383,8 +383,10 @@ func syncStoreSku() {
|
||||
func doDailyWork2() {
|
||||
globals.SugarLogger.Debug("doDailyWork2")
|
||||
|
||||
//同步京东商城门店库存和商品
|
||||
//同步京东商城门店的商品
|
||||
cms.CurVendorSync.SyncJdsStoresSkus(jxcontext.AdminCtx, nil, true, true)
|
||||
//刷新京东商城的门店库存
|
||||
cms.SyncJdsStoreStock(jxcontext.AdminCtx, dao.GetDB(), nil, true, true)
|
||||
}
|
||||
|
||||
func doDailyWork() {
|
||||
|
||||
Reference in New Issue
Block a user