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