pay
This commit is contained in:
@@ -106,44 +106,57 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
|||||||
order = &model.Order{
|
order = &model.Order{
|
||||||
OrderID: orderID,
|
OrderID: orderID,
|
||||||
PayPrice: payPrice,
|
PayPrice: payPrice,
|
||||||
|
UserID: orderInfo.UserID,
|
||||||
PayMethod: 5, //混合支付
|
PayMethod: 5, //混合支付
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
order = &model.Order{
|
order = &model.Order{
|
||||||
OrderID: orderID,
|
OrderID: orderID,
|
||||||
PayPrice: orderInfo.PayPrice,
|
PayPrice: orderInfo.PayPrice,
|
||||||
|
UserID: orderInfo.UserID,
|
||||||
PayMethod: 2, //微信支付
|
PayMethod: 2, //微信支付
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globals.SugarLogger.Debug("order.OrderID after=========================", order.OrderID)
|
globals.SugarLogger.Debug("检验初始数据情况", order.OrderID, order.PayPrice, order.PayMethod)
|
||||||
globals.SugarLogger.Debug("order.PayPrice after=========================", order.PayPrice)
|
txdb, _ := dao.Begin(db)
|
||||||
globals.SugarLogger.Debug("order.PayMethod after=========================", order.PayMethod)
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
panic(r)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
//微信支付实际金额更新到数据库
|
||||||
|
if _, err := dao.UpdateEntity(db, order, "PayPrice"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _, err := dao.UpdateEntity(db, order, "PayMethod"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
//if _, err := dao.UpdateEntityTx(txdb, &order, "PayPrice"); err != nil {
|
||||||
|
// dao.Rollback(db, txdb)
|
||||||
|
// return nil, err
|
||||||
|
//}
|
||||||
|
//if _, err := dao.UpdateEntityTx(txdb, &order, "PayMethod"); err != nil {
|
||||||
|
// dao.Rollback(db, txdb)
|
||||||
|
// return nil, err
|
||||||
|
//}
|
||||||
|
dao.Commit(db, txdb)
|
||||||
|
globals.SugarLogger.Debug("经过更新操作后的数据after=========================", order.OrderID, order.PayPrice, order.PayMethod)
|
||||||
globals.SugarLogger.Debugf("pay begin……")
|
globals.SugarLogger.Debugf("pay begin……")
|
||||||
//err = dao.GetEntity(db, order, "OrderID")
|
err = dao.GetEntity(db, order, "OrderID")
|
||||||
if order.OrderID == "" {
|
if order.OrderID == "" {
|
||||||
return result, fmt.Errorf("未找到此订单!")
|
return result, fmt.Errorf("未找到此订单!")
|
||||||
}
|
}
|
||||||
payHandler.Order = order
|
payHandler.Order = order
|
||||||
globals.SugarLogger.Debug("order.payprice==================", payHandler.Order.PayPrice)
|
globals.SugarLogger.Debug("再次从数据库获得order详情", payHandler.Order.PayPrice, payHandler.Order.PayMethod)
|
||||||
//如果用户没有对应账单信息就给他生成一条
|
//如果用户没有对应账单信息就给他生成一条
|
||||||
txDB, _ := dao.Begin(db)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
dao.Rollback(db, txDB)
|
|
||||||
panic(r)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 给用户创建一个银行卡账户
|
// 给用户创建一个银行卡账户
|
||||||
globals.SugarLogger.Debug("create bill begin……")
|
globals.SugarLogger.Debug("create bill begin……")
|
||||||
globals.SugarLogger.Debug("order.UserID……", order.UserID)
|
|
||||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||||
if userBill == nil {
|
if userBill == nil {
|
||||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
globals.SugarLogger.Debug("order.UserID,userBill=======================", order.UserID, userBill)
|
||||||
|
err = financial.AddUserBill(txdb, jxutils.GenBillID(), order.UserID)
|
||||||
}
|
}
|
||||||
err = payHandler.CreatePay(txDB, appId)
|
err = payHandler.CreatePay(txdb, appId)
|
||||||
globals.SugarLogger.Debug("errrrrr=========================", err)
|
|
||||||
//dao.Commit(db, txDB)
|
|
||||||
globals.SugarLogger.Debug("the last step of this program,return err……", err)
|
globals.SugarLogger.Debug("the last step of this program,return err……", err)
|
||||||
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
||||||
return payHandler.WxPayParam, err
|
return payHandler.WxPayParam, err
|
||||||
@@ -192,6 +205,7 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
}
|
}
|
||||||
dao.Commit(db, txDB)
|
dao.Commit(db, txDB)
|
||||||
}()
|
}()
|
||||||
|
//增加账单 余额减去相应金额
|
||||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, order.PayPrice, 0); err != nil {
|
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, order.PayPrice, 0); err != nil {
|
||||||
dao.Rollback(db, txDB)
|
dao.Rollback(db, txDB)
|
||||||
return nil, "使用余额支付失败:", err
|
return nil, "使用余额支付失败:", err
|
||||||
@@ -222,6 +236,7 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
|||||||
globals.SugarLogger.Debug("进入混合支付部分")
|
globals.SugarLogger.Debug("进入混合支付部分")
|
||||||
//orderInfo.PayMethod = 5 //混合支付状态
|
//orderInfo.PayMethod = 5 //混合支付状态
|
||||||
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
||||||
|
|
||||||
globals.SugarLogger.Debug("needPay=================", needPay)
|
globals.SugarLogger.Debug("needPay=================", needPay)
|
||||||
globals.SugarLogger.Debug("orderInfo.PayPrice=================", orderInfo.PayPrice)
|
globals.SugarLogger.Debug("orderInfo.PayPrice=================", orderInfo.PayPrice)
|
||||||
globals.SugarLogger.Debug("orderInfo.OrderID=================", orderInfo.OrderID)
|
globals.SugarLogger.Debug("orderInfo.OrderID=================", orderInfo.OrderID)
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ func OnTLPayCallback(call *tonglianpayapi.CallBackResult) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||||
|
globals.SugarLogger.Debug("进入微信回调============================")
|
||||||
order := &model.Order{
|
order := &model.Order{
|
||||||
OrderID: call.CusorderID,
|
OrderID: call.CusorderID,
|
||||||
}
|
}
|
||||||
@@ -272,21 +273,25 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
|||||||
if (order.OrderType == 2 || order.OrderType == 5) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if (order.OrderType == 2 || order.OrderType == 5) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
return OnWXPayFinished(order)
|
return OnWXPayFinished(order)
|
||||||
} else if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
} else if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
|
globals.SugarLogger.Debug("得到微信回调结果,快递流程开始")
|
||||||
txdb, _ := dao.Begin(db)
|
txdb, _ := dao.Begin(db)
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
panic(r)
|
panic(r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
globals.SugarLogger.Debug("更新order")
|
||||||
if _, err := dao.UpdateEntityTx(txdb, order); err != nil {
|
if _, err := dao.UpdateEntityTx(txdb, order); err != nil {
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, txdb)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
globals.SugarLogger.Debug("获取UserVendorOrder")
|
||||||
userOrder := model.UserVendorOrder{LocalWayBill: order.OrderID}
|
userOrder := model.UserVendorOrder{LocalWayBill: order.OrderID}
|
||||||
if err := dao.GetEntity(db, &userOrder, "LocalWayBill"); err != nil {
|
if err := dao.GetEntity(db, &userOrder, "LocalWayBill"); err != nil {
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, txdb)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
globals.SugarLogger.Debug("更新UserVendorOrder")
|
||||||
userOrder.OrderStatus = payStatus
|
userOrder.OrderStatus = payStatus
|
||||||
if _, err := dao.UpdateEntityTx(txdb, &userOrder, "OrderStatus"); err != nil {
|
if _, err := dao.UpdateEntityTx(txdb, &userOrder, "OrderStatus"); err != nil {
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, txdb)
|
||||||
@@ -294,32 +299,31 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
|||||||
}
|
}
|
||||||
//1-余额,2-微信,5-混合
|
//1-余额,2-微信,5-混合
|
||||||
if order.PayMethod == 5 {
|
if order.PayMethod == 5 {
|
||||||
|
globals.SugarLogger.Debug("进入混合支付回调流程")
|
||||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//创建混合支付账单
|
//创建混合支付账单
|
||||||
totalPrice := order.PayPrice + userBill.AccountBalance
|
totalPrice := order.PayPrice + userBill.AccountBalance
|
||||||
if err := AddMixPay(txdb, order.OrderID, userBill.AccountBalance, totalPrice, 5); err != nil {
|
globals.SugarLogger.Debug("totalPrice=================", totalPrice)
|
||||||
|
globals.SugarLogger.Debug("进入增加mixpay账单")
|
||||||
|
if err := AddMixPay(txdb, order.OrderID, userBill.AccountBalance, totalPrice, 1); err != nil {
|
||||||
|
globals.SugarLogger.Debug("增加mixpay账单失败")
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, txdb)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//余额清空
|
//余额清空
|
||||||
|
globals.SugarLogger.Debug("开始清空余额")
|
||||||
if err := dao.UpdateUserBill(order.UserID, 0); err != nil {
|
if err := dao.UpdateUserBill(order.UserID, 0); err != nil {
|
||||||
globals.SugarLogger.Debug("修改余额失败")
|
globals.SugarLogger.Debug("修改余额失败")
|
||||||
dao.Rollback(db, txdb)
|
dao.Rollback(db, txdb)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if order.PayMethod == 5 || order.PayMethod == 2 {
|
|
||||||
//更新order状态
|
|
||||||
order.Status = 110 //支付成功
|
|
||||||
if _, err := dao.UpdateEntityTx(txdb, &order, "Status"); err != nil {
|
|
||||||
dao.Rollback(db, txdb)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dao.Commit(db, txdb)
|
dao.Commit(db, txdb)
|
||||||
|
globals.SugarLogger.Debug("call.TrxStatus======================", call.TrxStatus)
|
||||||
|
globals.SugarLogger.Debug("order.OrderType======================", order.OrderType)
|
||||||
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||||
switch order.OrderType {
|
switch order.OrderType {
|
||||||
case model.PayType4Express:
|
case model.PayType4Express:
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ type MixPay struct {
|
|||||||
BalancePrice int `orm:"column(balance_price)" json:"balance_price"` //余额支付部分
|
BalancePrice int `orm:"column(balance_price)" json:"balance_price"` //余额支付部分
|
||||||
TotalPrice int `orm:"column(total_price)" json:"total_price"` //订单总额
|
TotalPrice int `orm:"column(total_price)" json:"total_price"` //订单总额
|
||||||
WxPrice int `orm:"column(wx_price)" json:"wx_price"` //微信支付部分
|
WxPrice int `orm:"column(wx_price)" json:"wx_price"` //微信支付部分
|
||||||
Status int `orm:"column(status)" json:"status"` //订单状态 退款/正常
|
Status int `orm:"column(status)" json:"status"` //订单状态 -1:退款/1:正常
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *MixPay) TableIndex() [][]string {
|
func (v *MixPay) TableIndex() [][]string {
|
||||||
|
|||||||
Reference in New Issue
Block a user