- GetStores add range limit.
This commit is contained in:
@@ -221,9 +221,25 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
|||||||
}()
|
}()
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||||
// globals.SugarLogger.Debug(sql)
|
// globals.SugarLogger.Debug(sql)
|
||||||
if err = dao.GetRows(db, &retVal.Stores, sql, sqlParams...); err == nil {
|
var storeList []*StoreExt
|
||||||
retVal.TotalCount = dao.GetLastTotalRowCount(db)
|
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil {
|
||||||
for _, v := range retVal.Stores {
|
mapLimit := false
|
||||||
|
var (
|
||||||
|
mapLatitude, mapLongitude float64
|
||||||
|
mapRadius int
|
||||||
|
)
|
||||||
|
if mapLatitude2, ok := params["mapLatitude"].(string); ok {
|
||||||
|
mapLimit = true
|
||||||
|
mapLatitude = utils.Str2Float64(mapLatitude2)
|
||||||
|
mapLongitude = utils.Str2Float64(params["mapLongitude"].(string))
|
||||||
|
mapRadius = params["mapRadius"].(int)
|
||||||
|
}
|
||||||
|
for _, v := range storeList {
|
||||||
|
valid := !mapLimit
|
||||||
|
if mapLimit {
|
||||||
|
valid = jxutils.EarthDistance(mapLongitude, mapLatitude, v.FloatLng, v.FloatLat)*1000 <= float64(mapRadius)
|
||||||
|
}
|
||||||
|
if valid {
|
||||||
if v.StoreMapStr != "" {
|
if v.StoreMapStr != "" {
|
||||||
if err = utils.UnmarshalUseNumber([]byte(v.StoreMapStr), &v.StoreMaps); err != nil {
|
if err = utils.UnmarshalUseNumber([]byte(v.StoreMapStr), &v.StoreMaps); err != nil {
|
||||||
dao.Rollback(db)
|
dao.Rollback(db)
|
||||||
@@ -236,6 +252,13 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
retVal.Stores = append(retVal.Stores, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mapLimit {
|
||||||
|
retVal.TotalCount = len(retVal.Stores)
|
||||||
|
} else {
|
||||||
|
retVal.TotalCount = dao.GetLastTotalRowCount(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dao.Commit(db)
|
dao.Commit(db)
|
||||||
|
|||||||
@@ -105,6 +105,15 @@ func GetUniversalOrderIDFromOrderStatus(status *model.OrderStatus) string {
|
|||||||
return ComposeUniversalOrderID(status.VendorOrderID, status.VendorID)
|
return ComposeUniversalOrderID(status.VendorOrderID, status.VendorID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// distance单位为米
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// 返回结果单元为公里
|
||||||
func EarthDistance(lat1, lng1, lat2, lng2 float64) float64 {
|
func EarthDistance(lat1, lng1, lat2, lng2 float64) float64 {
|
||||||
radius := 6378.137
|
radius := 6378.137
|
||||||
rad := math.Pi / 180.0
|
rad := math.Pi / 180.0
|
||||||
|
|||||||
@@ -98,13 +98,6 @@ func GetPolygonFromCircleStr(lng, lat, distance float64, pointCount int) string
|
|||||||
return strings.Join(points2, ";")
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func IntMap2List(intMap map[int]int) []int {
|
func IntMap2List(intMap map[int]int) []int {
|
||||||
retVal := make([]int, len(intMap))
|
retVal := make([]int, len(intMap))
|
||||||
index := 0
|
index := 0
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ type StoreController struct {
|
|||||||
// @Param vendorStoreConds query string false "为厂商条件对象{vendorID: cond},注意vendorID是字符串形式,cond,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
// @Param vendorStoreConds query string false "为厂商条件对象{vendorID: cond},注意vendorID是字符串形式,cond,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
||||||
// @Param courierStoreCond query string false "查询关联门店的条件(如果此字段没有设置,courierStoreConds无效),and:与,or:或,指的是courierStoreConds里的条件间的关系,这组条件与其它条件都是与的关系"
|
// @Param courierStoreCond query string false "查询关联门店的条件(如果此字段没有设置,courierStoreConds无效),and:与,or:或,指的是courierStoreConds里的条件间的关系,这组条件与其它条件都是与的关系"
|
||||||
// @Param courierStoreConds query string false "为厂商条件对象{vendorID: cond},注意vendorID是字符串形式,cond,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
// @Param courierStoreConds query string false "为厂商条件对象{vendorID: cond},注意vendorID是字符串形式,cond,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
||||||
|
// @Param mapLongitude query string false "地图中心经度"
|
||||||
|
// @Param mapLatitude query string false "地图中心纬度"
|
||||||
|
// @Param mapRadius query int false "地图半径(单位为米)"
|
||||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
|||||||
Reference in New Issue
Block a user