- 饿百与京东拉门店数据基本OK

This commit is contained in:
gazebo
2019-06-24 21:43:20 +08:00
parent 3fed4d3af9
commit dd92bb99f5
14 changed files with 408 additions and 173 deletions

View File

@@ -2,8 +2,6 @@ package misc
import (
"fmt"
"math"
"strconv"
"strings"
"time"
@@ -16,15 +14,8 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
type CityCenter struct {
Lng float64
Lat float64
CityName string
}
func StartRefreshEbaiRealMobile() {
if globals.ReallyCallPlatformAPI {
utils.AfterFuncWithRecover(5*time.Second, func() {
@@ -88,147 +79,6 @@ func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime ti
return hint, err
}
func StartGetCityStoreInfo() {
cityCenters := make([]*CityCenter, 0)
guiyang := &CityCenter{
Lng: 106.713478,
Lat: 26.578343,
CityName: "贵阳市",
}
cityCenters = append(cityCenters, guiyang)
GetCityStoreInfo(cityCenters)
}
func GetCityStoreInfo(cityCenters []*CityCenter) {
utils.CallFuncAsync(func() {
for i := 0; i < len(cityCenters); i++ {
cityCenter := cityCenters[i]
cityPoints := GetCityPoints(cityCenter.Lng, cityCenter.Lat, cityCenter.CityName)
for j := 0; j < len(cityPoints); j++ {
point := cityPoints[j]
SaveJdPointsStores(point)
SaveEbaiPointsStores(point)
}
}
})
}
func SaveJdPointsStores(point []string) {
retVal, err := api.JdAPI.GetStoreList(point[0], point[1])
if err == nil {
retVal2 := retVal["data"].(map[string]interface{})
storeList := retVal2["data"].([]interface{})
for _, x := range storeList {
xMap := x.(map[string]interface{})
floorCellData := xMap["floorCellData"].(map[string]interface{})
storeId := floorCellData["storeId"].(string)
sql := `
SELECT *
FROM store_info
WHERE vendor_id = ? AND vendor_store_id = ?
`
sqlParams := []interface{}{
model.VendorIDJD,
storeId,
}
var storeList []*model.StoreInfo
db := dao.GetDB()
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil && len(storeList) == 0 {
SaveJdStoreInfo(storeId, point[2])
}
}
}
}
func SaveJdStoreInfo(storeId, cityName string) {
retVal, err := api.JdAPI.GetStoreInfo(storeId)
if err == nil {
store := retVal["storeInfo"].(map[string]interface{})
storeCommentVO := retVal["storeCommentVO"].(map[string]interface{})
storeInfo := &model.StoreInfo{
VendorID: model.VendorIDJD,
VendorStoreID: utils.Interface2String(store["storeId"]),
CityName: cityName,
StoreName: utils.Interface2String(store["storeName"]),
Address: utils.Interface2String(store["storeAddress"]),
ShopScore: utils.Interface2Float64WithDefault(storeCommentVO["scoreAvg"], 0),
Tel: utils.Interface2String(store["storeTel"]),
RecentOrderNum: utils.Interface2String(store["monthSaleNum"]),
SkuCount: utils.Interface2String(store["inSaleNum"]),
BusinessType: utils.Interface2String(store["industry"]),
}
db := dao.GetDB()
dao.CreateEntity(db, storeInfo)
}
}
func SaveEbaiPointsStores(point []string) {
retVal, err := api.EbaiAPI.GetStoreList(point[0], point[1])
if err == nil {
storeList := retVal["shop_list"].([]interface{})
for _, x := range storeList {
xMap := x.(map[string]interface{})
shopInfo := xMap["shop_info"].(map[string]interface{})
storeId := shopInfo["wid"].(string)
sql := `
SELECT *
FROM store_info
WHERE vendor_id = ? AND vendor_store_id = ?
`
sqlParams := []interface{}{
model.VendorIDEBAI,
storeId,
}
var storeList []*model.StoreInfo
db := dao.GetDB()
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil && len(storeList) == 0 {
SaveEbaiStoreInfo(storeId, point[2])
}
}
}
}
func SaveEbaiStoreInfo(storeId, cityName string) {
store, err := api.EbaiAPI.GetStoreInfo(storeId)
if err == nil {
storeInfo := &model.StoreInfo{
VendorID: model.VendorIDEBAI,
VendorStoreID: utils.Interface2String(store["shop_id"]),
CityName: cityName,
}
if store["storeIsUnderfind"] == nil {
storeInfo.StoreName = utils.Interface2String(store["name"])
storeInfo.Address = utils.Interface2String(store["address"])
storeInfo.ShopScore = utils.Interface2Float64WithDefault(store["shop_score"], 0)
storeInfo.Tel = utils.Interface2String(store["phone"])
storeInfo.RecentOrderNum = utils.Int64ToStr(utils.Interface2Int64WithDefault(store["recent_order_num"], 0))
storeInfo.SkuCount = utils.Int64ToStr(utils.Interface2Int64WithDefault(store["sku_count"], 0))
storeInfo.BusinessType = utils.Interface2String(store["category"])
}
db := dao.GetDB()
dao.CreateEntity(db, storeInfo)
}
}
func GetCityPoints(lng float64, lat float64, cityName string) (cityPoints [][]string) {
oneDu := 111319.55
for a := 0; a <= 80; a++ {
distance := float64(a*2000 - 80000)
angle := float64(math.Pi / 2)
newLng := strconv.FormatFloat(lng+(distance*math.Sin(angle*math.Pi/180))/(oneDu*math.Cos(lat*math.Pi/180)), 'f', -1, 64)
for b := 0; b <= 80; b++ {
distance2 := float64(b*2000 - 80000)
angle2 := float64(0)
newLat := strconv.FormatFloat(lat+(distance2*math.Cos(angle2*math.Pi/180))/oneDu, 'f', -1, 64)
point := make([]string, 0)
point = append(point, newLng)
point = append(point, newLat)
point = append(point, cityName)
cityPoints = append(cityPoints, point)
}
}
return cityPoints
}
func StartDailyWork() {
if globals.ReallyCallPlatformAPI {
now := time.Now()