From 686416521ae3ee4217d0da4d0d7ce66a1d3e9b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 3 Nov 2020 14:23:05 +0800 Subject: [PATCH] sort --- business/auth2/auth2.go | 1 + business/model/dao/dao_job.go | 28 +++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/business/auth2/auth2.go b/business/auth2/auth2.go index 617d6d6db..92553e48a 100644 --- a/business/auth2/auth2.go +++ b/business/auth2/auth2.go @@ -273,6 +273,7 @@ func LoginInternal(ctx *Context, authType, authID, authIDType, authSecret string if user != nil && user.GetID() != "" { userProvider.UpdateLastLogin(user.GetID(), authType, ctx.GetRealRemoteIP()) } + globals.SugarLogger.Debugf("tetetetet", utils.Format4Output(user, false)) //如果是小程序 if authType == "weixinmini" || authType == "weixinapp" { appID := strings.Split(authSecret, ",")[0] diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go index 5ac2d7bd7..43363894e 100644 --- a/business/model/dao/dao_job.go +++ b/business/model/dao/dao_job.go @@ -10,6 +10,11 @@ import ( "git.rosy.net.cn/jx-callback/business/model" ) +const ( + sortTypeDistance = 1 //距离 + sortTypeAvgPrice = 4 //奖励高低 +) + func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategory, err error) { sql := ` 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) { - var jobs []*GetJobsResult + var ( + jobs []*GetJobsResult + distanceFlag bool + sqlParams = []interface{}{} + ) + if lng != 0 && lat != 0 && (sortType == sortTypeDistance || sortType == -sortTypeDistance) { + distanceFlag = true + } sql := ` 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 = ? WHERE 1 = 1 ` - sqlParams := []interface{}{utils.DefaultTimeValue} + sqlParams = append(sqlParams, utils.DefaultTimeValue) if len(userIDs) > 0 { sql += ` AND a.user_id IN (` + GenQuestionMarks(len(userIDs)) + `)` sqlParams = append(sqlParams, userIDs) @@ -67,6 +84,11 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types sql += ` AND a.created_at <= ?` sqlParams = append(sqlParams, toTime) } + if sortType != 0 { + if sortType == sortTypeDistance || sortType == -sortTypeDistance { + sql += ` ORDER distance` + } + } sql += " LIMIT ? OFFSET ?" pageSize = jxutils.FormalizePageSize(pageSize) sqlParams = append(sqlParams, pageSize, offset)