diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go index 9cd6467e7..a7aa780e6 100644 --- a/business/model/dao/dao_job.go +++ b/business/model/dao/dao_job.go @@ -3,6 +3,7 @@ package dao import ( "encoding/json" "fmt" + "math" "time" "git.rosy.net.cn/baseapi/utils" @@ -481,39 +482,42 @@ func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng fl for _, v := range stations { utils.Map2StructByJson(v.Prices, &v.OilInfo, false) } - if oilCode != "" { - for i := 0; i < len(stations); i++ { - for j := 0; j < len(stations)-i-1; j++ { - var ( - index int - index2 int - ) - for k, v := range stations[j].OilInfo { - if v.OilCode == oilCode { - index = k + if math.Abs(utils.Int2Float64(sortType)) == 3 { + if oilCode != "" { + for i := 0; i < len(stations); i++ { + for j := 0; j < len(stations)-i-1; j++ { + var ( + index int + index2 int + ) + for k, v := range stations[j].OilInfo { + if v.OilCode == oilCode { + index = k + } } - } - for k, v := range stations[j+1].OilInfo { - if v.OilCode == oilCode { - index2 = k + for k, v := range stations[j+1].OilInfo { + if v.OilCode == oilCode { + index2 = k + } } - } - if sortType == 3 { - if utils.Str2Float64(stations[j].OilInfo[index].StationPrice) < utils.Str2Float64(stations[j+1].OilInfo[index2].StationPrice) { - temp := stations[j] - stations[j] = stations[j+1] - stations[j+1] = temp - } - } else if sortType == -3 { - if utils.Str2Float64(stations[j].OilInfo[index].StationPrice) > utils.Str2Float64(stations[j+1].OilInfo[index2].StationPrice) { - temp := stations[j] - stations[j] = stations[j+1] - stations[j+1] = temp + if sortType == 3 { + if utils.Str2Float64(stations[j].OilInfo[index].StationPrice) < utils.Str2Float64(stations[j+1].OilInfo[index2].StationPrice) { + temp := stations[j] + stations[j] = stations[j+1] + stations[j+1] = temp + } + } else if sortType == -3 { + if utils.Str2Float64(stations[j].OilInfo[index].StationPrice) > utils.Str2Float64(stations[j+1].OilInfo[index2].StationPrice) { + temp := stations[j] + stations[j] = stations[j+1] + stations[j+1] = temp + } } } } } } + pagedInfo.Data = stations } return pagedInfo, err }