余额不足

This commit is contained in:
苏尹岚
2020-10-29 14:04:31 +08:00
parent baed9d8c4b
commit b485bb7bec

View File

@@ -61,7 +61,7 @@ func getWeekTime() (weekTimeBegin, weekTimeEnd time.Time) {
return weekTimeBegin, weekTimeEnd return weekTimeBegin, weekTimeEnd
} }
func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (err error) { func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (errCode string, err error) {
var ( var (
db = dao.GetDB() db = dao.GetDB()
job = &model.Job{} job = &model.Job{}
@@ -78,42 +78,40 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (err error) {
json.Unmarshal(data, &job) json.Unmarshal(data, &job)
} }
if job.UserID == "" { if job.UserID == "" {
return fmt.Errorf("参数有误!") return errCode, fmt.Errorf("参数有误!")
} }
if ctx.GetUserID() != job.UserID { if ctx.GetUserID() != job.UserID {
return fmt.Errorf("用户信息已过期,请重新登录!") return errCode, fmt.Errorf("用户信息已过期,请重新登录!")
} }
//发布任务要扣除任务总额的保证金,不够扣就要进行充值 //发布任务要扣除任务总额的保证金,不够扣就要进行充值
userBill, err := dao.GetUserBill(db, job.UserID, "") userBill, err := dao.GetUserBill(db, job.UserID, "")
if userBill == nil { if userBill == nil {
return fmt.Errorf("未查询到该用户的账单!") return errCode, fmt.Errorf("未查询到该用户的账单!")
} }
job.TotalPrice = job.Count * job.AvgPrice job.TotalPrice = job.Count * job.AvgPrice
if userBill.AccountBalance < job.TotalPrice { if userBill.AccountBalance < job.TotalPrice {
job.Status = model.JobStatusFailed return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("用户余额不足!")
} else {
job.Status = model.JobStatusDoing
} }
if job.Count <= 0 { if job.Count <= 0 {
return fmt.Errorf("任务数量不能为0") return errCode, fmt.Errorf("任务数量不能为0")
} }
if job.UserID == "" { if job.UserID == "" {
return fmt.Errorf("任务发起人不能为空!") 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, DayTimeBegin, DayTimeEnd, 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 {
return err return errCode, err
} }
if len(members) <= 0 { if len(members) <= 0 {
return fmt.Errorf("非会员一天只能发布一起任务,请确认!") return errCode, fmt.Errorf("非会员一天只能发布一起任务,请确认!")
} }
} }
if job.Address != "" && (job.Lng == 0 || job.Lat == 0) { if job.Address != "" && (job.Lng == 0 || job.Lat == 0) {
lng, lat, err := api.AutonaviAPI.GetCoordinateFromAddressByPage(job.Address) lng, lat, err := api.AutonaviAPI.GetCoordinateFromAddressByPage(job.Address)
if err != nil { if err != nil {
return err return errCode, err
} }
job.Lng = jxutils.StandardCoordinate2Int(lng) job.Lng = jxutils.StandardCoordinate2Int(lng)
job.Lat = jxutils.StandardCoordinate2Int(lat) job.Lat = jxutils.StandardCoordinate2Int(lat)
@@ -147,7 +145,7 @@ func PublishJob(ctx *jxcontext.Context, jobExt *model.JobExt) (err error) {
} }
} }
dao.Commit(db) dao.Commit(db)
return err return errCode, err
} }
func CancelPublishJob(ctx *jxcontext.Context, jobID int) (err error) { func CancelPublishJob(ctx *jxcontext.Context, jobID int) (err error) {