- ebai store.
This commit is contained in:
@@ -2,6 +2,7 @@ package jxutils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -64,3 +65,28 @@ func StrTime2JxOperationTime(strTime string, defValue int16) int16 {
|
|||||||
func JxOperationTime2StrTime(value int16) string {
|
func JxOperationTime2StrTime(value int16) string {
|
||||||
return fmt.Sprintf("%02d:%02d:00", value/100, value%100)
|
return fmt.Sprintf("%02d:%02d:00", value/100, value%100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetPolygonFromCircle(lng, lat, distance float64, pointCount int) (points [][2]float64) {
|
||||||
|
points = make([][2]float64, pointCount)
|
||||||
|
for k := range points {
|
||||||
|
angle := float64(k) * 360 / float64(pointCount)
|
||||||
|
points[k][0], points[k][1] = ConvertDistanceToLogLat(lng, lat, float64(distance), angle)
|
||||||
|
}
|
||||||
|
return points
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPolygonFromCircleStr(lng, lat, distance float64, pointCount int) string {
|
||||||
|
points := GetPolygonFromCircle(lng, lat, distance, pointCount)
|
||||||
|
points2 := make([]string, len(points))
|
||||||
|
for k, v := range points {
|
||||||
|
points2[k] = fmt.Sprintf("%.6f,%.6f", v[0], v[1])
|
||||||
|
}
|
||||||
|
return strings.Join(points2, ";")
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConvertDistanceToLogLat(lng, lat, distance, angle float64) (newLng, newLat float64) {
|
||||||
|
oneDu := 111319.55
|
||||||
|
newLng = lng + (distance*math.Sin(angle*math.Pi/180))/(oneDu*math.Cos(lat*math.Pi/180)) //将距离转换成经度的计算公式
|
||||||
|
newLat = lat + (distance*math.Cos(angle*math.Pi/180))/oneDu //将距离转换成纬度的计算公式
|
||||||
|
return newLng, newLat
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package jxutils
|
package jxutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
@@ -22,3 +23,11 @@ func TestSplitSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log(result)
|
t.Log(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetPolygonFromCircle(t *testing.T) {
|
||||||
|
points := GetPolygonFromCircle(104.054727, 30.575362, 1000, 8)
|
||||||
|
for _, v := range points {
|
||||||
|
t.Log(fmt.Sprintf("lng=%f&lat=%f", v[0], v[1]))
|
||||||
|
}
|
||||||
|
t.Log(points)
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,13 +96,20 @@ func (p *PurchaseHandler) UpdateStore(storeID int, userName string) (err error)
|
|||||||
WHERE t1.id = ?`
|
WHERE t1.id = ?`
|
||||||
if err = dao.GetRow(db, &store, sql, model.VendorIDJD, storeID); err == nil {
|
if err = dao.GetRow(db, &store, sql, model.VendorIDJD, storeID); err == nil {
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"name": jxutils.ComposeStoreName(store.Name, partner.StoreNameSeparator, VendorStorePrefix),
|
"baidu_shop_id": store.VendorStoreID,
|
||||||
"address": store.Address,
|
"name": jxutils.ComposeStoreName(store.Name, partner.StoreNameSeparator, VendorStorePrefix),
|
||||||
"coord_type": ebaiapi.CoordTypeAutonavi, // 一直用高德
|
"phone": store.Tel1,
|
||||||
|
"ivr_phone": store.Tel2,
|
||||||
|
"longitude": jxutils.IntCoordinate2Standard(store.Lng),
|
||||||
|
"latitude": jxutils.IntCoordinate2Standard(store.Lat),
|
||||||
|
"address": store.Address,
|
||||||
|
"coord_type": ebaiapi.CoordTypeAutonavi, // 一直用高德
|
||||||
|
"delivery_region": JxDeliveryRegion2Ebai(&store.Store),
|
||||||
|
"business_time": JxBusinessTime2Ebai(&store.Store),
|
||||||
}
|
}
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
|
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
|
||||||
if globals.EnableStoreWrite {
|
if globals.EnableStoreWrite {
|
||||||
err = api.JdAPI.UpdateStoreInfo4Open(store.VendorStoreID, store.RealLastOperator, params)
|
err = api.EbaiAPI.ShopUpdate(params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -133,6 +140,42 @@ func EbaiDeliveryRegion2Jx(deliveryRegion interface{}) string {
|
|||||||
return strings.Join(coords, ";")
|
return strings.Join(coords, ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
func JxDeliveryRegion2Ebai(coords string) string {
|
func JxDeliveryRegion2Ebai(store *model.Store) interface{} {
|
||||||
return ""
|
rangeStr := store.DeliveryRange
|
||||||
|
if store.DeliveryRangeType == model.DeliveryRangeTypeRadius {
|
||||||
|
rangeStr = jxutils.GetPolygonFromCircleStr(jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat), utils.Str2Float64(store.DeliveryRange), 8)
|
||||||
|
}
|
||||||
|
pointPairs := strings.Split(rangeStr, ";")
|
||||||
|
region := make([]map[string]interface{}, len(pointPairs))
|
||||||
|
for k, v := range pointPairs {
|
||||||
|
pointPair := strings.Split(v, ",")
|
||||||
|
region[k] = map[string]interface{}{
|
||||||
|
"longitude": utils.Str2Float64(pointPair[0]),
|
||||||
|
"latitude": utils.Str2Float64(pointPair[1]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deliveryRegion := []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": store.Address + "配送区",
|
||||||
|
"delivery_fee": 600,
|
||||||
|
"delivery_time": "60",
|
||||||
|
"min_buy_free": "0",
|
||||||
|
"min_order_price": "0",
|
||||||
|
"region": region,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return deliveryRegion
|
||||||
|
}
|
||||||
|
|
||||||
|
func JxBusinessTime2Ebai(store *model.Store) interface{} {
|
||||||
|
bTime := make([]map[string]interface{}, 1)
|
||||||
|
bTime[0]["start"] = jxutils.JxOperationTime2StrTime(store.OpenTime1)
|
||||||
|
bTime[0]["end"] = jxutils.JxOperationTime2StrTime(store.CloseTime1)
|
||||||
|
if store.OpenTime2 != 0 {
|
||||||
|
bTime = append(bTime, map[string]interface{}{
|
||||||
|
"start": jxutils.JxOperationTime2StrTime(store.OpenTime2),
|
||||||
|
"end": jxutils.JxOperationTime2StrTime(store.CloseTime2),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return bTime
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user