job
This commit is contained in:
53
business/jxstore/cms/job.go
Normal file
53
business/jxstore/cms/job.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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 != "" {
|
||||
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)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
dao.Commit(db)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user