This commit is contained in:
苏尹岚
2020-10-14 18:29:36 +08:00
parent 0ff054afed
commit 54438022ff
15 changed files with 223 additions and 113 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"time"
"git.rosy.net.cn/jx-callback/business/jxstore/financial"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
@@ -30,9 +32,20 @@ func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
// switch job.JobCategoryID {
// case 1:
// }
// if ctx.GetUserID() != job.UserID {
// return fmt.Errorf("用户信息已过期,请重新登录!")
// }
if ctx.GetUserID() != job.UserID {
return fmt.Errorf("用户信息已过期,请重新登录!")
}
//发布任务要扣除任务总额的保证金,不够扣就要进行充值
userBill, err := dao.GetUserBill(db, job.UserID, "")
if userBill == nil {
return fmt.Errorf("未查询到该用户的账单!")
}
job.TotalPrice = job.Count * job.AvgPrice
if userBill.DepositBalance < job.TotalPrice {
job.Status = model.JobStatusFailed
} else {
job.Status = model.JobStatusDoing
}
if job.Count <= 0 {
return fmt.Errorf("任务数量不能为0")
}
@@ -57,8 +70,6 @@ func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
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() {
@@ -76,6 +87,18 @@ func PublishJob(ctx *jxcontext.Context, job *model.Job) (err error) {
if err != nil {
dao.Rollback(db)
}
//发布任务要扣除任务总额的保证金,不够扣就要进行充值
if err == nil && job.Status != model.JobStatusFailed {
//1、账户支出增加一条记录
if err = financial.AddBillExpend(db, userBill.BillID, model.OrderTypeDeposit, job.TotalPrice); err != nil {
dao.Rollback(db)
}
//2、账户表保证金总额增加相应值
userBill.DepositBalance -= job.TotalPrice
if _, err = dao.UpdateEntity(db, userBill, "DepositBalance"); err != nil {
dao.Rollback(db)
}
}
dao.Commit(db)
return err
}