From 8ab2af4f1ce30180852ff084ae8c532f22ccfe1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Mon, 2 Nov 2020 18:25:25 +0800 Subject: [PATCH] distance --- business/jxstore/cms/job.go | 11 +++++++++++ business/model/dao/dao_job.go | 18 +++++++++++++++--- controllers/job_controller.go | 4 +++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index 3e5320613..a8bce53d4 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -196,6 +196,17 @@ func GetJobs(ctx *jxcontext.Context, userIDs []string, categoryIDs, statuss, ven return dao.GetJobs(dao.GetDB(), userIDs, categoryIDs, statuss, vendorIDs, []int{model.JobTypeNormal}, includeStep, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset) } +func GetJobDetail(ctx *jxcontext.Context, jobID int, lng, lat float64) (job *dao.GetJobsResult, err error) { + var ( + db = dao.GetDB() + ) + job, err = dao.GetJobDetail(db, jobID) + if job.Lng != 0 && job.Lat != 0 { + job.Distance = jxutils.EarthDistance(lng, lat, jxutils.IntCoordinate2Standard(job.Lng), jxutils.IntCoordinate2Standard(job.Lat)) + } + return job, err +} + func AcceptJob(ctx *jxcontext.Context, jobID int) (errCode string, err error) { var ( db = dao.GetDB() diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go index 523d3e714..98d65b74b 100644 --- a/business/model/dao/dao_job.go +++ b/business/model/dao/dao_job.go @@ -25,8 +25,9 @@ func GetJobCategories(db *DaoDB, name string) (jobCategories []*model.JobCategor type GetJobsResult struct { model.Job - CategoryName string `json:"categoryName"` //分类名 - IndexImg string `json:"indexImg"` //任务封面 + CategoryName string `json:"categoryName"` //分类名 + IndexImg string `json:"indexImg"` //任务封面 + Distance float64 `json:"distance"` //距用户距离 } func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types []int, includeStep bool, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) { @@ -182,7 +183,10 @@ func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []in } func GetJobDetail(db *DaoDB, jobID int) (job *GetJobsResult, err error) { - var jobSteps []*model.JobStep + var ( + jobImgs []*model.JobImg + jobSteps []*model.JobStep + ) sql := ` SELECT a.*, b.name FROM job a @@ -205,6 +209,14 @@ func GetJobDetail(db *DaoDB, jobID int) (job *GetJobsResult, err error) { sqlParams2 := []interface{}{job.ID, utils.DefaultTimeValue} err = GetRows(db, &jobSteps, sql2, sqlParams2) job.JobSteps = jobSteps + sql3 := ` + SELECT * + FROM job_img + WHERE job_id = ? + ` + sqlParams3 := []interface{}{job.ID} + err = GetRows(db, &jobImgs, sql3, sqlParams3) + job.JobImgs = jobImgs } else { return job, fmt.Errorf("未查到到该任务!") } diff --git a/controllers/job_controller.go b/controllers/job_controller.go index 208f93767..e97754dfb 100644 --- a/controllers/job_controller.go +++ b/controllers/job_controller.go @@ -93,12 +93,14 @@ func (c *JobController) GetJobs() { // @Description 查看任务 // @Param token header string true "认证token" // @Param jobID query int false "任务ID" +// @Param lng query float64 false "经度" +// @Param lat query float64 false "维度" // @Success 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult // @router /GetJobDetail [get] func (c *JobController) GetJobDetail() { c.callGetJobDetail(func(params *tJobGetJobDetailParams) (retVal interface{}, errCode string, err error) { - retVal, err = dao.GetJobDetail(dao.GetDB(), params.JobID) + retVal, err = cms.GetJobDetail(params.Ctx, params.JobID, params.Lng, params.Lat) return retVal, "", err }) }