- 饿百与京东拉门店数据基本OK
This commit is contained in:
@@ -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()
|
||||
|
||||
100
business/jxutils/ditu/ditu.go
Normal file
100
business/jxutils/ditu/ditu.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package ditu
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
const (
|
||||
keyMultiple = 1000000
|
||||
)
|
||||
|
||||
type Coordinate struct {
|
||||
Lng float64
|
||||
Lat float64
|
||||
}
|
||||
|
||||
func roundCoordinate(lng, lat float64, roundLng, roundLat int) (lng2, lat2 int) {
|
||||
lng2 = jxutils.StandardCoordinate2Int(lng+jxutils.IntCoordinate2Standard(roundLng)/2) / roundLng * roundLng
|
||||
lat2 = jxutils.StandardCoordinate2Int(lat+jxutils.IntCoordinate2Standard(roundLat)/2) / roundLat * roundLat
|
||||
return lng2, lat2
|
||||
}
|
||||
|
||||
func (c *Coordinate) GetMapKey() int64 {
|
||||
return int64(c.Lng*keyMultiple*keyMultiple + c.Lat*keyMultiple)
|
||||
}
|
||||
|
||||
func GetRound4Radius(lng, lat float64, gridWith int) (roundLng, roundLat int) {
|
||||
lng2, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(gridWith), 90)
|
||||
_, lat2 := jxutils.ConvertDistanceToLogLat(lng, lat, float64(gridWith), 0)
|
||||
// globals.SugarLogger.Debugf("GetRound4Radius gridWith:%d, lng:%f, lat:%f, lng2:%f, lat2:%f", gridWith, lng, lat, lng2, lat2)
|
||||
return jxutils.StandardCoordinate2Int(math.Abs(lng2 - lng)), jxutils.StandardCoordinate2Int(math.Abs(lat2 - lat))
|
||||
}
|
||||
|
||||
func GetGridsFromCoordinate(lng, lat float64, radius int, roundLng, roundLat int) (coordList []*Coordinate) {
|
||||
beginLng, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(radius), 270)
|
||||
_, beginLat := jxutils.ConvertDistanceToLogLat(lng, lat, float64(radius), 180)
|
||||
intBeginLng, intBeginLat := roundCoordinate(beginLng, beginLat, roundLng, roundLat)
|
||||
|
||||
endLng, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(radius), 90)
|
||||
_, endLat := jxutils.ConvertDistanceToLogLat(lng, lat, float64(radius), 0)
|
||||
intEndLng, intEndLat := roundCoordinate(endLng, endLat, roundLng, roundLat)
|
||||
|
||||
for intLng := intBeginLng; intLng <= intEndLng; intLng += roundLng {
|
||||
for intLat := intBeginLat; intLat <= intEndLat; intLat += roundLat {
|
||||
coordList = append(coordList, &Coordinate{
|
||||
Lng: jxutils.IntCoordinate2Standard(intLng),
|
||||
Lat: jxutils.IntCoordinate2Standard(intLat),
|
||||
})
|
||||
}
|
||||
}
|
||||
return coordList
|
||||
}
|
||||
|
||||
func GetDistrictCoordinateList(districtCode int, radius, gridWith int) (coordList []*Coordinate) {
|
||||
districts, err := api.AutonaviAPI.GetDistricts(0, utils.Int2Str(districtCode))
|
||||
if err == nil {
|
||||
if len(districts) > 0 {
|
||||
roundLng, roundLat := GetRound4Radius(districts[0].Lng, districts[0].Lat, gridWith)
|
||||
for _, district := range districts {
|
||||
coordList = append(coordList, GetGridsFromCoordinate(district.Lng, district.Lat, radius, roundLng, roundLat)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
return coordList
|
||||
}
|
||||
|
||||
func GetCityCoordinateList(cityCode int, radius, gridWith int) (coordList []*Coordinate) {
|
||||
districts, err := api.AutonaviAPI.GetDistricts(1, utils.Int2Str(cityCode))
|
||||
if err == nil {
|
||||
coordMap := make(map[int64]*Coordinate)
|
||||
if len(districts) > 0 {
|
||||
roundLng, roundLat := GetRound4Radius(districts[0].Lng, districts[0].Lat, gridWith)
|
||||
for _, district := range districts {
|
||||
nextLevelAllFailed := true // 表示下级行政区的中心坐标都拿不到
|
||||
for _, v := range district.Districts {
|
||||
if v.Lng > 0 && v.Lat > 0 {
|
||||
// nextLevelAllFailed = false
|
||||
coordList := GetGridsFromCoordinate(v.Lng, v.Lat, radius, roundLng, roundLat)
|
||||
for _, coord := range coordList {
|
||||
coordMap[coord.GetMapKey()] = coord
|
||||
}
|
||||
}
|
||||
}
|
||||
if nextLevelAllFailed {
|
||||
coordList := GetGridsFromCoordinate(district.Lng, district.Lat, radius*3, roundLng, roundLat)
|
||||
for _, coord := range coordList {
|
||||
coordMap[coord.GetMapKey()] = coord
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, coord := range coordMap {
|
||||
coordList = append(coordList, coord)
|
||||
}
|
||||
}
|
||||
return coordList
|
||||
}
|
||||
26
business/jxutils/ditu/ditu_test.go
Normal file
26
business/jxutils/ditu/ditu_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package ditu
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
}
|
||||
|
||||
func TestGetCityCoordinateLists(t *testing.T) {
|
||||
coords := GetCityCoordinateList(110100, 5*1000, 2*1000)
|
||||
// coords := GetDistrictCoordinateLists(510105, 10*1000, 2*1000)
|
||||
t.Log(len(coords))
|
||||
// t.Log(utils.Format4Output(coords, false))
|
||||
var list []map[string]interface{}
|
||||
for _, v := range coords {
|
||||
list = append(list, map[string]interface{}{
|
||||
"position": []float64{v.Lng, v.Lat},
|
||||
})
|
||||
}
|
||||
t.Log(utils.Format4Output(list, true))
|
||||
}
|
||||
38
business/model/net_spider.go
Normal file
38
business/model/net_spider.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
type PageShop struct {
|
||||
ModelIDCULD
|
||||
|
||||
Name string `orm:"size(255)" json:"name"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||
OrgCode string `orm:"size(255)" json:"orgCode"`
|
||||
VendorStatus string `orm:"size(48)" json:"vendorStatus"`
|
||||
Status int `json:"status"` // 取值同Store.Status
|
||||
|
||||
CityCode int `orm:"default(0)" json:"cityCode"` // todo ?
|
||||
DistrictCode int `orm:"default(0)" json:"districtCode"` // todo ?
|
||||
Address string `orm:"size(255)" json:"address"`
|
||||
Lng float64 `json:"lng"`
|
||||
Lat float64 `json:"lat"`
|
||||
|
||||
Tel1 string `orm:"size(32);index" json:"tel1"`
|
||||
Tel2 string `orm:"size(32);index" json:"tel2"`
|
||||
|
||||
ShopScore float32 `json:"shopScore"` // 店铺评分
|
||||
RecentOrderNum int `orm:"size(48)" json:"recentOrderNum"` // 月订单量
|
||||
SkuCount int `orm:"size(48)" json:"skuCount"` // 商品总量
|
||||
BusinessType string `orm:"size(48)" json:"businessType"` // 经营范围
|
||||
}
|
||||
|
||||
func (*PageShop) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorStoreID", "VendorID"},
|
||||
}
|
||||
}
|
||||
|
||||
func (*PageShop) TableIndex() [][]string {
|
||||
return [][]string{
|
||||
[]string{"Tel1"},
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package model
|
||||
|
||||
type StoreInfo struct {
|
||||
ID int64 `orm:"column(id)" json:"id"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"` // 平台
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` // 店铺ID
|
||||
CityName string `orm:"size(48)" json:"cityName"` // 店铺所在城市
|
||||
StoreName string `orm:"size(48)" json:"storeName"` // 店铺名称
|
||||
Address string `orm:"size(255)" json:"address"` // 店铺地址
|
||||
ShopScore float64 `json:"shopScore"` // 店铺评分
|
||||
Tel string `orm:"size(48)" json:"tel"` // 店铺电话
|
||||
RecentOrderNum string `orm:"size(48)" json:"recentOrderNum"` // 月订单量
|
||||
SkuCount string `orm:"size(48)" json:"skuCount"` // 商品总量
|
||||
BusinessType string `orm:"size(48)" json:"businessType"` // 经营范围
|
||||
}
|
||||
|
||||
func (o *StoreInfo) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"VendorStoreID", "VendorID"},
|
||||
}
|
||||
}
|
||||
86
business/netspider/netspider.go
Normal file
86
business/netspider/netspider.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package netspider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
func GetCityShops(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs []int, cityCode, radius, gridWith int) (pageStoreList []*model.PageShop, err error) {
|
||||
coordList := ditu.GetCityCoordinateList(cityCode, radius, gridWith)
|
||||
if len(coordList) > 0 {
|
||||
task := tasksch.NewParallelTask("GetCityShops", nil, ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
vendorID := batchItemList[0].(int)
|
||||
storeList, err2 := getStoreListByCoordinates(ctx, task, vendorID, utils.Int2Str(cityCode), coordList)
|
||||
if err = err2; err == nil {
|
||||
retVal = storeList
|
||||
}
|
||||
return retVal, err
|
||||
}, vendorIDs)
|
||||
tasksch.AddChild(parentTask, task).Run()
|
||||
list, err2 := task.GetResult(0)
|
||||
if err = err2; err != nil && len(list) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range list {
|
||||
v2 := v.(*model.PageShop)
|
||||
v2.CityCode = cityCode
|
||||
dao.WrapAddIDCULDEntity(v, ctx.GetUserName())
|
||||
pageStoreList = append(pageStoreList, v.(*model.PageShop))
|
||||
}
|
||||
}
|
||||
return pageStoreList, err
|
||||
}
|
||||
|
||||
func getStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, cityInfo string, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error) {
|
||||
if handler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformNetSpiderHandler); handler != nil {
|
||||
task1 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get list", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
pos := batchItemList[0].(*ditu.Coordinate)
|
||||
storeIDList, err := handler.GetStoreIDListByCoordinates(ctx, pos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return storeIDList, nil
|
||||
}, coordList)
|
||||
tasksch.AddChild(parentTask, task1).Run()
|
||||
fullStoreIDs, err2 := task1.GetResult(0)
|
||||
if err = err2; err != nil && len(fullStoreIDs) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
storeIDMap := make(map[string]int)
|
||||
for _, v := range fullStoreIDs {
|
||||
storeIDMap[v.(string)] = 1
|
||||
}
|
||||
var storeIDs []string
|
||||
for storeID := range storeIDMap {
|
||||
storeIDs = append(storeIDs, storeID)
|
||||
}
|
||||
|
||||
task2 := tasksch.NewParallelTask(fmt.Sprintf("GetStoreListByCoordinate[%s] get detail", model.VendorChineseNames[vendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeID := batchItemList[0].(string)
|
||||
storePageInfo, err := handler.GetStorePageInfo(ctx, cityInfo, storeID)
|
||||
if err == nil && storePageInfo != nil {
|
||||
return []interface{}{storePageInfo}, nil
|
||||
}
|
||||
return nil, err
|
||||
}, storeIDs)
|
||||
tasksch.AddChild(parentTask, task2).Run()
|
||||
shopList, err2 := task2.GetResult(0)
|
||||
if err = err2; err != nil && len(shopList) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range shopList {
|
||||
storeList = append(storeList, v.(*model.PageShop))
|
||||
}
|
||||
}
|
||||
return storeList, err
|
||||
}
|
||||
41
business/netspider/netspider_test.go
Normal file
41
business/netspider/netspider_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package netspider
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
|
||||
_ "git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
"git.rosy.net.cn/jx-callback/globals/testinit"
|
||||
)
|
||||
|
||||
func init() {
|
||||
testinit.Init()
|
||||
}
|
||||
|
||||
func TestGetStoreListByCoordinate(t *testing.T) {
|
||||
storeList, err := getStoreListByCoordinates(jxcontext.AdminCtx, nil, 3, "成都",
|
||||
[]*ditu.Coordinate{
|
||||
&ditu.Coordinate{
|
||||
Lng: 104.057218,
|
||||
Lat: 30.6949,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(storeList, false))
|
||||
t.Log(len(storeList))
|
||||
}
|
||||
|
||||
func TestGetCityShops(t *testing.T) {
|
||||
shopList, err := GetCityShops(jxcontext.AdminCtx, nil, []int{0, 3}, 510100, 5000, 3000)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(shopList, false))
|
||||
t.Log(len(shopList))
|
||||
}
|
||||
14
business/partner/partner_spider.go
Normal file
14
business/partner/partner_spider.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package partner
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
type IPurchasePlatformNetSpiderHandler interface {
|
||||
GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error)
|
||||
GetStorePageInfo(ctx *jxcontext.Context, cityInfo, storeID string) (storePageInfo *model.PageShop, err error)
|
||||
|
||||
// GetStoreListByCoordinates(ctx *jxcontext.Context, parentTask tasksch.ITask, cityInfo string, coordList []*ditu.Coordinate) (storeList []*model.PageShop, err error)
|
||||
}
|
||||
49
business/partner/purchase/ebai/net_spider.go
Normal file
49
business/partner/purchase/ebai/net_spider.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package ebai
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) {
|
||||
shopListInfo, err := api.EbaiAPI.GetStoreList2(coord.Lng, coord.Lat)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shopListInfo != nil {
|
||||
for _, v := range shopListInfo.ShopList {
|
||||
storeIDList = append(storeIDList, v.ShopInfo.Wid)
|
||||
}
|
||||
}
|
||||
return storeIDList, nil
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, cityInfo, storeID string) (storePageInfo *model.PageShop, err error) {
|
||||
shopInfo, err2 := api.EbaiAPI.GetStoreInfo2(storeID)
|
||||
if err = err2; err == nil && shopInfo != nil {
|
||||
_, _, districtCode := api.AutonaviAPI.GetCoordinateFromAddress(shopInfo.Address, cityInfo)
|
||||
return &model.PageShop{
|
||||
Name: shopInfo.Name,
|
||||
VendorID: model.VendorIDEBAI,
|
||||
VendorStoreID: storeID,
|
||||
OrgCode: shopInfo.Brand,
|
||||
VendorStatus: utils.Int2Str(shopInfo.BusinessStatus),
|
||||
|
||||
Address: shopInfo.Address,
|
||||
Lng: shopInfo.Longitude,
|
||||
Lat: shopInfo.Latitude,
|
||||
DistrictCode: districtCode,
|
||||
|
||||
Tel1: shopInfo.Phone,
|
||||
|
||||
RecentOrderNum: shopInfo.RecentOrderNum,
|
||||
SkuCount: shopInfo.SkuCount,
|
||||
BusinessType: shopInfo.Category,
|
||||
ShopScore: float32(shopInfo.ShopScore),
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
1
business/partner/purchase/ebai/net_spider_test.go
Normal file
1
business/partner/purchase/ebai/net_spider_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package ebai
|
||||
51
business/partner/purchase/jd/net_spider.go
Normal file
51
business/partner/purchase/jd/net_spider.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ditu"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func (c *PurchaseHandler) GetStoreIDListByCoordinates(ctx *jxcontext.Context, coord *ditu.Coordinate) (storeIDList []string, err error) {
|
||||
shopListInfo, err := api.JdAPI.GetStoreList(utils.Float64ToStr(coord.Lng), utils.Float64ToStr(coord.Lat))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shopListInfo != nil {
|
||||
shopDataList, _ := shopListInfo["data"].(map[string]interface{})["data"].([]interface{})
|
||||
for _, v := range shopDataList {
|
||||
floorCellData := v.(map[string]interface{})["floorCellData"].(map[string]interface{})
|
||||
storeIDList = append(storeIDList, utils.Interface2String(floorCellData["storeId"]))
|
||||
}
|
||||
}
|
||||
return storeIDList, nil
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) GetStorePageInfo(ctx *jxcontext.Context, cityInfo, storeID string) (storePageInfo *model.PageShop, err error) {
|
||||
shopInfo, err2 := api.JdAPI.GetStoreInfo2(storeID)
|
||||
if err = err2; err == nil && shopInfo != nil {
|
||||
lng, lat, districtCode := api.AutonaviAPI.GetCoordinateFromAddress(shopInfo.StoreInfo.StoreAddress, cityInfo)
|
||||
return &model.PageShop{
|
||||
Name: shopInfo.StoreInfo.StoreName,
|
||||
VendorID: model.VendorIDJD,
|
||||
VendorStoreID: storeID,
|
||||
OrgCode: shopInfo.StoreInfo.OrgCode,
|
||||
VendorStatus: utils.Int2Str(shopInfo.StoreInfo.StationStatus),
|
||||
|
||||
Address: shopInfo.StoreInfo.StoreAddress,
|
||||
Lng: lng,
|
||||
Lat: lat,
|
||||
DistrictCode: districtCode,
|
||||
|
||||
Tel1: shopInfo.StoreInfo.StoreTel,
|
||||
|
||||
RecentOrderNum: int(utils.Str2Int64WithDefault(shopInfo.StoreInfo.MonthSaleNum, 0)),
|
||||
SkuCount: int(utils.Str2Int64WithDefault(shopInfo.StoreInfo.InSaleNum, 0)),
|
||||
BusinessType: shopInfo.StoreInfo.Industry,
|
||||
ShopScore: float32(shopInfo.StoreCommentVO.ScoreAvg),
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
1
business/partner/purchase/jd/net_spider_test.go
Normal file
1
business/partner/purchase/jd/net_spider_test.go
Normal file
@@ -0,0 +1 @@
|
||||
package jd
|
||||
@@ -36,7 +36,7 @@ func Init() {
|
||||
orm.RegisterModel(&model.Promotion{}, &model.PromotionStore{}, &model.PromotionSku{})
|
||||
orm.RegisterModel(&model.AuthBind{}, &model.User{})
|
||||
|
||||
orm.RegisterModel(&model.StoreInfo{})
|
||||
// orm.RegisterModel(&model.PageShop{})
|
||||
|
||||
// orm.RegisterModel(&model.ActivityForSku{})
|
||||
// orm.RegisterModel(&legacymodel.JxBadComments2{})
|
||||
|
||||
Reference in New Issue
Block a user