65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package cms
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
|
||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||
|
||
"git.rosy.net.cn/jx-callback/globals/api"
|
||
|
||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||
"git.rosy.net.cn/jx-callback/business/model"
|
||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||
)
|
||
|
||
func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
|
||
var (
|
||
db = dao.GetDB()
|
||
)
|
||
//需根据任务类型做一些参数判断,比如门店商品链接,地址
|
||
// switch job.JobCategoryID {
|
||
// case 1:
|
||
// }
|
||
// if ctx.GetUserID() != job.UserID {
|
||
// return fmt.Errorf("用户信息已过期,请重新登录!")
|
||
// }
|
||
if job.Count <= 0 {
|
||
return fmt.Errorf("任务数量不能为0!")
|
||
}
|
||
if job.Address != "" && (job.Lng == 0 || job.Lat == 0) {
|
||
lng, lat, err := api.AutonaviAPI.GetCoordinateFromAddressByPage(job.Address)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
job.Lng = jxutils.StandardCoordinate2Int(lng)
|
||
job.Lat = jxutils.StandardCoordinate2Int(lat)
|
||
}
|
||
job.TotalPrice = job.Count * job.AvgPrice
|
||
job.Status = model.JobStatusDoing
|
||
dao.WrapAddIDCULEntity(job, ctx.GetUserName())
|
||
dao.Begin(db)
|
||
defer func() {
|
||
if r := recover(); r != nil {
|
||
dao.Rollback(db)
|
||
panic(r)
|
||
}
|
||
}()
|
||
err = dao.CreateEntity(db, job)
|
||
for _, v := range job.JobSteps {
|
||
dao.WrapAddIDCULEntity(v, ctx.GetUserName())
|
||
v.JobID = job.ID
|
||
err = dao.CreateEntity(db, v)
|
||
}
|
||
if err != nil {
|
||
dao.Rollback(db)
|
||
}
|
||
dao.Commit(db)
|
||
return err
|
||
}
|
||
|
||
func GetJobs(ctx *jxcontext.Context, userIDs []string, categoryIDs []int, includeStep bool, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||
return dao.GetJobs(dao.GetDB(), userIDs, categoryIDs, includeStep, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
|
||
}
|