sort
This commit is contained in:
@@ -273,6 +273,7 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string
|
|||||||
if user != nil && user.GetID() != "" {
|
if user != nil && user.GetID() != "" {
|
||||||
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP())
|
||||||
}
|
}
|
||||||
|
globals.SugarLogger.Debugf("tetetetet", utils.Format4Output(user, false))
|
||||||
//如果是小程序
|
//如果是小程序
|
||||||
if authType == "weixinmini" || authType == "weixinapp" {
|
if authType == "weixinmini" || authType == "weixinapp" {
|
||||||
appID := strings.Split(authSecret, ",")[0]
|
appID := strings.Split(authSecret, ",")[0]
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
sortTypeDistance = 1 //距离
|
||||||
|
sortTypeAvgPrice = 4 //奖励高低
|
||||||
|
)
|
||||||
|
|
||||||
func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategory, err error) {
|
func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategory, err error) {
|
||||||
sql := `
|
sql := `
|
||||||
SELECT * FROM job_category WHERE deleted_at = ?
|
SELECT * FROM job_category WHERE deleted_at = ?
|
||||||
@@ -31,14 +36,26 @@ type GetJobsResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types []int, includeStep bool, fromTime, toTime time.Time, lng, lat float64, sortType, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types []int, includeStep bool, fromTime, toTime time.Time, lng, lat float64, sortType, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||||
var jobs []*GetJobsResult
|
var (
|
||||||
|
jobs []*GetJobsResult
|
||||||
|
distanceFlag bool
|
||||||
|
sqlParams = []interface{}{}
|
||||||
|
)
|
||||||
|
if lng != 0 && lat != 0 && (sortType == sortTypeDistance || sortType == -sortTypeDistance) {
|
||||||
|
distanceFlag = true
|
||||||
|
}
|
||||||
sql := `
|
sql := `
|
||||||
SELECT SQL_CALC_FOUND_ROWS a.*, b.name
|
SELECT SQL_CALC_FOUND_ROWS a.*, b.name
|
||||||
FROM job a
|
`
|
||||||
|
if distanceFlag {
|
||||||
|
sql += `, ROUND(POWER((POWER(a.lng,2)-POWER(?,2))+(POWER(a.lat,2)-POWER(?,2)),1/2)) distance`
|
||||||
|
sqlParams = append(sqlParams, lng, lat)
|
||||||
|
}
|
||||||
|
sql += ` FROM job a
|
||||||
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
JOIN job_category b ON b.id = a.job_category_id AND b.deleted_at = ?
|
||||||
WHERE 1 = 1
|
WHERE 1 = 1
|
||||||
`
|
`
|
||||||
sqlParams := []interface{}{utils.DefaultTimeValue}
|
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||||
if len(userIDs) > 0 {
|
if len(userIDs) > 0 {
|
||||||
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)`
|
||||||
sqlParams = append(sqlParams, userIDs)
|
sqlParams = append(sqlParams, userIDs)
|
||||||
@@ -67,6 +84,11 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types
|
|||||||
sql += ` AND a.created_at <= ?`
|
sql += ` AND a.created_at <= ?`
|
||||||
sqlParams = append(sqlParams, toTime)
|
sqlParams = append(sqlParams, toTime)
|
||||||
}
|
}
|
||||||
|
if sortType != 0 {
|
||||||
|
if sortType == sortTypeDistance || sortType == -sortTypeDistance {
|
||||||
|
sql += ` ORDER distance`
|
||||||
|
}
|
||||||
|
}
|
||||||
sql += " LIMIT ? OFFSET ?"
|
sql += " LIMIT ? OFFSET ?"
|
||||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||||
sqlParams = append(sqlParams, pageSize, offset)
|
sqlParams = append(sqlParams, pageSize, offset)
|
||||||
|
|||||||
Reference in New Issue
Block a user