acceptjob
This commit is contained in:
@@ -127,8 +127,8 @@ func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetJobs(ctx *jxcontext.Context, userIDs []string, categoryIDs, statuss []int, includeStep bool, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
return dao.GetJobs(dao.GetDB(), userIDs, categoryIDs, statuss, includeStep, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
|
||||
func GetJobs(ctx *jxcontext.Context, userIDs []string, categoryIDs, statuss, vendorIDs []int, includeStep bool, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
return dao.GetJobs(dao.GetDB(), userIDs, categoryIDs, statuss, vendorIDs, includeStep, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
|
||||
}
|
||||
|
||||
func AcceptJob(ctx *jxcontext.Context, jobID int) (err error) {
|
||||
@@ -171,7 +171,41 @@ func AcceptJob(ctx *jxcontext.Context, jobID int) (err error) {
|
||||
default:
|
||||
return fmt.Errorf("不支持的任务限次类型!%v", job.LimitCountType)
|
||||
}
|
||||
|
||||
jobOrder := &model.JobOrder{
|
||||
JobID: jobID,
|
||||
JobOrderID: jxutils.GenJobOrderNo(),
|
||||
UserID: job.UserID,
|
||||
Status: model.JobOrderStatusAccept,
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if err = dao.CreateEntity(db, jobOrder); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
//用户接受任务,任务剩余次数-1
|
||||
job.SurplusCount -= 1
|
||||
if _, err = dao.UpdateEntity(db, job, "SurplusCount"); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
dao.Commit(db)
|
||||
//任务限时完成
|
||||
utils.AfterFuncWithRecover(time.Hour*time.Duration(job.JobLimitAt), func() {
|
||||
jobOrders, _ := dao.GetJobOrdersNoPage(db, jobID, jobOrder.JobOrderID, userID, "", utils.ZeroTimeValue, utils.ZeroTimeValue, nil)
|
||||
if len(jobOrders) == 0 {
|
||||
return
|
||||
}
|
||||
jobOrder := jobOrders[0]
|
||||
if jobOrder.Status == model.JobOrderStatusCancel {
|
||||
return
|
||||
}
|
||||
jobOrder.Status = model.JobOrderStatusCancel
|
||||
dao.UpdateEntity(db, jobOrder, "Status")
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user