This commit is contained in:
苏尹岚
2020-12-03 11:43:37 +08:00
parent d12e4edd08
commit 57812bf484

View File

@@ -436,7 +436,7 @@ func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng fl
SELECT SQL_CALC_FOUND_ROWS *
`
if distanceFlag {
sql += `, ROUND(POWER((POWER(longitude-?,2))+(POWER(latitude-?,2)),1/2)) distance2`
sql += `, getDistance(?, ?, longitude, latitude) distance`
sqlParams = append(sqlParams, lng, lat)
}
sql += `
@@ -457,9 +457,9 @@ func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng fl
}
if sortType != 0 {
if sortType == 1 {
sql += " ORDER BY distance2"
sql += " ORDER BY distance"
} else if sortType == -1 {
sql += " ORDER BY distance2 DESC"
sql += " ORDER BY distance DESC"
} else if sortType == 2 {
sql += " ORDER BY star_num"
} else if sortType == -2 {
@@ -474,18 +474,18 @@ func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng fl
if err = GetRows(db, &stations, sql, sqlParams...); err == nil {
pagedInfo = &model.PagedInfo{
TotalCount: GetLastTotalRowCount(db),
// Data: stations,
Data: stations,
}
for _, v := range stations {
var distance float64
if v.Longitude != 0 && v.Latitude != 0 {
distance = jxutils.EarthDistance(lng, lat, v.Longitude, v.Latitude)
} else {
distance = 0
}
v.Distance = distance
}
pagedInfo.Data = stations
// for _, v := range stations {
// var distance float64
// if v.Longitude != 0 && v.Latitude != 0 {
// distance = jxutils.EarthDistance(lng, lat, v.Longitude, v.Latitude)
// } else {
// distance = 0
// }
// v.Distance = distance
// }
// pagedInfo.Data = stations
}
return pagedInfo, err
}