diff --git a/business/jxstore/tempop/tempop.go b/business/jxstore/tempop/tempop.go index ff42aeee0..b52204f2f 100644 --- a/business/jxstore/tempop/tempop.go +++ b/business/jxstore/tempop/tempop.go @@ -10,11 +10,11 @@ import ( "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" "git.rosy.net.cn/baseapi/platformapi/jdapi" - "git.rosy.net.cn/baseapi/platformapi/jdshopapi" "git.rosy.net.cn/baseapi/platformapi/mtwmapi" "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils/errlist" @@ -1499,153 +1499,98 @@ func addSku(outSkuId string, cagtegoryId int, shopCategories []int64, brandId in } func UploadJdsImage(ctx *jxcontext.Context) (err error) { - // 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 = "320406" - // vendorOrgCode = "82029" - // ) + var ( + jdStoreIDs = []string{"11734848"} + jdStoreIDxipu = "12005417" + 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" + // vendorOrgCode = "82029" + ) - // 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 { - // v.VendorPrice = int64(math.Round(float64(v.VendorPrice) * 1.05)) - // priceList[jdStoreID] = append(priceList[jdStoreID], v) - // 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) - // } - // } - // 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) - // } - // } - // 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) - // } - // } - // } - // return retVal, err - // }, []int{0}) - // tasksch.HandleTask(task, nil, true).Run() - // _, err = task.GetResult(0) + 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) + } + } + 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) + // } + // } + 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) + // } + // } + } + return retVal, err + }, []int{0}) + tasksch.HandleTask(task, nil, true).Run() + _, err = task.GetResult(0) // var ( // storeMaps []*model.StoreMap // db = dao.GetDB() @@ -1724,72 +1669,72 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) { // JdsStreetName: v.JdsStreetName, // } // dao.WrapAddIDCULDEntity(storeMap, "jxadmin") - if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie2", model.ConfigTypeCookie, ""); err == nil { - api.JdShop2API.SetCookieWithStr(configs[0].Value) - } - for i := 1; i < 6; i++ { - shopListResult, _ := api.JdShop2API.ShopList(i) - for _, v := range shopListResult.List { - var store *model.Store - sql := ` - SELECT a.* - FROM store a - JOIN store_map b ON a.id = b.store_id - WHERE b.deleted_at = '1970-01-01 00:00:00' - AND b.vendor_id = 5 - AND b.vendor_store_id = ? - AND b.vendor_org_code = 2 - ` - sqlParams := []interface{}{v.StoreID} - err = dao.GetRow(dao.GetDB(), &store, sql, sqlParams) - if strings.Contains(v.StoreName, "(") { - v.StoreName = v.StoreName[0:strings.Index(v.StoreName, "(")] + v.StoreName[strings.Index(v.StoreName, ")")+3:len(v.StoreName)] - } - if strings.Contains(v.StoreName, ".") { - v.StoreName = v.StoreName[0:strings.Index(v.StoreName, ".")] + v.StoreName[strings.Index(v.StoreName, ".")+1:len(v.StoreName)] - } - if shopDetailResult, err := api.JdShop2API.ShopDetail(v.StoreID); err == nil { - if store.Licence != "" { - data, _, _ := jxutils.DownloadFileByURL(store.Licence) - fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)] - url, _ := api.JdShop2API.UploadImageNew(data, fileName) - ex := store.LicenceExpire - if ex == "" { - ex = utils.Time2Str(utils.Str2Time(store.LicenceValid).AddDate(0, 6, 0)) - } - if !strings.Contains(ex, "00:00:00") { - ex += " 00:00:00" - } - err = api.JdShop2API.UpdateBasic(&jdshopapi.UpdateBasicParam{ - StoreID: v.StoreID, - StoreName: v.StoreName, - CategoryID2: 62, - Coordinate: shopDetailResult.Coordinate, - BussinessBeginTime: shopDetailResult.BussinessBeginTime, - BussinessEndTime: shopDetailResult.BussinessEndTime, - ImgURL: shopDetailResult.ImgURL, - StorePhone: shopDetailResult.StorePhone, - AddName: shopDetailResult.AddName, - AddCode1: shopDetailResult.AddCode1, - AddCode2: shopDetailResult.AddCode2, - AddCode3: shopDetailResult.AddCode3, - CategoryID1: 34, - QualificationRequests: []*jdshopapi.QualificationRequests{ - &jdshopapi.QualificationRequests{ - QualificationID: 41, - QualificationName: "营业执照", - QualificationNo: store.LicenceCode, - QualificationURL: url, - StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)), - EndingTime: ex, - Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex}, - }, - }, - }) - } - } - } - } + // if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie2", model.ConfigTypeCookie, ""); err == nil { + // api.JdShop2API.SetCookieWithStr(configs[0].Value) + // } + // for i := 1; i < 6; i++ { + // shopListResult, _ := api.JdShop2API.ShopList(i) + // for _, v := range shopListResult.List { + // var store *model.Store + // sql := ` + // SELECT a.* + // FROM store a + // JOIN store_map b ON a.id = b.store_id + // WHERE b.deleted_at = '1970-01-01 00:00:00' + // AND b.vendor_id = 5 + // AND b.vendor_store_id = ? + // AND b.vendor_org_code = 2 + // ` + // sqlParams := []interface{}{v.StoreID} + // err = dao.GetRow(dao.GetDB(), &store, sql, sqlParams) + // if strings.Contains(v.StoreName, "(") { + // v.StoreName = v.StoreName[0:strings.Index(v.StoreName, "(")] + v.StoreName[strings.Index(v.StoreName, ")")+3:len(v.StoreName)] + // } + // if strings.Contains(v.StoreName, ".") { + // v.StoreName = v.StoreName[0:strings.Index(v.StoreName, ".")] + v.StoreName[strings.Index(v.StoreName, ".")+1:len(v.StoreName)] + // } + // if shopDetailResult, err := api.JdShop2API.ShopDetail(v.StoreID); err == nil { + // if store.Licence != "" { + // data, _, _ := jxutils.DownloadFileByURL(store.Licence) + // fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)] + // url, _ := api.JdShop2API.UploadImageNew(data, fileName) + // ex := store.LicenceExpire + // if ex == "" { + // ex = utils.Time2Str(utils.Str2Time(store.LicenceValid).AddDate(0, 6, 0)) + // } + // if !strings.Contains(ex, "00:00:00") { + // ex += " 00:00:00" + // } + // err = api.JdShop2API.UpdateBasic(&jdshopapi.UpdateBasicParam{ + // StoreID: v.StoreID, + // StoreName: v.StoreName, + // CategoryID2: 62, + // Coordinate: shopDetailResult.Coordinate, + // BussinessBeginTime: shopDetailResult.BussinessBeginTime, + // BussinessEndTime: shopDetailResult.BussinessEndTime, + // ImgURL: shopDetailResult.ImgURL, + // StorePhone: shopDetailResult.StorePhone, + // AddName: shopDetailResult.AddName, + // AddCode1: shopDetailResult.AddCode1, + // AddCode2: shopDetailResult.AddCode2, + // AddCode3: shopDetailResult.AddCode3, + // CategoryID1: 34, + // QualificationRequests: []*jdshopapi.QualificationRequests{ + // &jdshopapi.QualificationRequests{ + // QualificationID: 41, + // QualificationName: "营业执照", + // QualificationNo: store.LicenceCode, + // QualificationURL: url, + // StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)), + // EndingTime: ex, + // Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex}, + // }, + // }, + // }) + // } + // } + // } + // } return err }