- GetStores add range limit.
This commit is contained in:
@@ -221,22 +221,45 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa
|
||||
}()
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
if err = dao.GetRows(db, &retVal.Stores, sql, sqlParams...); err == nil {
|
||||
retVal.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
for _, v := range retVal.Stores {
|
||||
if v.StoreMapStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(v.StoreMapStr), &v.StoreMaps); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
var storeList []*StoreExt
|
||||
if err = dao.GetRows(db, &storeList, sql, sqlParams...); err == nil {
|
||||
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 v.CourierMapStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(v.CourierMapStr), &v.CourierMaps); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
if valid {
|
||||
if v.StoreMapStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(v.StoreMapStr), &v.StoreMaps); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if v.CourierMapStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(v.CourierMapStr), &v.CourierMaps); err != nil {
|
||||
dao.Rollback(db)
|
||||
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)
|
||||
return retVal, err
|
||||
|
||||
@@ -105,6 +105,15 @@ func GetUniversalOrderIDFromOrderStatus(status *model.OrderStatus) string {
|
||||
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 {
|
||||
radius := 6378.137
|
||||
rad := math.Pi / 180.0
|
||||
|
||||
@@ -98,13 +98,6 @@ func GetPolygonFromCircleStr(lng, lat, distance float64, pointCount int) string
|
||||
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 {
|
||||
retVal := make([]int, len(intMap))
|
||||
index := 0
|
||||
|
||||
@@ -26,6 +26,9 @@ type StoreController struct {
|
||||
// @Param vendorStoreConds query string false "为厂商条件对象{vendorID: cond},注意vendorID是字符串形式,cond,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
||||
// @Param courierStoreCond query string false "查询关联门店的条件(如果此字段没有设置,courierStoreConds无效),and:与,or:或,指的是courierStoreConds里的条件间的关系,这组条件与其它条件都是与的关系"
|
||||
// @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 pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
|
||||
Reference in New Issue
Block a user