diff --git a/business/jxstore/cms/job.go b/business/jxstore/cms/job.go index 0e679b406..9f8761e64 100644 --- a/business/jxstore/cms/job.go +++ b/business/jxstore/cms/job.go @@ -82,6 +82,9 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e if ctx.GetUserID() != job.UserID { return errCode, fmt.Errorf("用户信息已过期,请重新登录!") } + if job.FinishedAt.Sub(time.Now()) <= 0 { + return errCode, fmt.Errorf("任务截止日期必须大于今天!") + } // authBinds, err := dao.GetUserBindAuthInfo(dao.GetDB(), job.UserID, model.AuthBindTypeAuth, []string{"weixinapp"}, "", "", "wx70d0943e61e0d15c") // if err != nil { // return errCode, err @@ -105,7 +108,7 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e if job.UserID == "" { return errCode, fmt.Errorf("任务发起人不能为空!") } - jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, DayTimeBegin, DayTimeEnd, false) + jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, DayTimeBegin, DayTimeEnd, false) if len(jobs) > 0 { members, err := dao.GetUserMember(db, job.UserID, model.MemberTypeNormal) if err != nil { @@ -190,7 +193,7 @@ func CancelPublishJob(ctx *jxcontext.Context, jobID int) (err error) { } 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) + return dao.GetJobs(dao.GetDB(), userIDs, categoryIDs, statuss, vendorIDs, []int{model.JobTypeNormal}, includeStep, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset) } func AcceptJob(ctx *jxcontext.Context, jobID int) (errCode string, err error) { @@ -244,7 +247,7 @@ func AcceptJob(ctx *jxcontext.Context, jobID int) (errCode string, err error) { // Status: model.JobOrderStatusAccept, } //美团会员任务 - if jobID == model.JobIDMtMembers { + if job.Type == model.JobTypeMtMember { jobOrder.Status = model.JobOrderStatusSpec } else { jobOrder.Status = model.JobOrderStatusAccept @@ -271,7 +274,7 @@ func AcceptJob(ctx *jxcontext.Context, jobID int) (errCode string, err error) { JobTimerMap[jobOrder.JobOrderID] = timer }() //特殊任务,如美团会员,是直接要支付 - if jobID == model.JobIDMtMembers { + if job.Type == model.JobTypeMtMember { userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "") if err != nil { return errCode, err @@ -517,7 +520,7 @@ func RefreshJobStatus(ctx *jxcontext.Context) (err error) { db = dao.GetDB() ) globals.SugarLogger.Debugf("RefreshJobStatus begin...") - jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, utils.ZeroTimeValue, utils.ZeroTimeValue, false) + jobs, err := dao.GetJobsNoPage(db, nil, nil, []int{model.JobStatusDoing}, nil, utils.ZeroTimeValue, utils.ZeroTimeValue, false) if err != nil { globals.SugarLogger.Debugf("RefreshJobStatus err :%v", err) return @@ -541,10 +544,8 @@ func ImprotMtMembers(ctx *jxcontext.Context, mtMembers []*model.MtMember) (err e dao.WrapAddIDCULDEntity(v, ctx.GetUserName()) } if err = dao.CreateMultiEntities(db, mtMembers); err == nil { - job := &model.Job{} - job.ID = model.JobIDMtMembers - dao.GetEntity(db, job) - if job != nil { + job, err := dao.GetJob(db, nil, nil, nil, []int{model.JobTypeMtMember}, utils.ZeroTimeValue, utils.ZeroTimeValue, false) + if job != nil && err == nil { job.Count += len(mtMembers) dao.UpdateEntity(db, job, "Count") } @@ -556,7 +557,8 @@ func RechargeMtMembers(ctx *jxcontext.Context, phone int) (errCode string, err e var ( db = dao.GetDB() ) - errCode, err = AcceptJob(ctx, model.JobIDMtMembers) + job, err := dao.GetJob(db, nil, nil, nil, []int{model.JobTypeMtMember}, utils.ZeroTimeValue, utils.ZeroTimeValue, false) + errCode, err = AcceptJob(ctx, job.ID) if errCode != "" { return errCode, err } @@ -581,7 +583,8 @@ func SendJdDelivery(ctx *jxcontext.Context, dOrder *model.DeliveryOrder) (errCod var ( db = dao.GetDB() ) - errCode, err = AcceptJob(ctx, model.JobIDJdDelivery) + job, err := dao.GetJob(db, nil, nil, nil, []int{model.JobTypeJdDelivery}, utils.ZeroTimeValue, utils.ZeroTimeValue, false) + errCode, err = AcceptJob(ctx, job.ID) if errCode != "" { return errCode, err } diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go index 51f73df04..cf29ca765 100644 --- a/business/model/dao/dao_job.go +++ b/business/model/dao/dao_job.go @@ -1,6 +1,7 @@ package dao import ( + "encoding/json" "fmt" "time" @@ -27,7 +28,7 @@ type GetJobsResult struct { CategoryName string `json:"CategoryName"` //分类名 } -func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int, includeStep bool, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) { +func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs, types []int, includeStep bool, fromTime, toTime time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) { var jobs []*GetJobsResult sql := ` SELECT SQL_CALC_FOUND_ROWS a.*, b.name @@ -52,6 +53,10 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int, sql += ` AND a.vendor_id IN (` + GenQuestionMarks(len(vendorIDs)) + `)` sqlParams = append(sqlParams, vendorIDs) } + if len(types) > 0 { + sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)` + sqlParams = append(sqlParams, types) + } if fromTime != utils.ZeroTimeValue { sql += ` AND a.created_at >= ?` sqlParams = append(sqlParams, fromTime) @@ -100,7 +105,18 @@ func GetJobs(db *DaoDB, userIDs []string, categoryIDs, statuss, vendorIDs []int, return pagedInfo, err } -func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) { +func GetJob(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (job *model.Job, err error) { + jobs, err := GetJobsNoPage(db, userIDs, categoryIDs, statuss, types, fromTime, toTime, includeStep) + if err != nil { + return job, err + } + if data, err := json.Marshal(jobs[0]); err == nil { + json.Unmarshal(data, job) + } + return job, err +} + +func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss, types []int, fromTime, toTime time.Time, includeStep bool) (jobs []*GetJobsResult, err error) { sql := ` SELECT a.*, b.name FROM job a @@ -120,6 +136,10 @@ func GetJobsNoPage(db *DaoDB, userIDs []string, categoryIDs, statuss []int, from sql += ` AND a.status IN (` + GenQuestionMarks(len(statuss)) + `)` sqlParams = append(sqlParams, statuss) } + if len(types) > 0 { + sql += ` AND a.type IN (` + GenQuestionMarks(len(types)) + `)` + sqlParams = append(sqlParams, types) + } if fromTime != utils.ZeroTimeValue { sql += ` AND a.created_at >= ?` sqlParams = append(sqlParams, fromTime) diff --git a/business/model/job.go b/business/model/job.go index f7cd1a51c..e7c0a76c5 100644 --- a/business/model/job.go +++ b/business/model/job.go @@ -21,14 +21,15 @@ const ( JobOrderStatusFinish = 110 JobOrderStatusCancel = 115 - JobIDMtMembers = 1 //美团会员任务ID - JobIDJdDelivery = 2 //京东物流任务ID - JobTimerTypeAccept = 1 //接受任务 JobTimerTypeSubmit = 2 //交任务 JobTimerStatusWait = 0 //正在进行 JobTimerStatusFinish = 1 //定时任务已完成 + + JobTypeNormal = 0 //普通任务 + JobTypeMtMember = 1 //美团会员任务 + JobTypeJdDelivery = 2 //京东快递任务 ) type Job struct { @@ -54,6 +55,7 @@ type Job struct { VendorID int `orm:"column(vendor_id)" json:"vendorID"` //推广平台 StoreURL string `orm:"column(store_url)" json:"storeURL"` //门店链接 SkuURL string `orm:"column(sku_url)" json:"skuURL"` //商品优惠券链接 + Type int `json:"type"` //任务类型,0为普通任务,1为特殊任务 JobSteps []*JobStep `orm:"-" json:"jobSteps"` JobImgs []*JobImg `orm:"-" json:"jobImgs"` }