From dc7c9d210c72a069484b76a25829604353a73cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Fri, 22 May 2020 15:37:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store_sku.go | 12 ++++ business/jxstore/cms/sync.go | 106 +++++++++++++++--------------- business/jxstore/misc/misc.go | 3 +- 3 files changed, 68 insertions(+), 53 deletions(-) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 7626db551..2982e6763 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -13,6 +13,8 @@ import ( "time" "unicode" + "git.rosy.net.cn/baseapi/platformapi/jdshopapi" + "git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/refutil" @@ -4427,5 +4429,15 @@ func focusC4Matters(ctx *jxcontext.Context, db *dao.DaoDB, v *model.Sku) (err er } func RefreshJdsSkusStatus(ctx *jxcontext.Context) (err error) { + handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJDShop).(partner.ISingleStoreStoreSkuHandler) + remoteSkuList, err := handler.GetStoreSkusFullInfo(ctx, nil, 0, "", nil) + for _, v := range remoteSkuList { + if v.Status == jdshopapi.JdsSkuStatus2 { + reason, err := api.JdShopAPI.FindOpReason(utils.Str2Int64(v.VendorNameID)) + if err == nil && reason == jdshopapi.PassReason { + err = api.JdShopAPI.UpOrDown(utils.Str2Int64(v.VendorNameID), jdshopapi.JdsSkuStatus1) + } + } + } return err } diff --git a/business/jxstore/cms/sync.go b/business/jxstore/cms/sync.go index 21def0ef1..ab5b9a2c1 100644 --- a/business/jxstore/cms/sync.go +++ b/business/jxstore/cms/sync.go @@ -1115,14 +1115,14 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) { var ( - mainSkusMap = make(map[int]*model.StoreSkuBind) - skusMap = make(map[int]*model.StoreSkuBind) - updateList []*model.StoreSkuBind - addList []*model.StoreSkuBind - skuBindInfos1 []*StoreSkuBindInfo - skuBindInfos2 []*StoreSkuBindInfo - resultInterface1 []interface{} - resultInterface2 []interface{} + mainSkusMap = make(map[int]*model.StoreSkuBind) + skusMap = make(map[int]*model.StoreSkuBind) + updateList []*model.StoreSkuBind + addList []*model.StoreSkuBind + // skuBindInfos1 []*StoreSkuBindInfo + // skuBindInfos2 []*StoreSkuBindInfo + // resultInterface1 []interface{} + // resultInterface2 []interface{} ) storeSkusMain, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil) for _, v := range storeSkusMain { @@ -1142,50 +1142,52 @@ func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch } } } - task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, - func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - step := batchItemList[0].(int) - switch step { - case 0: - if len(updateList) > 0 { - task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, - func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - storeBind := batchItemList[0].(*model.StoreSkuBind) - retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, false)} - return retVal, err - }, updateList) - tasksch.HandleTask(task, ptTask, false).Run() - resultInterface1, err = task.GetResult(0) - for _, v := range resultInterface1 { - skuBindInfos1 = append(skuBindInfos1, v.(*StoreSkuBindInfo)) - } - hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false) - } - case 1: - if len(addList) > 0 { - task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, - func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { - storeBind := batchItemList[0].(*model.StoreSkuBind) - retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, true)} - return retVal, err - }, addList) - tasksch.HandleTask(task, ptTask, false).Run() - resultInterface2, err = task.GetResult(0) - for _, v := range resultInterface2 { - skuBindInfos2 = append(skuBindInfos2, v.(*StoreSkuBindInfo)) - } - hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false) - } - } - return retVal, err - }, []int{0, 1}) - tasksch.HandleTask(task, nil, true).Run() - if isAsync { - hint = task.GetID() - } else { - _, err = task.GetResult(0) - hint = "1" - } + fmt.Println("updateList", utils.Format4Output(updateList, false)) + fmt.Println("addList", utils.Format4Output(addList, false)) + // task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + // func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + // step := batchItemList[0].(int) + // switch step { + // case 0: + // if len(updateList) > 0 { + // task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + // func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + // storeBind := batchItemList[0].(*model.StoreSkuBind) + // retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, false)} + // return retVal, err + // }, updateList) + // tasksch.HandleTask(task, ptTask, false).Run() + // resultInterface1, err = task.GetResult(0) + // for _, v := range resultInterface1 { + // skuBindInfos1 = append(skuBindInfos1, v.(*StoreSkuBindInfo)) + // } + // hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false) + // } + // case 1: + // if len(addList) > 0 { + // task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx, + // func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + // storeBind := batchItemList[0].(*model.StoreSkuBind) + // retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, true)} + // return retVal, err + // }, addList) + // tasksch.HandleTask(task, ptTask, false).Run() + // resultInterface2, err = task.GetResult(0) + // for _, v := range resultInterface2 { + // skuBindInfos2 = append(skuBindInfos2, v.(*StoreSkuBindInfo)) + // } + // hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false) + // } + // } + // return retVal, err + // }, []int{0, 1}) + // tasksch.HandleTask(task, nil, true).Run() + // if isAsync { + // hint = task.GetID() + // } else { + // _, err = task.GetResult(0) + // hint = "1" + // } return hint, err } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index a9574af87..72e0f41d6 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -402,7 +402,8 @@ func doDailyWork() { //刷新京东商城订单结算价 orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, time.Now().AddDate(0, 0, -3).Format("20060102"), time.Now().Format("20060102")) //同步京东商城门店库存和商品 - + //同步上架京东商城待售商品 + cms.RefreshJdsSkusStatus(jxcontext.AdminCtx) } func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {