1
This commit is contained in:
@@ -144,10 +144,10 @@ func CheckMobileAndFlowCode(mobile, flowCode string) (bool, error) {
|
||||
|
||||
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, isChoose int) (result *financial.WxPayParam, err error) {
|
||||
var (
|
||||
temp_PayPrice int
|
||||
temp_PayMethod int
|
||||
db = dao.GetDB()
|
||||
txdb, _ = dao.Begin(db)
|
||||
tempPayprice int
|
||||
tempPaymethod int
|
||||
db = dao.GetDB()
|
||||
tdb, _ = dao.Begin(db)
|
||||
)
|
||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||
if err != nil {
|
||||
@@ -169,23 +169,23 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
||||
// 查询用户余额
|
||||
userBill, err := dao.GetUserBill(db, ctx.GetUserID(), "")
|
||||
if err != nil || userBill == nil { // 出现错误或异常直接使用金钱支付
|
||||
temp_PayPrice = orderInfo.PayPrice
|
||||
temp_PayMethod = model.OrderPayMethodWX
|
||||
tempPayprice = orderInfo.PayPrice
|
||||
tempPaymethod = model.OrderPayMethodWX
|
||||
} else {
|
||||
if userBill.AccountBalance-orderInfo.PayPrice >= 0 { // 余额大于支付金额,使用余额支付
|
||||
switch orderInfo.OrderType { // 1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单,7-话费
|
||||
case 2, 5:
|
||||
case model.OrderTypeMember, model.OrderTypeMemberYear:
|
||||
if err := financial.OnWXPayFinished(orderInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case 3:
|
||||
case model.OrderTypeDelivery:
|
||||
call := &tonglianpayapi.CallBackResult{}
|
||||
call.TrxID = "ziDingYi_" + utils.Int64ToStr(time.Now().Unix())
|
||||
call.TrxStatus = tonglianpayapi.TrxStatusSuccess
|
||||
if err := financial.OnWxPaySendPage(dao.GetDB(), orderInfo, call, 4); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case 7:
|
||||
case model.OrderTypeMobile:
|
||||
if err := financial.OnWxPayTelephone(orderInfo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -193,39 +193,39 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
||||
return nil, errors.New("其他待处理信息,联系管理员")
|
||||
}
|
||||
//账户支出
|
||||
if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
if err = financial.AddExpendUpdateAccount(tdb, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 1); err != nil {
|
||||
dao.Rollback(db, tdb)
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
} else {
|
||||
// 混合支付
|
||||
temp_PayPrice = orderInfo.PayPrice - userBill.AccountBalance
|
||||
temp_PayMethod = model.OrderPayMethodMix
|
||||
tempPayprice = orderInfo.PayPrice - userBill.AccountBalance
|
||||
tempPaymethod = model.OrderPayMethodMix
|
||||
//账户支出
|
||||
if err = financial.AddExpendUpdateAccount(txdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil {
|
||||
dao.Rollback(db, txdb)
|
||||
if err = financial.AddExpendUpdateAccount(tdb, userBill, model.BillTypePayByAccountBalance, userBill.AccountBalance, 1); err != nil {
|
||||
dao.Rollback(db, tdb)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else { // 原价给
|
||||
temp_PayPrice = orderInfo.PayPrice
|
||||
temp_PayMethod = model.OrderPayMethodWX
|
||||
tempPayprice = orderInfo.PayPrice
|
||||
tempPaymethod = model.OrderPayMethodWX
|
||||
}
|
||||
|
||||
orderInfo.PayPrice = temp_PayPrice
|
||||
orderInfo.PayMethod = temp_PayMethod
|
||||
orderInfo.PayPrice = tempPayprice
|
||||
orderInfo.PayMethod = tempPaymethod
|
||||
dao.UpdateEntity(dao.GetDB(), orderInfo, "PayPrice", "PayMethod")
|
||||
payHandler.Order = orderInfo
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
// 给用户创建一个银行卡账户
|
||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||
if userBill == nil {
|
||||
err = financial.AddUserBill(txdb, jxutils.GenBillID(), orderInfo.UserID)
|
||||
err = financial.AddUserBill(tdb, jxutils.GenBillID(), orderInfo.UserID)
|
||||
}
|
||||
err = payHandler.CreatePay(txdb, appId)
|
||||
err = payHandler.CreatePay(tdb, appId)
|
||||
return payHandler.WxPayParam, err
|
||||
}
|
||||
|
||||
@@ -235,12 +235,10 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//获取订单信息
|
||||
globals.SugarLogger.Debug("begin get pay_by_balance")
|
||||
orderInfo, err := dao.GetOrderByID(db, orderID)
|
||||
if err != nil {
|
||||
return nil, "获取订单信息失败", err
|
||||
}
|
||||
globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType)
|
||||
//获取用户 会员账户信息
|
||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||
if err != nil {
|
||||
@@ -320,7 +318,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
||||
//(2)用户使用余额,剩余微信支付
|
||||
totalPrice := orderInfo.PayPrice //订单原价
|
||||
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
||||
globals.SugarLogger.Debug("totalprice=====,needpay=====", totalPrice, needPay)
|
||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
||||
if err != nil {
|
||||
return nil, "微信支付失败:", err
|
||||
@@ -331,7 +328,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
||||
}
|
||||
if isChoose == model.PayNotChooseBalance {
|
||||
//(3)不选中余额支付 即直接微信支付
|
||||
globals.SugarLogger.Debug("进入PayNotChooseBalance==================")
|
||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||
if err != nil {
|
||||
return nil, "微信支付失败:", err
|
||||
|
||||
Reference in New Issue
Block a user