This commit is contained in:
苏尹岚
2020-12-04 09:29:13 +08:00
parent 503d91b3fa
commit 6ae6d067b4

View File

@@ -14,7 +14,6 @@ import (
"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"
@@ -1593,125 +1592,127 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// }, []int{0})
// tasksch.HandleTask(task, nil, true).Run()
// _, err = task.GetResult(0)
var (
storeMaps []*model.StoreMap
db = dao.GetDB()
)
if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie2", model.ConfigTypeCookie, ""); err == nil {
api.JdShop2API.SetCookieWithStr(configs[0].Value)
}
sql := `
SELECT * from store_map where vendor_id = 5 and deleted_at = '1970-01-01 00:00:00' and vendor_org_code = 2 and store_id <> 667281
AND store_id <> 100000
AND store_id <> 102919
AND LENGTH(vendor_store_id) < 9
`
err = dao.GetRows(db, &storeMaps, sql, nil)
for _, v := range storeMaps {
store, _ := dao.GetStoreDetail(db, v.StoreID, model.VendorIDJDShop, "2")
err = api.JdShop2API.DeleteStoresByID(utils.Str2Int64(store.VendorStoreID))
time.Sleep(time.Second)
data, _, _ := jxutils.DownloadFileByURL(jdshopapi.JdsStoreImg)
url, _ := api.JdShop2API.UploadImageNew(data, "2659335b16e3880e367759b8fc675933.tem.png")
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"
}
var url2 string
if store.Licence != "" {
data2, _, _ := jxutils.DownloadFileByURL(store.Licence)
fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)]
url2, _ = api.JdShop2API.UploadImageNew(data2, fileName)
}
storeName := store.Name
if strings.Contains(storeName, "") {
storeName = storeName[0:strings.Index(storeName, "")] + storeName[strings.Index(storeName, "")+3:len(storeName)]
}
if strings.Contains(storeName, "(") {
storeName = storeName[0:strings.Index(storeName, "(")] + storeName[strings.Index(storeName, ")")+3:len(storeName)]
}
if strings.Contains(storeName, ".") {
storeName = strings.ReplaceAll(storeName, ".", "")
}
if strings.Contains(storeName, "-") {
storeName = strings.ReplaceAll(storeName, "-", "")
}
if strings.Contains(storeName, " ") {
storeName = strings.ReplaceAll(storeName, " ", "")
}
storeName = "京西菜市" + strings.ReplaceAll(storeName, "店", "") + "生鲜店"
if len(storeName) > 30 {
storeName = utils.LimitUTF8StringLen2(storeName, 30)
}
param := &jdshopapi.UpdateBasicParam{
StoreName: storeName,
CategoryID2: 4,
Coordinate: utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lat)) + "," + utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lng)),
BussinessBeginTime: int2TimeStr(int(store.OpenTime1)),
BussinessEndTime: int2TimeStr(int(store.CloseTime1)),
ImgURL: url,
StorePhone: store.Tel1,
AddName: store.Address,
AddCode3: store.JdsCode,
CategoryID1: 3,
}
if url2 != "" {
param.CategoryID1 = 34
param.CategoryID2 = 62
param.QualificationRequests = []*jdshopapi.QualificationRequests{
&jdshopapi.QualificationRequests{
QualificationID: 41,
QualificationName: "营业执照",
QualificationNo: store.LicenceCode,
QualificationURL: url2,
StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)),
EndingTime: ex,
Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex},
},
}
}
if store.JdsStreetCode != 0 {
param.AddCode3 = store.JdsStreetCode
}
if param.AddCode3 == 0 {
param.AddCode3 = store.JdCode
}
//证明这个店可能隶属直辖市或者东莞
if model.ZXCityCodeMap[store.CityCode] != "" {
result, _ := api.AutonaviAPI.GetCoordinateAreaInfo(jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat))
if result["regeocode"] != nil {
street := result["regeocode"].(map[string]interface{})["addressComponent"].(map[string]interface{})["township"].(string)
if street != "" {
result1, _ := api.JdShopAPI.GetProvince()
for _, v := range result1 {
if strings.Contains(store.CityName, v.AreaName) {
result2, _ := api.JdShopAPI.GetCity(v.AreaID)
for _, vv := range result2 {
if strings.Contains(store.DistrictName, vv.AreaName) {
result3, _ := api.JdShopAPI.GetCounty(vv.AreaID)
for _, vvv := range result3 {
if street == vvv.AreaName {
param.AddCode3 = vvv.AreaID
break
}
}
}
}
}
}
}
}
}
if vendorStroeID, err := api.JdShop2API.SubmitBasic(param); err == nil {
v.VendorStoreID = utils.Int64ToStr(vendorStroeID)
dao.UpdateEntity(db, v, "VendorStoreID")
time.Sleep(time.Second)
err = api.JdShop2API.UpdateExpand(int(vendorStroeID))
}
}
//建店
// var (
// storeMaps []*model.StoreMap
// db = dao.GetDB()
// )
// if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie2", model.ConfigTypeCookie, ""); err == nil {
// api.JdShop2API.SetCookieWithStr(configs[0].Value)
// }
// sql := `
// SELECT * from store_map where vendor_id = 5 and deleted_at = '1970-01-01 00:00:00' and vendor_org_code = 2 and store_id <> 667281
// AND store_id <> 100000
// AND store_id <> 102919
// AND LENGTH(vendor_store_id) < 9
// `
// err = dao.GetRows(db, &storeMaps, sql, nil)
// for _, v := range storeMaps {
// store, _ := dao.GetStoreDetail(db, v.StoreID, model.VendorIDJDShop, "2")
// err = api.JdShop2API.DeleteStoresByID(utils.Str2Int64(store.VendorStoreID))
// time.Sleep(time.Second)
// data, _, _ := jxutils.DownloadFileByURL(jdshopapi.JdsStoreImg)
// url, _ := api.JdShop2API.UploadImageNew(data, "2659335b16e3880e367759b8fc675933.tem.png")
// 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"
// }
// var url2 string
// if store.Licence != "" {
// data2, _, _ := jxutils.DownloadFileByURL(store.Licence)
// fileName := store.Licence[strings.LastIndex(store.Licence, "/")+1 : len(store.Licence)]
// url2, _ = api.JdShop2API.UploadImageNew(data2, fileName)
// }
// storeName := store.Name
// if strings.Contains(storeName, "") {
// storeName = storeName[0:strings.Index(storeName, "")] + storeName[strings.Index(storeName, "")+3:len(storeName)]
// }
// if strings.Contains(storeName, "(") {
// storeName = storeName[0:strings.Index(storeName, "(")] + storeName[strings.Index(storeName, ")")+3:len(storeName)]
// }
// if strings.Contains(storeName, ".") {
// storeName = strings.ReplaceAll(storeName, ".", "")
// }
// if strings.Contains(storeName, "-") {
// storeName = strings.ReplaceAll(storeName, "-", "")
// }
// if strings.Contains(storeName, " ") {
// storeName = strings.ReplaceAll(storeName, " ", "")
// }
// storeName = "京西菜市" + strings.ReplaceAll(storeName, "店", "") + "生鲜店"
// if len(storeName) > 30 {
// storeName = utils.LimitUTF8StringLen2(storeName, 30)
// }
// param := &jdshopapi.UpdateBasicParam{
// StoreName: storeName,
// CategoryID2: 4,
// Coordinate: utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lat)) + "," + utils.Float64ToStr(jxutils.IntCoordinate2Standard(store.Lng)),
// BussinessBeginTime: int2TimeStr(int(store.OpenTime1)),
// BussinessEndTime: int2TimeStr(int(store.CloseTime1)),
// ImgURL: url,
// StorePhone: store.Tel1,
// AddName: store.Address,
// AddCode3: store.JdsCode,
// CategoryID1: 3,
// }
// if url2 != "" {
// param.CategoryID1 = 34
// param.CategoryID2 = 62
// param.QualificationRequests = []*jdshopapi.QualificationRequests{
// &jdshopapi.QualificationRequests{
// QualificationID: 41,
// QualificationName: "营业执照",
// QualificationNo: store.LicenceCode,
// QualificationURL: url2,
// StartTime: utils.Time2Str(utils.Str2Time(store.LicenceValid)),
// EndingTime: ex,
// Time: []string{utils.Time2Str(utils.Str2Time(store.LicenceValid)), ex},
// },
// }
// }
// if store.JdsStreetCode != 0 {
// param.AddCode3 = store.JdsStreetCode
// }
// if param.AddCode3 == 0 {
// param.AddCode3 = store.JdCode
// }
// //证明这个店可能隶属直辖市或者东莞
// if model.ZXCityCodeMap[store.CityCode] != "" {
// result, _ := api.AutonaviAPI.GetCoordinateAreaInfo(jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat))
// if result["regeocode"] != nil {
// street := result["regeocode"].(map[string]interface{})["addressComponent"].(map[string]interface{})["township"].(string)
// if street != "" {
// result1, _ := api.JdShopAPI.GetProvince()
// for _, v := range result1 {
// if strings.Contains(store.CityName, v.AreaName) {
// result2, _ := api.JdShopAPI.GetCity(v.AreaID)
// for _, vv := range result2 {
// if strings.Contains(store.DistrictName, vv.AreaName) {
// result3, _ := api.JdShopAPI.GetCounty(vv.AreaID)
// for _, vvv := range result3 {
// if street == vvv.AreaName {
// param.AddCode3 = vvv.AreaID
// break
// }
// }
// }
// }
// }
// }
// }
// }
// }
// if vendorStroeID, err := api.JdShop2API.SubmitBasic(param); err == nil {
// v.VendorStoreID = utils.Int64ToStr(vendorStroeID)
// dao.UpdateEntity(db, v, "VendorStoreID")
// time.Sleep(time.Second)
// err = api.JdShop2API.UpdateExpand(int(vendorStroeID))
// }
// }
//分类
// var (
// db = dao.GetDB()
// )
@@ -1744,33 +1745,57 @@ func UploadJdsImage(ctx *jxcontext.Context) (err error) {
// }
// }
// }
// var (
// db = dao.GetDB()
// )
// storeSkus, _ := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID2}, nil)
// for _, v := range storeSkus {
// if v.JdsID != 0 {
// if err = api.JdShop2API.StoreSkuBindStore(false, []string{utils.Int64ToStr(v.JdsID)}, []string{"1000063128"}); err == nil {
// storeSkus2, _ := dao.GetStoresSkusInfo(db, []int{667281}, []int{v.SkuID})
// if len(storeSkus2) > 0 {
// status := storeSkus2[0].Status
// stock := storeSkus2[0].Stock
// price := storeSkus2[0].Price
// if status == model.StoreSkuBindStatusNormal {
// api.JdShop2API.StoreWareDoUpdate(status, v.JdsID, "1000063128")
// }
// if stock != 0 {
// api.JdShop2API.StoreUpdateStock(stock, v.JdsID, "1000063128")
// }
// api.JdShop2API.StoreUpdatePrice(utils.Float64ToStr(jxutils.IntPrice2Standard(int64(price))), v.JdsID, "1000063128")
// } else {
// continue
// }
// }
// } else {
// continue
// }
// }
//门店建商品
var (
db = dao.GetDB()
storeMaps []*model.StoreMap
)
sql := `
SELECT *
FROM store_map
WHERE vendor_id = 5
AND deleted_at = '1970-01-01 00:00:00'
AND vendor_org_code = 2
AND store_id <> 667281
AND store_id <> 100000
AND store_id <> 102919
AND store_id = 103075
`
err = dao.GetRows(db, &storeMaps, sql, nil)
storeSkus, _ := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID2}, nil)
task := tasksch.NewParallelTask("京东商城门店建商品1", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
func(task2 *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
v := batchItemList[0].(*model.StoreSkuBind)
if v.JdsID != 0 {
task := tasksch.NewParallelTask("京东商城门店建商品2", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(true), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if err = api.JdShop2API.StoreSkuBindStore(false, []string{utils.Int64ToStr(v.JdsID)}, []string{storeMap.VendorStoreID}); err == nil {
storeSkus2, _ := dao.GetStoresSkusInfo(db, []int{storeMap.StoreID}, []int{v.SkuID})
if len(storeSkus2) > 0 {
status := storeSkus2[0].Status
stock := storeSkus2[0].Stock
price := storeSkus2[0].Price
if status == model.StoreSkuBindStatusNormal {
api.JdShop2API.StoreWareDoUpdate(status, v.JdsID, storeMap.VendorStoreID)
}
if stock != 0 {
api.JdShop2API.StoreUpdateStock(stock, v.JdsID, storeMap.VendorStoreID)
}
api.JdShop2API.StoreUpdatePrice(utils.Float64ToStr(jxutils.IntPrice2Standard(int64(price))), v.JdsID, storeMap.VendorStoreID)
} else {
return retVal, err
}
}
return retVal, err
}, storeMaps)
tasksch.HandleTask(task, task2, true).Run()
_, err = task.GetResult(0)
}
return retVal, err
}, storeSkus)
tasksch.HandleTask(task, nil, true).Run()
_, err = task.GetResult(0)
return err
}