pay
This commit is contained in:
@@ -106,44 +106,57 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
||||
order = &model.Order{
|
||||
OrderID: orderID,
|
||||
PayPrice: payPrice,
|
||||
UserID: orderInfo.UserID,
|
||||
PayMethod: 5, //混合支付
|
||||
}
|
||||
} else {
|
||||
order = &model.Order{
|
||||
OrderID: orderID,
|
||||
PayPrice: orderInfo.PayPrice,
|
||||
UserID: orderInfo.UserID,
|
||||
PayMethod: 2, //微信支付
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debug("order.OrderID after=========================", order.OrderID)
|
||||
globals.SugarLogger.Debug("order.PayPrice after=========================", order.PayPrice)
|
||||
globals.SugarLogger.Debug("order.PayMethod after=========================", order.PayMethod)
|
||||
globals.SugarLogger.Debug("检验初始数据情况", order.OrderID, order.PayPrice, order.PayMethod)
|
||||
txdb, _ := dao.Begin(db)
|
||||
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……")
|
||||
//err = dao.GetEntity(db, order, "OrderID")
|
||||
err = dao.GetEntity(db, order, "OrderID")
|
||||
if order.OrderID == "" {
|
||||
return result, fmt.Errorf("未找到此订单!")
|
||||
}
|
||||
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("order.UserID……", order.UserID)
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
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)
|
||||
globals.SugarLogger.Debug("errrrrr=========================", err)
|
||||
//dao.Commit(db, txDB)
|
||||
err = payHandler.CreatePay(txdb, appId)
|
||||
globals.SugarLogger.Debug("the last step of this program,return err……", err)
|
||||
globals.SugarLogger.Debugf("result : %v", utils.Format4Output(payHandler.WxPayParam, false))
|
||||
return payHandler.WxPayParam, err
|
||||
@@ -192,6 +205,7 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
}()
|
||||
//增加账单 余额减去相应金额
|
||||
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, order.PayPrice, 0); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "使用余额支付失败:", err
|
||||
@@ -222,6 +236,7 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
||||
globals.SugarLogger.Debug("进入混合支付部分")
|
||||
//orderInfo.PayMethod = 5 //混合支付状态
|
||||
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
||||
|
||||
globals.SugarLogger.Debug("needPay=================", needPay)
|
||||
globals.SugarLogger.Debug("orderInfo.PayPrice=================", orderInfo.PayPrice)
|
||||
globals.SugarLogger.Debug("orderInfo.OrderID=================", orderInfo.OrderID)
|
||||
|
||||
Reference in New Issue
Block a user