复制京东价格

This commit is contained in:
苏尹岚
2020-11-19 15:52:52 +08:00
parent f3bbb33c75
commit e25a6cf680

View File

@@ -10,11 +10,11 @@ import (
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin" "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/delivery"
"git.rosy.net.cn/jx-callback/business/partner/putils"
"github.com/360EntSecGroup-Skylar/excelize" "github.com/360EntSecGroup-Skylar/excelize"
"github.com/qiniu/api.v7/storage" "github.com/qiniu/api.v7/storage"
"git.rosy.net.cn/baseapi/platformapi/jdapi" "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/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/errlist" "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) { func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// var ( var (
// jdStoreIDs = []string{ jdStoreIDs = []string{"11734848"}
// "11734848", jdStoreIDxipu = "12005417"
// "11734850", skuMap = make(map[string]partner.StoreSkuInfo)
// "11734854", priceList = make(map[string][]*partner.StoreSkuInfo)
// "11734862", // statusList1 = make(map[string][]*partner.StoreSkuInfo)
// "11734868", // statusList2 = make(map[string][]*partner.StoreSkuInfo)
// "11734873", // stockList = make(map[string][]*partner.StoreSkuInfo)
// "11734874", vendorOrgCode = "320406"
// "11734886", // vendorOrgCode = "82029"
// "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"
// )
// handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler) handler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IPurchasePlatformStoreSkuHandler)
// multiHandler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IMultipleStoresHandler) multiHandler := partner.GetPurchasePlatformFromVendorID(model.VendorIDJD).(partner.IMultipleStoresHandler)
// allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "") allSkuNameInfoList, err := multiHandler.GetSkus(ctx, vendorOrgCode, 0, "")
// skuInfos := storeSkuFullList2BareFilter(allSkuNameInfoList) skuInfos := storeSkuFullList2BareFilter(allSkuNameInfoList)
// outStoreSkuList, err := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreIDxipu, skuInfos) outStoreSkuList, err := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreIDxipu, skuInfos)
// for _, vv := range outStoreSkuList { for _, vv := range outStoreSkuList {
// skuMap[vv.VendorSkuID] = *vv skuMap[vv.VendorSkuID] = *vv
// } }
// for _, jdStoreID := range jdStoreIDs { for _, jdStoreID := range jdStoreIDs {
// skuInfos2 := storeSkuFullList2BareFilter(allSkuNameInfoList) skuInfos2 := storeSkuFullList2BareFilter(allSkuNameInfoList)
// outStoreSkuList2, _ := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreID, skuInfos2) outStoreSkuList2, _ := handler.GetStoreSkusBareInfo(ctx, vendorOrgCode, nil, 0, jdStoreID, skuInfos2)
// for _, v := range outStoreSkuList2 { for _, v := range outStoreSkuList2 {
// v.VendorPrice = int64(math.Round(float64(v.VendorPrice) * 1.05)) a := skuMap[v.VendorSkuID]
// priceList[jdStoreID] = append(priceList[jdStoreID], v) if &a == nil {
// a := skuMap[v.VendorSkuID] continue
// if &a == nil { }
// continue if a.VendorPrice != v.VendorPrice {
// } v.VendorPrice = a.VendorPrice
// if a.VendorPrice != v.VendorPrice { priceList[jdStoreID] = append(priceList[jdStoreID], v)
// v.VendorPrice = a.VendorPrice }
// priceList[jdStoreID] = append(priceList[jdStoreID], v) // if a.Status != v.Status {
// } // v.Status = a.Status
// if a.Status != v.Status { // if v.Status == model.SkuStatusNormal {
// v.Status = a.Status // statusList1[jdStoreID] = append(statusList1[jdStoreID], v)
// if v.Status == model.SkuStatusNormal { // } else {
// statusList1[jdStoreID] = append(statusList1[jdStoreID], v) // statusList2[jdStoreID] = append(statusList2[jdStoreID], v)
// } else { // }
// statusList2[jdStoreID] = append(statusList2[jdStoreID], v) // }
// } // if a.Stock != v.Stock {
// } // v.Stock = a.Stock
// if a.Stock != v.Stock { // stockList[jdStoreID] = append(stockList[jdStoreID], v)
// 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) {
// task := tasksch.NewParallelTask("syncStoreSkuNew", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx, step := batchItemList[0].(int)
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { switch step {
// step := batchItemList[0].(int) case 0:
// switch step { if len(priceList) > 0 {
// case 0: for k, v := range priceList {
// if len(priceList) > 0 { _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
// for k, v := range priceList { failedList, err := handler.UpdateStoreSkusPrice(ctx, vendorOrgCode, 0, k, batchedStoreSkuList)
// _, err = putils.FreeBatchStoreSkuInfo("更新门店商品价格", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { if len(failedList) > 0 {
// failedList, err := handler.UpdateStoreSkusPrice(ctx, vendorOrgCode, 0, k, batchedStoreSkuList) task.AddFailedList(failedList)
// if len(failedList) > 0 { }
// task.AddFailedList(failedList) return nil, 1, err
// } }, ctx, task, v, 50, true)
// return nil, 1, err }
// }, ctx, task, v, 50, true) }
// } case 1:
// } // if len(statusList1) > 0 {
// case 1: // for k, v := range statusList1 {
// if len(statusList1) > 0 { // _, err = putils.FreeBatchStoreSkuInfo("更新门店商品状态", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
// for k, v := range statusList1 { // failedList, err := handler.UpdateStoreSkusStatus(ctx, vendorOrgCode, 0, k, batchedStoreSkuList, batchedStoreSkuList[0].Status)
// _, err = putils.FreeBatchStoreSkuInfo("更新门店商品状态", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { // if len(failedList) > 0 {
// failedList, err := handler.UpdateStoreSkusStatus(ctx, vendorOrgCode, 0, k, batchedStoreSkuList, batchedStoreSkuList[0].Status) // task.AddFailedList(failedList)
// if len(failedList) > 0 { // }
// task.AddFailedList(failedList) // return nil, 1, err
// } // }, ctx, task, v, 50, true)
// return nil, 1, err // }
// }, ctx, task, v, 50, true) // }
// } case 2:
// } case 3:
// case 2: // if len(stockList) > 0 {
// case 3: // for k, v := range stockList {
// if len(stockList) > 0 { // _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) {
// for k, v := range stockList { // failedList, err := handler.UpdateStoreSkusStock(ctx, vendorOrgCode, 0, k, batchedStoreSkuList)
// _, err = putils.FreeBatchStoreSkuInfo("更新门店商品库存", func(task tasksch.ITask, batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, successCount int, err error) { // if len(failedList) > 0 {
// failedList, err := handler.UpdateStoreSkusStock(ctx, vendorOrgCode, 0, k, batchedStoreSkuList) // task.AddFailedList(failedList)
// if len(failedList) > 0 { // }
// task.AddFailedList(failedList) // return nil, 1, err
// } // }, ctx, task, v, 50, true)
// return nil, 1, err // }
// }, ctx, task, v, 50, true) // }
// } }
// } return retVal, err
// } }, []int{0})
// return retVal, err tasksch.HandleTask(task, nil, true).Run()
// }, []int{0}) _, err = task.GetResult(0)
// tasksch.HandleTask(task, nil, true).Run()
// _, err = task.GetResult(0)
// var ( // var (
// storeMaps []*model.StoreMap // storeMaps []*model.StoreMap
// db = dao.GetDB() // db = dao.GetDB()
@@ -1724,72 +1669,72 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// JdsStreetName: v.JdsStreetName, // JdsStreetName: v.JdsStreetName,
// } // }
// dao.WrapAddIDCULDEntity(storeMap, "jxadmin") // dao.WrapAddIDCULDEntity(storeMap, "jxadmin")
if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie2", model.ConfigTypeCookie, ""); err == nil { // if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie2", model.ConfigTypeCookie, ""); err == nil {
api.JdShop2API.SetCookieWithStr(configs[0].Value) // api.JdShop2API.SetCookieWithStr(configs[0].Value)
} // }
for i := 1; i < 6; i++ { // for i := 1; i < 6; i++ {
shopListResult, _ := api.JdShop2API.ShopList(i) // shopListResult, _ := api.JdShop2API.ShopList(i)
for _, v := range shopListResult.List { // for _, v := range shopListResult.List {
var store *model.Store // var store *model.Store
sql := ` // sql := `
SELECT a.* // SELECT a.*
FROM store a // FROM store a
JOIN store_map b ON a.id = b.store_id // JOIN store_map b ON a.id = b.store_id
WHERE b.deleted_at = '1970-01-01 00:00:00' // WHERE b.deleted_at = '1970-01-01 00:00:00'
AND b.vendor_id = 5 // AND b.vendor_id = 5
AND b.vendor_store_id = ? // AND b.vendor_store_id = ?
AND b.vendor_org_code = 2 // AND b.vendor_org_code = 2
` // `
sqlParams := []interface{}{v.StoreID} // sqlParams := []interface{}{v.StoreID}
err = dao.GetRow(dao.GetDB(), &store, sql, sqlParams) // err = dao.GetRow(dao.GetDB(), &store, sql, sqlParams)
if strings.Contains(v.StoreName, "") { // if strings.Contains(v.StoreName, "") {
v.StoreName = v.StoreName[0:strings.Index(v.StoreName, "")] + v.StoreName[strings.Index(v.StoreName, "")+3:len(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, ".") { // if strings.Contains(v.StoreName, ".") {
v.StoreName = v.StoreName[0:strings.Index(v.StoreName, ".")] + v.StoreName[strings.Index(v.StoreName, ".")+1:len(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 shopDetailResult, err := api.JdShop2API.ShopDetail(v.StoreID); err == nil {
if store.Licence != "" { // if store.Licence != "" {
data, _, _ := jxutils.DownloadFileByURL(store.Licence) // data, _, _ := jxutils.DownloadFileByURL(store.Licence)
fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)] // fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)]
url, _ := api.JdShop2API.UploadImageNew(data, fileName) // url, _ := api.JdShop2API.UploadImageNew(data, fileName)
ex := store.LicenceExpire // ex := store.LicenceExpire
if ex == "" { // if ex == "" {
ex = utils.Time2Str(utils.Str2Time(store.LicenceValid).AddDate(0, 6, 0)) // ex = utils.Time2Str(utils.Str2Time(store.LicenceValid).AddDate(0, 6, 0))
} // }
if !strings.Contains(ex, "00:00:00") { // if !strings.Contains(ex, "00:00:00") {
ex += " 00:00:00" // ex += " 00:00:00"
} // }
err = api.JdShop2API.UpdateBasic(&jdshopapi.UpdateBasicParam{ // err = api.JdShop2API.UpdateBasic(&jdshopapi.UpdateBasicParam{
StoreID: v.StoreID, // StoreID: v.StoreID,
StoreName: v.StoreName, // StoreName: v.StoreName,
CategoryID2: 62, // CategoryID2: 62,
Coordinate: shopDetailResult.Coordinate, // Coordinate: shopDetailResult.Coordinate,
BussinessBeginTime: shopDetailResult.BussinessBeginTime, // BussinessBeginTime: shopDetailResult.BussinessBeginTime,
BussinessEndTime: shopDetailResult.BussinessEndTime, // BussinessEndTime: shopDetailResult.BussinessEndTime,
ImgURL: shopDetailResult.ImgURL, // ImgURL: shopDetailResult.ImgURL,
StorePhone: shopDetailResult.StorePhone, // StorePhone: shopDetailResult.StorePhone,
AddName: shopDetailResult.AddName, // AddName: shopDetailResult.AddName,
AddCode1: shopDetailResult.AddCode1, // AddCode1: shopDetailResult.AddCode1,
AddCode2: shopDetailResult.AddCode2, // AddCode2: shopDetailResult.AddCode2,
AddCode3: shopDetailResult.AddCode3, // AddCode3: shopDetailResult.AddCode3,
CategoryID1: 34, // CategoryID1: 34,
QualificationRequests: []*jdshopapi.QualificationRequests{ // QualificationRequests: []*jdshopapi.QualificationRequests{
&jdshopapi.QualificationRequests{ // &jdshopapi.QualificationRequests{
QualificationID: 41, // QualificationID: 41,
QualificationName: "营业执照", // QualificationName: "营业执照",
QualificationNo: store.LicenceCode, // QualificationNo: store.LicenceCode,
QualificationURL: url, // QualificationURL: url,
StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)), // StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)),
EndingTime: ex, // EndingTime: ex,
Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex}, // Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex},
}, // },
}, // },
}) // })
} // }
} // }
} // }
} // }
return err return err
} }