新增混合支付+完善新会员充值
This commit is contained in:
@@ -118,6 +118,67 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
||||
return payHandler.WxPayParam, err
|
||||
}
|
||||
|
||||
var (
|
||||
NotPay = 2 //订单待支付
|
||||
AlreadyPay = 1 //订单已支付
|
||||
)
|
||||
|
||||
//余额支付 微信补差值
|
||||
func PayByBalance(ctx *jxcontext.Context, orderID string, payType, restPrice int, appID, vendorPayType string) (errMsg string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//获取订单信息
|
||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||
if err != nil {
|
||||
return "获取订单信息失败", err
|
||||
}
|
||||
//获取用户 会员账户信息
|
||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||
if err != nil {
|
||||
return "获取用户会员账户余额失败", err
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if orderInfo.Status == NotPay {
|
||||
if userBill.AccountBalance > 0 {
|
||||
//余额 全款支付
|
||||
if userBill.AccountBalance > orderInfo.PayPrice && userBill.AccountBalance-orderInfo.PayPrice > 0 {
|
||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return "使用余额支付失败:", err
|
||||
}
|
||||
orderInfo.Status = AlreadyPay
|
||||
} else {
|
||||
//需支付部分
|
||||
//restPrice := orderInfo.PayPrice - userBill.AccountBalance
|
||||
orderInfo.PayPrice = restPrice
|
||||
if _, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID); err != nil {
|
||||
return "微信支付失败:", err
|
||||
}
|
||||
//支付成功后修改余额为0
|
||||
if err := dao.UpdateUserBill(orderInfo.UserID, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return "余额修改失败:", err
|
||||
}
|
||||
//增加一条用户账单
|
||||
if err = financial.AddBillExpend(txDB, userBill.BillID, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return "使用余额支付失败:", err
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
func Cash(ctx *jxcontext.Context, orderID string, payType int, vendorPayType string) (errCode string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
@@ -146,6 +207,15 @@ func GetOrders(ctx *jxcontext.Context, orderID, userID string, orderType int, ci
|
||||
return dao.GetOrders(dao.GetDB(), orderID, userID, orderType, cityCodes, utils.Str2Time(fromTime), utils.Str2Time(toTime), keyword, offset, pageSize)
|
||||
}
|
||||
|
||||
//id获取订单详情(单条查询)
|
||||
//func GetOrderByID(ctx *jxcontext.Context, orderID int) (errMsg string, err error) {
|
||||
// //var db = dao.GetDB()
|
||||
// if _, err := dao.GetOrderByID(dao.GetDB(), orderID); err != nil {
|
||||
// return "id获取订单详情失败", err
|
||||
// }
|
||||
// return "", err
|
||||
//}
|
||||
|
||||
func FinishedCashOrders(ctx *jxcontext.Context, orderIDs []string) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
|
||||
Reference in New Issue
Block a user