From 2b74307ce66d2cd60fee388693eb685df45ba594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 12 Nov 2020 18:28:15 +0800 Subject: [PATCH] jdprice --- business/jxstore/tempop/tempop.go | 433 +++++++++++++++--------------- 1 file changed, 216 insertions(+), 217 deletions(-) diff --git a/business/jxstore/tempop/tempop.go b/business/jxstore/tempop/tempop.go index efff74c75..000e20365 100644 --- a/business/jxstore/tempop/tempop.go +++ b/business/jxstore/tempop/tempop.go @@ -8,10 +8,9 @@ import ( "strings" "time" - "git.rosy.net.cn/jx-callback/business/jxstore/act" - "git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" "git.rosy.net.cn/jx-callback/business/partner/delivery" + "git.rosy.net.cn/jx-callback/business/partner/putils" "github.com/360EntSecGroup-Skylar/excelize" "github.com/qiniu/api.v7/storage" @@ -1712,235 +1711,235 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) { // cms.UpdateStoreSkus(ctx, 0, storeDetail.ID, skuBindInfos, true, true) // } var ( - // jdStoreIDs = []string{ - // "11734848", - // "11734850", - // "11734854", - // "11734862", - // "11734868", - // "11734873", - // "11734874", - // "11734886", - // "11748353", - // "11890095", - // "11800399", - // "11738114", - // "11857499", - // "11873440", - // "11883071", - // "11734852", - // "11886763", - // "11874614", - // "11734884", - // "11926674", - // "11929173", - // "11894144", - // "11734861", - // "11951611", - // "11800403", - // "11913597", - // "11980746", - // "11981675", - // "12011812", - // "12007545", - // "11734846", - // "12005417", - // "12005640", - // "12005682", - // "12006134", - // "11982352", - // "12007250", - // "12007560", - // "11982427", - // "12008087", - // "12035806", - // "12008160", - // "12008395", - // "12009345", - // "11940019", - // "12010237", - // "12010654", - // "12011111", - // "12006857", - // "11734851", - // "12030632", - // "12050456", - // } - // jdStoreIDxipu = "11890095" - // skuMap = make(map[string]partner.StoreSkuInfo) - // priceList = make(map[string][]*partner.StoreSkuInfo) - // statusList1 = make(map[string][]*partner.StoreSkuInfo) - // statusList2 = make(map[string][]*partner.StoreSkuInfo) - // stockList = make(map[string][]*partner.StoreSkuInfo) - // vendorOrgCode = "82029" - storeID = 2 - db = dao.GetDB() + jdStoreIDs = []string{ + "11734848", + "11734850", + "11734854", + "11734862", + // "11734868", + "11734873", + "11734874", + "11734886", + "11748353", + "11890095", + "11800399", + "11738114", + "11857499", + "11873440", + "11883071", + "11734852", + "11886763", + "11874614", + "11734884", + "11926674", + "11929173", + "11894144", + "11734861", + "11951611", + "11800403", + "11913597", + "11980746", + "11981675", + "12011812", + "12007545", + "11734846", + "12005417", + "12005640", + "12005682", + "12006134", + "11982352", + "12007250", + "12007560", + "11982427", + "12008087", + "12035806", + "12008160", + "12008395", + "12009345", + "11940019", + "12010237", + "12010654", + "12011111", + "12006857", + "11734851", + "12030632", + "12050456", + } + jdStoreIDxipu = "11890095" + skuMap = make(map[string]partner.StoreSkuInfo) + priceList = make(map[string][]*partner.StoreSkuInfo) + statusList1 = make(map[string][]*partner.StoreSkuInfo) + statusList2 = make(map[string][]*partner.StoreSkuInfo) + stockList = make(map[string][]*partner.StoreSkuInfo) + vendorOrgCode = "320406" + // storeID = 2 + // db = dao.GetDB() ) - // handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler) - // multiHandler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IMultipleStoresHandler) - // allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "") - // skuInfos := storeSkuFullList2BareFilter(allSkuNameInfoList) - // outStoreSkuList, err := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreIDxipu, skuInfos) - // for _, vv := range outStoreSkuList { - // skuMap[vv.VendorSkuID] = *vv - // } - // for _, jdStoreID := range jdStoreIDs { - // skuInfos2 := storeSkuFullList2BareFilter(allSkuNameInfoList) - // outStoreSkuList2, _ := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreID, skuInfos2) - // for _, v := range outStoreSkuList2 { - // a := skuMap[v.VendorSkuID] - // if &a == nil { - // continue - // } - // if a.VendorPrice != v.VendorPrice { - // v.VendorPrice = a.VendorPrice - // priceList[jdStoreID] = append(priceList[jdStoreID], v) - // } - // if a.Status != v.Status { - // v.Status = a.Status - // if v.Status == model.SkuStatusNormal { - // statusList1[jdStoreID] = append(statusList1[jdStoreID], v) - // } else { - // statusList2[jdStoreID] = append(statusList2[jdStoreID], v) - // } - // } - // if a.Stock != v.Stock { - // v.Stock = a.Stock - // stockList[jdStoreID] = append(stockList[jdStoreID], v) - // } - // } - // } + handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler) + multiHandler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IMultipleStoresHandler) + allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "") + skuInfos := storeSkuFullList2BareFilter(allSkuNameInfoList) + outStoreSkuList, err := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreIDxipu, skuInfos) + for _, vv := range outStoreSkuList { + skuMap[vv.VendorSkuID] = *vv + } + for _, jdStoreID := range jdStoreIDs { + skuInfos2 := storeSkuFullList2BareFilter(allSkuNameInfoList) + outStoreSkuList2, _ := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreID, skuInfos2) + for _, v := range outStoreSkuList2 { + a := skuMap[v.VendorSkuID] + if &a == nil { + continue + } + if a.VendorPrice != v.VendorPrice { + v.VendorPrice = a.VendorPrice + priceList[jdStoreID] = append(priceList[jdStoreID], v) + } + if a.Status != v.Status { + v.Status = a.Status + if v.Status == model.SkuStatusNormal { + statusList1[jdStoreID] = append(statusList1[jdStoreID], v) + } else { + statusList2[jdStoreID] = append(statusList2[jdStoreID], v) + } + } + if a.Stock != v.Stock { + v.Stock = a.Stock + stockList[jdStoreID] = append(stockList[jdStoreID], v) + } + } + } task := tasksch.NewParallelTask("syncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { step := batchItemList[0].(int) switch step { case 0: - // if len(priceList) > 0 { - // for k, v := range priceList { - // _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - // failedList, err := handler.UpdateStoreSkusPrice(ctx, vendorOrgCode, 0, k, batchedStoreSkuList) - // if len(failedList) > 0 { - // task.AddFailedList(failedList) - // } - // return nil, 1, err - // }, ctx, task, v, 50, true) - // } - // } + if len(priceList) > 0 { + for k, v := range priceList { + _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + failedList, err := handler.UpdateStoreSkusPrice(ctx, vendorOrgCode, 0, k, batchedStoreSkuList) + if len(failedList) > 0 { + task.AddFailedList(failedList) + } + return nil, 1, err + }, ctx, task, v, 50, true) + } + } case 1: - // if len(statusList1) > 0 { - // for k, v := range statusList1 { - // _, err = putils.FreeBatchStoreSkuInfo("更新门店商品状态", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - // failedList, err := handler.UpdateStoreSkusStatus(ctx, vendorOrgCode, 0, k, batchedStoreSkuList, batchedStoreSkuList[0].Status) - // if len(failedList) > 0 { - // task.AddFailedList(failedList) - // } - // return nil, 1, err - // }, ctx, task, v, 50, true) - // } - // } + if len(statusList1) > 0 { + for k, v := range statusList1 { + _, err = putils.FreeBatchStoreSkuInfo("更新门店商品状态", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + failedList, err := handler.UpdateStoreSkusStatus(ctx, vendorOrgCode, 0, k, batchedStoreSkuList, batchedStoreSkuList[0].Status) + if len(failedList) > 0 { + task.AddFailedList(failedList) + } + return nil, 1, err + }, ctx, task, v, 50, true) + } + } case 2: case 3: - // if len(stockList) > 0 { - // for k, v := range stockList { - // _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { - // failedList, err := handler.UpdateStoreSkusStock(ctx, vendorOrgCode, 0, k, batchedStoreSkuList) - // if len(failedList) > 0 { - // task.AddFailedList(failedList) - // } - // return nil, 1, err - // }, ctx, task, v, 50, true) - // } - // } - case 4: - var storeIDs = []int{ - // 667534, - // 667481, - // 667460, - // 667420, - // 667355, - // 667341, - // 667339, - // 667336, - // 667332, - // 667312, - // 667308, - // 667307, - // 667306, - // 667305, - // 667304, - // 667299, - // 667297, - // 667292, - // 667284, - // 667281, - // 667278, - // 667234, - // 667158, - // 667092, - // 667001, - // 666975, - // 666706, - // 666677, - // 666667, - // 103408, - // 103205, - // 103127, - // 103113, - // 102996, - // 102973, - // 102630, - // 102613, - // 102595, - // 102482, - // 101942, - // 101897, - // 101042, - // 100654, - // 100471, - // 100153, - // 100141, - // 100140, - 42, - // 100129, - // 100121, - // 100117, - // 100115, - } - list, _ := dao.QueryActs(db, 0, 0, 9999, -1, "", model.VendorIDJD, nil, []int{model.ActSkuDirectDown}, nil, storeID, nil, 0, time.Now().AddDate(0, -3, 0), time.Now(), utils.ZeroTimeValue, utils.ZeroTimeValue) - for _, v := range list.Data { - var actStoreSkuList []*act.ActStoreSkuParam - _, actStoreSku2, _ := dao.GetActStoreSkuVendorList(db, v.ID, []int{model.VendorIDJD}, []int{storeID}, nil, "", 0, 9999) - for _, vv := range actStoreSku2 { - for _, storeID2 := range storeIDs { - actStoreSku := &act.ActStoreSkuParam{} - actStoreSku.StoreID = storeID2 - actStoreSku.SkuID = vv.SkuID - actStoreSku.ActPrice = vv.ActPrice - actStoreSku.EarningPrice = vv.EarningPrice - actStoreSku.Stock = vv.Stock - actStoreSkuList = append(actStoreSkuList, actStoreSku) - } + if len(stockList) > 0 { + for k, v := range stockList { + _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { + failedList, err := handler.UpdateStoreSkusStock(ctx, vendorOrgCode, 0, k, batchedStoreSkuList) + if len(failedList) > 0 { + task.AddFailedList(failedList) + } + return nil, 1, err + }, ctx, task, v, 50, true) } - fmt.Println("actStoreSkuList", utils.Format4Output(actStoreSkuList, false)) - // act.CreateAct(ctx, &model.Act{ - // Name: "复制犀浦下街活动" + utils.Int2Str(k), - // Type: model.ActSkuDirectDown, - // LimitUser: v.LimitUser, - // LimitDaily: v.LimitDaily, - // LimitCount: v.LimitCount, - // OverlapRule: v.OverlapRule, - // CreateType: model.ActCreateTypeAPI, - // PricePercentage: v.PricePercentage, - // BeginAt: v.BeginAt, - // EndAt: v.EndAt, - // Advertising: v.Advertising, - // Remark: v.Remark, - // }, []int{model.VendorIDJD}, vendorOrgCode, nil, actStoreSkuList, true) } + // case 4: + // var storeIDs = []int{ + // 667534, + // 667481, + // 667460, + // 667420, + // 667355, + // 667341, + // 667339, + // 667336, + // 667332, + // 667312, + // 667308, + // 667307, + // 667306, + // 667305, + // 667304, + // 667299, + // 667297, + // 667292, + // 667284, + // 667281, + // 667278, + // 667234, + // 667158, + // 667092, + // 667001, + // 666975, + // 666706, + // 666677, + // 666667, + // 103408, + // 103205, + // 103127, + // 103113, + // 102996, + // 102973, + // 102630, + // 102613, + // 102595, + // 102482, + // 101942, + // 101897, + // 101042, + // 100654, + // 100471, + // 100153, + // 100141, + // 100140, + // 42, + // 100129, + // 100121, + // 100117, + // 100115, + // } + // list, _ := dao.QueryActs(db, 0, 0, 9999, -1, "", model.VendorIDJD, nil, []int{model.ActSkuDirectDown}, nil, storeID, nil, 0, time.Now().AddDate(0, -3, 0), time.Now(), utils.ZeroTimeValue, utils.ZeroTimeValue) + // for _, v := range list.Data { + // var actStoreSkuList []*act.ActStoreSkuParam + // _, actStoreSku2, _ := dao.GetActStoreSkuVendorList(db, v.ID, []int{model.VendorIDJD}, []int{storeID}, nil, "", 0, 9999) + // for _, vv := range actStoreSku2 { + // for _, storeID2 := range storeIDs { + // actStoreSku := &act.ActStoreSkuParam{} + // actStoreSku.StoreID = storeID2 + // actStoreSku.SkuID = vv.SkuID + // actStoreSku.ActPrice = vv.ActPrice + // actStoreSku.EarningPrice = vv.EarningPrice + // actStoreSku.Stock = vv.Stock + // actStoreSkuList = append(actStoreSkuList, actStoreSku) + // } + // } + // fmt.Println("actStoreSkuList", utils.Format4Output(actStoreSkuList, false)) + // act.CreateAct(ctx, &model.Act{ + // Name: "复制犀浦下街活动" + utils.Int2Str(k), + // Type: model.ActSkuDirectDown, + // LimitUser: v.LimitUser, + // LimitDaily: v.LimitDaily, + // LimitCount: v.LimitCount, + // OverlapRule: v.OverlapRule, + // CreateType: model.ActCreateTypeAPI, + // PricePercentage: v.PricePercentage, + // BeginAt: v.BeginAt, + // EndAt: v.EndAt, + // Advertising: v.Advertising, + // Remark: v.Remark, + // }, []int{model.VendorIDJD}, vendorOrgCode, nil, actStoreSkuList, true) + // } } return retVal, err - }, []int{0, 1, 2, 3, 4}) + }, []int{0, 1, 2, 3}) tasksch.HandleTask(task, nil, true).Run() _, err = task.GetResult(0) return err