cash finish
This commit is contained in:
@@ -60,7 +60,7 @@ func Pay(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (er
|
||||
return err
|
||||
}
|
||||
|
||||
func Cash(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (err error) {
|
||||
func Cash(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
order = &model.Order{
|
||||
@@ -79,6 +79,9 @@ func Cash(ctx *jxcontext.Context, orderID, payType int, vendorPayType string) (e
|
||||
if userBill == nil {
|
||||
err = financial.AddUserBill(db, jxutils.GenBillID(), order.UserID)
|
||||
}
|
||||
if userBill.AccountBalance < order.PayPrice {
|
||||
return model.ErrCodeAccountBalanceNotEnough, err
|
||||
}
|
||||
err = payHandler.CreateRefund()
|
||||
return err
|
||||
return errCode, err
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ func (p *PayHandler) CreateRefund() (err error) {
|
||||
if authInfo, err := p.Ctx.GetV2AuthInfo(); err == nil && authInfo.GetAuthType() == weixin.AuthTypeWxApp {
|
||||
param.OpenID = authInfo.GetAuthID()
|
||||
}
|
||||
globals.SugarLogger.Debugf("CreateRefund wx param: %v", utils.Format4Output(param, false))
|
||||
result, err := api.WxpayAPI.Transfers(param)
|
||||
if err == nil {
|
||||
p.Order.PayFinishedAt = utils.Str2Time(result.PaymentTime)
|
||||
@@ -94,7 +95,7 @@ func (p *PayHandler) CreateRefund() (err error) {
|
||||
}
|
||||
dao.UpdateEntity(dao.GetDB(), p.Order)
|
||||
if result.ReturnMsg == "" {
|
||||
err = OnPayFinished(p.Order)
|
||||
err = OnCashFinished(p.Order)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -46,7 +46,7 @@ func OnPayFinished(order *model.Order) (err error) {
|
||||
switch order.Type {
|
||||
case model.OrderTypeAccount:
|
||||
//如果是账户充值(发布任务等)
|
||||
//1、账户收入表增加一条保证金记录
|
||||
//1、账户收入表明细
|
||||
if err = AddBillIncome(db, billID, order.Type, order.PayPrice); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
@@ -63,3 +63,44 @@ func OnPayFinished(order *model.Order) (err error) {
|
||||
globals.SugarLogger.Debugf("OnPayFinished end modify account ...")
|
||||
return err
|
||||
}
|
||||
|
||||
func OnCashFinished(order *model.Order) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
billID int64
|
||||
)
|
||||
globals.SugarLogger.Debugf("OnCashFinished begin modify account order: %v", utils.Format4Output(order, false))
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if userBill == nil {
|
||||
globals.SugarLogger.Debugf("OnCashFinished 未找到该用户的账单 order: %v", utils.Format4Output(order, false))
|
||||
return fmt.Errorf("未找到该用户的账单!%v", order.UserID)
|
||||
}
|
||||
//根据订单类型来操作账户
|
||||
switch order.Type {
|
||||
case model.OrderTypeAccount:
|
||||
//如果是账户提现
|
||||
//1、账户支出明细增加一条
|
||||
if err = AddBillExpend(db, billID, order.Type, order.PayPrice); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
//2、账户表账户余额减少相应值
|
||||
userBill.AccountBalance -= order.PayPrice
|
||||
if _, err = dao.UpdateEntity(db, userBill, "AccountBalance"); err != nil {
|
||||
dao.Rollback(db)
|
||||
}
|
||||
default:
|
||||
globals.SugarLogger.Debugf("OnPayFinished 暂不支持此订单类型 order: %v", utils.Format4Output(order, false))
|
||||
return fmt.Errorf("暂不支持此订单类型!")
|
||||
}
|
||||
dao.Commit(db)
|
||||
globals.SugarLogger.Debugf("OnCashFinished end modify account ...")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ func (c *OrderController) Pay() {
|
||||
// @router /Cash [post]
|
||||
func (c *OrderController) Cash() {
|
||||
c.callCash(func(params *tOrderCashParams) (retVal interface{}, errCode string, err error) {
|
||||
err = cms.Cash(params.Ctx, params.OrderID, params.PayType, params.VendorPayType)
|
||||
return retVal, "", err
|
||||
errCode, err = cms.Cash(params.Ctx, params.OrderID, params.PayType, params.VendorPayType)
|
||||
return retVal, errCode, err
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user