bill job
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -11,10 +11,6 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
const (
|
||||
OrderTypeDeposit = 1 //保证金
|
||||
)
|
||||
|
||||
func CreateOrder(ctx *jxcontext.Context, price, orderType int) (order *model.Order, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
@@ -47,8 +43,24 @@ func Pay(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (er
|
||||
order = &model.Order{
|
||||
OrderID: int64(orderID),
|
||||
}
|
||||
payHandler = &financial.PayHandler{
|
||||
PayType: payType,
|
||||
Ctx: ctx,
|
||||
VendorPayType: vendorPayType,
|
||||
}
|
||||
)
|
||||
err = dao.GetEntity(db, order, "OrderID")
|
||||
err = financial.IPayHandler.CreatePay(order, payType, vendorPayType)
|
||||
payHandler.Order = order
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if userBill == nil {
|
||||
userBillInsert := &model.UserBill{
|
||||
BillID: jxutils.GenBillID(),
|
||||
UserID: order.UserID,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(userBillInsert, jxcontext.AdminCtx.GetUserName())
|
||||
err = dao.CreateEntity(db, userBillInsert)
|
||||
}
|
||||
err = payHandler.CreatePay()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -206,12 +206,25 @@ func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVeri
|
||||
} else {
|
||||
outAuthInfo, err = auth2.BindUser(inAuthInfo, user)
|
||||
}
|
||||
//给用户添加一条账单记录
|
||||
err = AddUserBill(user)
|
||||
} else if dao.IsDuplicateError(err) {
|
||||
err = auth2.ErrUserID2AlreadyExist
|
||||
}
|
||||
return outAuthInfo, err
|
||||
}
|
||||
|
||||
func AddUserBill(user *model.User) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
userBill := &model.UserBill{
|
||||
BillID: jxutils.GenBillID(),
|
||||
UserID: user.UserID,
|
||||
}
|
||||
return dao.CreateEntity(db, userBill)
|
||||
}
|
||||
|
||||
func GetUserBindAuthInfo(ctx *jxcontext.Context) (authList []*model.AuthBind, err error) {
|
||||
authInfo, err := ctx.GetV2AuthInfo()
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user