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
|
||||||
|
}
|
||||||
@@ -1,18 +1,31 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
JobStatusDoing = 0
|
||||||
|
JobStatusFinished = 1
|
||||||
|
)
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
ModelIDCULD
|
ModelIDCULD
|
||||||
|
|
||||||
ThingID string `orm:"column(thing_id)" json:"thingID"` //发布人ID
|
UserID string `orm:"column(user_id)" json:"thingID"` //发布人ID
|
||||||
ThingType int `json:"thingType"` //发布人类型,1是普通用户,2是商户
|
JobCategoryID int `orm:"column(job_category_id)" json:"jobCategoryID"` //任务类型
|
||||||
JobCategoryID int `orm:"column(job_category_id)" json:"jobCategoryID"` //任务类型
|
JobSpan string `orm:"size(500)" json:"jobSpan"` //任务标签
|
||||||
JobSpan string `orm:"size(500)" json:"jobSpan"` //任务标签
|
Title string `orm:"size(255)" json:"title"` //任务标题
|
||||||
Title string `orm:"size(255)" json:"title"` //任务标题
|
Content string `orm:"size(500)" json:"content"` //任务内容
|
||||||
Content string `orm:"size(500)" json:"content"` //任务内容
|
Count int `json:"count"` //任务数量
|
||||||
Count int `json:"count"` //任务数量
|
AvgPrice int `json:"avgPrice"` //单个任务金额
|
||||||
AvgPrice int `json:"avgPrice"` //单个任务金额
|
TotalPrice int `json:"totalPrice"` //任务总金额
|
||||||
TotalPrice int `json:"totalPrice"` //任务总金额
|
Status int `json:"status"` //任务状态
|
||||||
Status int `json:"status"` //任务状态
|
Address string `orm:"size(500)" json:"address"` //任务地址
|
||||||
|
Lng int `json:"lng"` // 乘了10的6次方
|
||||||
|
Lat int `json:"lat"` // 乘了10的6次方
|
||||||
|
FinishedAt time.Time `json:"finishedAt"` //截止日期
|
||||||
|
StoreURL string `orm:"column(store_url)" json:"storeURL"` //门店链接
|
||||||
|
SkuURL string `orm:"column(sku_url)" json:"skuURL"` //商品优惠券链接
|
||||||
|
JobSteps []*JobStep `orm:"-" json:"jobSteps"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Job) TableIndex() [][]string {
|
func (v *Job) TableIndex() [][]string {
|
||||||
|
|||||||
@@ -1,7 +1,29 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import "github.com/astaxie/beego"
|
import (
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"github.com/astaxie/beego"
|
||||||
|
)
|
||||||
|
|
||||||
type JobController struct {
|
type JobController struct {
|
||||||
beego.Controller
|
beego.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 发布任务
|
||||||
|
// @Description 发布任务
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param payload formData string true "job+step 类型"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /PublishJob [post]
|
||||||
|
func (c *JobController) PublishJob() {
|
||||||
|
c.callPublishJob(func(params *tJobPublishJobParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var job *model.Job
|
||||||
|
if err = jxutils.Strings2Objs(params.Payload, &job); err == nil {
|
||||||
|
err = cms.PublishJob(params.Ctx, job)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user