This commit is contained in:
苏尹岚
2021-04-21 17:30:28 +08:00
parent a500b2631b
commit 433b980c52

View File

@@ -117,29 +117,26 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e
if job.Count <= 0 { if job.Count <= 0 {
return errCode, fmt.Errorf("任务数量不能为0") return errCode, fmt.Errorf("任务数量不能为0")
} }
fmt.Println("1111111111111111111111111111111111", ctx.GetToken())
job.SurplusCount = job.Count job.SurplusCount = job.Count
if job.UserID == "" { if job.UserID == "" {
return errCode, fmt.Errorf("任务发起人不能为空!") return errCode, fmt.Errorf("任务发起人不能为空!")
} }
var (
userBill *model.UserBill
)
if ctx.GetToken() != jxcontext.RsmDefultToken {
if ctx.GetUserID() != job.UserID { if ctx.GetUserID() != job.UserID {
return errCode, fmt.Errorf("用户信息已过期,请重新登录!") return errCode, fmt.Errorf("用户信息已过期,请重新登录!")
} }
if job.FinishedAt.Sub(time.Now()) <= 0 {
return errCode, fmt.Errorf("任务截止日期必须大于今天!")
}
if job2, _ := dao.GetJobWithTitle(db, job.Title); job2 != nil {
return errCode, fmt.Errorf("任务标题重复,请重新输入!")
}
if job.JobCityCode != model.JobCountrywideCode {
_, _, job.JobCityCode, err = getAddressInfoFromCoord(db, job.JobLng, job.JobLat)
}
//验证微信绑定 //验证微信绑定
if err = auth2.CheckWeixinminiAuthBind(ctx.GetUserID()); err != nil { if err = auth2.CheckWeixinminiAuthBind(ctx.GetUserID()); err != nil {
return "", err return "", err
} }
fmt.Println("1111111111111111111111111111111111", ctx.GetLoginType())
//发布任务要扣除任务总额的保证金,不够扣就要进行充值 //发布任务要扣除任务总额的保证金,不够扣就要进行充值
userBill, err := dao.GetUserBill(db, job.UserID, "") userBill, _ = dao.GetUserBill(db, job.UserID, "")
if userBill == nil { if userBill == nil {
return errCode, fmt.Errorf("未查询到该用户的账单!") return errCode, fmt.Errorf("未查询到该用户的账单!")
} }
@@ -147,8 +144,7 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e
if userBill.AccountBalance < job.TotalPrice { if userBill.AccountBalance < job.TotalPrice {
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!") return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!")
} }
jobs, _ := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, DayTimeBegin, DayTimeEnd, 0, false)
jobs, err := dao.GetJobsNoPage(db, []string{job.UserID}, nil, nil, nil, DayTimeBegin, DayTimeEnd, 0, false)
if len(jobs) > 0 { if len(jobs) > 0 {
members, err := dao.GetUserMember(db, job.UserID, model.MemberTypeNormal) members, err := dao.GetUserMember(db, job.UserID, model.MemberTypeNormal)
if err != nil { if err != nil {
@@ -166,6 +162,17 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e
job.Lng = jxutils.StandardCoordinate2Int(lng) job.Lng = jxutils.StandardCoordinate2Int(lng)
job.Lat = jxutils.StandardCoordinate2Int(lat) job.Lat = jxutils.StandardCoordinate2Int(lat)
} }
}
if job.FinishedAt.Sub(time.Now()) <= 0 {
return errCode, fmt.Errorf("任务截止日期必须大于今天!")
}
if job2, _ := dao.GetJobWithTitle(db, job.Title); job2 != nil {
return errCode, fmt.Errorf("任务标题重复,请重新输入!")
}
if job.JobCityCode != model.JobCountrywideCode {
_, _, job.JobCityCode, err = getAddressInfoFromCoord(db, job.JobLng, job.JobLat)
}
dao.WrapAddIDCULDEntity(job, ctx.GetUserName()) dao.WrapAddIDCULDEntity(job, ctx.GetUserName())
txDB, _ := dao.Begin(db) txDB, _ := dao.Begin(db)
defer func() { defer func() {
@@ -193,13 +200,14 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e
return return
} }
//发布任务要扣除任务总额的保证金,不够扣就要进行充值 //发布任务要扣除任务总额的保证金,不够扣就要进行充值
if err == nil && job.Status != model.JobStatusFailed { if err == nil && job.Status != model.JobStatusFailed && ctx.GetToken() != jxcontext.RsmDefultToken {
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeDeposit, job.TotalPrice, job.ID); err != nil { if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypeDeposit, job.TotalPrice, job.ID); err != nil {
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
return return
} }
} }
dao.Commit(db, txDB) dao.Commit(db, txDB)
if ctx.GetToken() != jxcontext.RsmDefultToken {
content := new(strings.Builder) content := new(strings.Builder)
content.WriteString("您的任务:") content.WriteString("您的任务:")
content.WriteString(job.Title) content.WriteString(job.Title)
@@ -207,6 +215,7 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, e
content.WriteString(utils.Float64ToStr(jxutils.IntPrice2Standard(int64(job.TotalPrice)))) content.WriteString(utils.Float64ToStr(jxutils.IntPrice2Standard(int64(job.TotalPrice))))
content.WriteString("元") content.WriteString("元")
event.SendSysMessageSimple(content.String(), job.UserID) event.SendSysMessageSimple(content.String(), job.UserID)
}
return errCode, err return errCode, err
} }