From dffbae543068e5ad31f01dc0e5309e3bfbddf1d0 Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 24 Jun 2019 21:38:18 +0800 Subject: [PATCH] - up --- platformapi/autonavi/autonavi.go | 21 +++++++++++++++++++++ platformapi/autonavi/autonavi_test.go | 5 +++++ platformapi/ebaiapi/store_page.go | 4 ++-- platformapi/jdapi/store_page.go | 2 +- utils/typeconv.go | 4 ++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/platformapi/autonavi/autonavi.go b/platformapi/autonavi/autonavi.go index c8f6b157..62e73d1d 100644 --- a/platformapi/autonavi/autonavi.go +++ b/platformapi/autonavi/autonavi.go @@ -177,6 +177,27 @@ func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retL return lng, lat, err } +func (a *API) GetCoordinateFromAddress(address string, cityInfo string) (lng, lat float64, districtCode int) { + params := map[string]interface{}{ + "address": address, + } + if cityInfo != "" { + params["city"] = cityInfo + } + + result, err := a.AccessAPI("geocode/geo", params) + if err == nil { + if geocodes, ok := result["geocodes"].([]interface{}); ok && len(geocodes) > 0 { + geocode := geocodes[0].(map[string]interface{}) + locationList := strings.Split(utils.Interface2String(geocode["location"]), ",") + if len(locationList) > 1 { + return utils.Str2Float64WithDefault(locationList[0], 0), utils.Str2Float64WithDefault(locationList[1], 0), int(utils.Str2Int64(utils.Interface2String(geocode["adcode"]))) + } + } + } + return lng, lat, 0 +} + // 这里的District指的是实际的District,有些市是没有区的,比如东莞,这种情况下返回的区码是一个假的区域,即市的编码加上9000000 func (a *API) GetCoordinateDistrictCode(lng, lat float64) (districtCode int) { result, err := a.GetCoordinateAreaInfo(lng, lat) diff --git a/platformapi/autonavi/autonavi_test.go b/platformapi/autonavi/autonavi_test.go index c2155ac1..81c2d857 100644 --- a/platformapi/autonavi/autonavi_test.go +++ b/platformapi/autonavi/autonavi_test.go @@ -83,3 +83,8 @@ func TestGetDistricts(t *testing.T) { } t.Log(utils.Format4Output(districtList, false)) } + +func TestGetCoordinateFromAddress(t *testing.T) { + lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("天府广场", "成都市") + t.Logf("lng:%f, lat:%f, districtCode:%d", lng, lat, districtCode) +} diff --git a/platformapi/ebaiapi/store_page.go b/platformapi/ebaiapi/store_page.go index 504ebcef..7bceb410 100644 --- a/platformapi/ebaiapi/store_page.go +++ b/platformapi/ebaiapi/store_page.go @@ -266,7 +266,7 @@ type PageShopInfo struct { CanRefund int `json:"can_refund"` Category string `json:"category"` CityID string `json:"city_id"` - CurrentBusinessTime string `json:"current_business_time"` + CurrentBusinessTime interface{} `json:"current_business_time"` // 无值时为空字符串,有值时为对象:{"end":"20:45","start":"08:05"} DeliveryInfo []interface{} `json:"delivery_info"` DeliveryMode struct { Tag []interface{} `json:"tag"` @@ -300,7 +300,7 @@ type PageShopInfo struct { Qualification string `json:"qualification"` RecentOrderNum int `json:"recent_order_num"` ShopID string `json:"shop_id"` - ShopScore int `json:"shop_score"` + ShopScore float64 `json:"shop_score"` ShopSourceFrom int `json:"shop_source_from"` SkuCount int `json:"sku_count"` TakeoutCost int `json:"takeout_cost"` diff --git a/platformapi/jdapi/store_page.go b/platformapi/jdapi/store_page.go index 720b8036..09c39e1b 100644 --- a/platformapi/jdapi/store_page.go +++ b/platformapi/jdapi/store_page.go @@ -181,7 +181,7 @@ func (a *API) AccessStorePage(fullURL string, formData map[string]interface{}) ( retVal = jsonResult1 code := jsonResult1["code"].(string) if code == ResponseCodeSuccess { - retVal = jsonResult1["result"].(map[string]interface{}) + retVal, _ = jsonResult1["result"].(map[string]interface{}) return platformapi.ErrLevelSuccess, nil } newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code) diff --git a/utils/typeconv.go b/utils/typeconv.go index 9aacf1ab..67459739 100644 --- a/utils/typeconv.go +++ b/utils/typeconv.go @@ -255,6 +255,10 @@ func Float64TwoInt64(data float64) int64 { return int64(math.Round(data)) } +func Float64ToStr(data float64) string { + return fmt.Sprint(data) +} + // timestamp is in second func Timestamp2Str(timestamp int64) string { return Time2Str(Timestamp2Time(timestamp))