Files
jx-callback/business/jxstore/cms/job.go
苏尹岚 accb629e14 shan
2020-10-14 11:57:12 +08:00

86 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package cms
import (
"fmt"
"time"
"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"
)
const (
AcceptMaxCount = 2
)
func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
var (
db = dao.GetDB()
timeNow = utils.Time2Date(time.Now())
fromTime = utils.Time2Str(timeNow) + "00:00:00"
toTime = utils.Time2Str(timeNow) + "23:59:59"
)
//需根据任务类型做一些参数判断,比如门店商品链接,地址
// switch job.JobCategoryID {
// case 1:
// }
// if ctx.GetUserID() != job.UserID {
// return fmt.Errorf("用户信息已过期,请重新登录!")
// }
if job.Count <= 0 {
return fmt.Errorf("任务数量不能为0")
}
if job.UserID == "" {
return fmt.Errorf("任务发起人不能为空!")
}
jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, utils.Str2Time(fromTime), utils.Str2Time(toTime), false)
if len(jobs) > 0 {
members, err := dao.GetUserMember(db, job.UserID, 0, 0, true)
if err != nil {
return err
}
if len(members) <= 0 {
return fmt.Errorf("非会员一天只能发布一起任务,请确认!")
}
}
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)
}