This commit is contained in:
苏尹岚
2020-12-16 18:24:29 +08:00
parent cf22855307
commit ee27ffdeef

View File

@@ -14,6 +14,7 @@ import (
const ( const (
sortTypeDistance = 1 //距离 sortTypeDistance = 1 //距离
sortTypeTime = 2 //发布时间
sortTypeAvgPrice = 4 //奖励高低 sortTypeAvgPrice = 4 //奖励高低
) )
@@ -122,6 +123,10 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types
sql += ` ORDER BY a.avg_price` sql += ` ORDER BY a.avg_price`
} else if sortType == -sortTypeAvgPrice { } else if sortType == -sortTypeAvgPrice {
sql += ` ORDER BY a.avg_price DESC` sql += ` ORDER BY a.avg_price DESC`
} else if sortType == sortTypeTime {
sql += ` ORDER BY a.created_at`
} else if sortType == -sortTypeTime {
sql += ` ORDER BY a.created_at DESC`
} }
} }
sql += " LIMIT ? OFFSET ?" sql += " LIMIT ? OFFSET ?"
@@ -140,19 +145,19 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types
v.JobSteps = jobSteps v.JobSteps = jobSteps
} }
} }
var ( // var (
distance float64 // distance float64
) // )
if jobImgs, err := GetJobImgs(db, v.ID); err == nil && len(jobImgs) > 0 { if jobImgs, err := GetJobImgs(db, v.ID); err == nil && len(jobImgs) > 0 {
v.JobImgs = jobImgs v.JobImgs = jobImgs
v.IndexImg = jobImgs[0].Img v.IndexImg = jobImgs[0].Img
} }
if v.Lng != 0 && v.Lat != 0 { // if v.Lng != 0 && v.Lat != 0 {
distance = jxutils.EarthDistance(lng, lat, jxutils.IntCoordinate2Standard(v.Lng), jxutils.IntCoordinate2Standard(v.Lat)) // distance = jxutils.EarthDistance(lng, lat, jxutils.IntCoordinate2Standard(v.Lng), jxutils.IntCoordinate2Standard(v.Lat))
} else { // } else {
distance = 0 // distance = 0
} // }
v.Distance = distance // v.Distance = distance
} }
pagedInfo.Data = jobs pagedInfo.Data = jobs
} }