GetStoreListByLocation添加可选参数needWalkDistance
This commit is contained in:
@@ -68,7 +68,8 @@ type Store4User struct {
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
|
||||
Distance int `json:"distance"`
|
||||
Distance int `json:"distance"`
|
||||
WalkDistance int `json:"walkDistance"`
|
||||
}
|
||||
|
||||
type Store4UserList []*Store4User
|
||||
@@ -78,6 +79,9 @@ func (x Store4UserList) Len() int {
|
||||
}
|
||||
|
||||
func (x Store4UserList) Less(i, j int) bool {
|
||||
if x[i].WalkDistance != x[j].Distance {
|
||||
return x[i].WalkDistance < x[j].Distance
|
||||
}
|
||||
return x[i].Distance < x[j].Distance
|
||||
}
|
||||
|
||||
@@ -2028,7 +2032,7 @@ func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContin
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64) (storeList []*Store4User, err error) {
|
||||
func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, needWalkDistance bool) (storeList []*Store4User, err error) {
|
||||
const (
|
||||
maxRadius = 5000
|
||||
maxStoreCount4User = 5
|
||||
@@ -2077,6 +2081,25 @@ func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64) (storeList
|
||||
storeList2 = append(storeList2, v)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果要求以步行距离来算
|
||||
if needWalkDistance {
|
||||
var coordList []*autonavi.Coordinate
|
||||
for _, v := range storeList2 {
|
||||
coordList = append(coordList, &autonavi.Coordinate{
|
||||
Lng: v.FloatLng,
|
||||
Lat: v.FloatLat,
|
||||
})
|
||||
}
|
||||
if distanceList, err2 := api.AutonaviAPI.BatchWalkingDistance(lng, lat, coordList); err2 == nil {
|
||||
for k, v := range storeList2 {
|
||||
v.WalkDistance = int(distanceList[k])
|
||||
}
|
||||
} else {
|
||||
return nil, err2
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(Store4UserList(storeList2))
|
||||
storeList = storeList2
|
||||
if len(storeList) > maxStoreCount4User {
|
||||
|
||||
@@ -535,12 +535,13 @@ func (c *StoreController) SyncStoresCourierInfo() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param lng query float64 true "经度"
|
||||
// @Param lat query float64 true "纬度"
|
||||
// @Param needWalkDistance query bool false "是否需要返回步行距离(且以步行距离排序)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetStoreListByLocation [get]
|
||||
func (c *StoreController) GetStoreListByLocation() {
|
||||
c.callGetStoreListByLocation(func(params *tStoreGetStoreListByLocationParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetStoreListByLocation(params.Ctx, params.Lng, params.Lat)
|
||||
retVal, err = cms.GetStoreListByLocation(params.Ctx, params.Lng, params.Lat, params.NeedWalkDistance)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user