add 充值到余额订单
This commit is contained in:
@@ -105,9 +105,7 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
||||
VendorPayType: vendorPayType,
|
||||
}
|
||||
)
|
||||
globals.SugarLogger.Debug("payPrice before1111=========================", payPrice)
|
||||
//支付金额<原金额
|
||||
globals.SugarLogger.Debug("order.PayPrice=========================", order.PayPrice)
|
||||
if payPrice < order.PayPrice {
|
||||
temp_PayPrice = payPrice
|
||||
temp_PayMethod = 5
|
||||
@@ -115,39 +113,21 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
|
||||
temp_PayPrice = orderInfo.PayPrice
|
||||
temp_PayMethod = 2
|
||||
}
|
||||
globals.SugarLogger.Debug("检验初始数据情况", order.OrderID, order.PayMethod)
|
||||
globals.SugarLogger.Debug("检验初始数据情况", order.PayPrice)
|
||||
//微信支付实际金额更新到数据库
|
||||
if _, err := dao.SetOrderStatus(txDB, temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//if _, err := dao.UpdateEntityTx(txDB, order); err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
globals.SugarLogger.Debug("经过更新操作后的数据after=========================", order.OrderID, order.PayPrice, order.PayMethod)
|
||||
globals.SugarLogger.Debug("经过更新操作后的数据after=========================", order.PayPrice)
|
||||
globals.SugarLogger.Debugf("pay begin……")
|
||||
err = dao.GetEntity(db, order, "OrderID")
|
||||
if order.OrderID == "" {
|
||||
return result, fmt.Errorf("未找到此订单!")
|
||||
}
|
||||
|
||||
//info, err := dao.GetOrderByID(db, orderID)
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
globals.SugarLogger.Debug("Order再次从数据库获得order详情", order.PayPrice, order.PayMethod)
|
||||
//globals.SugarLogger.Debug("Order再次从数据库获得order详情", info.PayPrice, info.PayMethod)
|
||||
payHandler.Order = order
|
||||
//payHandler.Order = info
|
||||
|
||||
globals.SugarLogger.Debug("payHandler.Order再次从数据库获得order详情", payHandler.Order.PayPrice, payHandler.Order.PayMethod)
|
||||
//如果用户没有对应账单信息就给他生成一条
|
||||
// 给用户创建一个银行卡账户
|
||||
globals.SugarLogger.Debug("create bill begin……")
|
||||
userBill, err := dao.GetUserBill(db, order.UserID, "")
|
||||
if userBill == nil {
|
||||
globals.SugarLogger.Debug("order.UserID,userBill=======================", order.UserID, userBill)
|
||||
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
|
||||
}
|
||||
err = payHandler.CreatePay(txDB, appId)
|
||||
@@ -167,7 +147,6 @@ var (
|
||||
func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, vendorPayType, appID string) (*financial.WxPayParam, string, error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
//txDB orm.TxOrmer
|
||||
)
|
||||
//获取订单信息
|
||||
globals.SugarLogger.Debug("begin get order_info")
|
||||
@@ -177,106 +156,91 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
|
||||
}
|
||||
globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType)
|
||||
//获取用户 会员账户信息
|
||||
globals.SugarLogger.Debug("开始获取会员信息")
|
||||
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
|
||||
if err != nil {
|
||||
return nil, "获取用户会员账户余额失败", err
|
||||
}
|
||||
if orderInfo.Status == NotPay {
|
||||
globals.SugarLogger.Debug("进入账单未支付")
|
||||
globals.SugarLogger.Debug("user_bill.balance==================", userBill.AccountBalance)
|
||||
//需要充值余额支付的方式//todo 后续添加
|
||||
//if orderInfo.OrderType == 6 {
|
||||
//
|
||||
//}
|
||||
// (3)使用余额且 余额大于支付金额
|
||||
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == Choose {
|
||||
globals.SugarLogger.Debug("进入余额支付部分")
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
panic(r)
|
||||
//快递混合支付
|
||||
if orderInfo.OrderType == 3 {
|
||||
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == Choose {
|
||||
globals.SugarLogger.Debug("进入余额支付部分")
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
//增加账单 余额减去相应金额
|
||||
money := userBill.AccountBalance - orderInfo.PayPrice
|
||||
if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
|
||||
return nil, "余额支付失败", err
|
||||
}
|
||||
}()
|
||||
//增加账单 余额减去相应金额
|
||||
globals.SugarLogger.Debug("增加账单 余额减去相应金额")
|
||||
money := userBill.AccountBalance - orderInfo.PayPrice
|
||||
if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
|
||||
return nil, "余额支付失败", err
|
||||
}
|
||||
//更新订单状态
|
||||
globals.SugarLogger.Debug("更新order状态")
|
||||
//temp_method := 1
|
||||
//temp_status := 110
|
||||
orderInfo.PayMethod = 1
|
||||
orderInfo.Status = 110
|
||||
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "PayMethod"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "更新order.PayMethod状态失败", err
|
||||
}
|
||||
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "Status"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "更新order.Status状态失败", err
|
||||
}
|
||||
//if _, err := dao.SetOrderStatus(txDB, orderInfo.PayPrice, 1, 110, orderID); err != nil {
|
||||
// dao.Rollback(db, txDB)
|
||||
// return nil, "更新order状态失败", err
|
||||
//}
|
||||
//todo 后续需增加其他订单类型
|
||||
//(1)更新快递 订单状态
|
||||
globals.SugarLogger.Debug("更新UserVendorOrder状态")
|
||||
temp_vendor_status := 4
|
||||
if _, err := dao.SetUserVendorOrderStatus(txDB, orderInfo.OrderID, temp_vendor_status); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "更新user_vendor_order状态失败", err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
//再次从数据库获取order、userOrder
|
||||
orderNew, err := dao.GetOrderByID(db, orderID)
|
||||
if err != nil {
|
||||
return nil, "获取orderNew失败", err
|
||||
}
|
||||
globals.SugarLogger.Debug("再次获取order数据进行检验", orderNew.PayMethod, orderNew.PayPrice)
|
||||
userOrder, err := dao.GetUserVendorOrder(db, orderNew.UserID, orderNew.OrderID)
|
||||
if err != nil {
|
||||
return nil, "获取userOrder失败", err
|
||||
}
|
||||
globals.SugarLogger.Debug("再次获取user_vendor_order数据进行检验", userOrder.OrderStatus)
|
||||
//快递单 同步到qbd
|
||||
globals.SugarLogger.Debug("输出一下", orderInfo.Status, userOrder.OrderStatus)
|
||||
if orderNew.Status == 110 && userOrder.OrderStatus == 4 {
|
||||
globals.SugarLogger.Debug("进入qbd创建订单流程")
|
||||
if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil {
|
||||
return nil, "", err
|
||||
//更新订单状态
|
||||
orderInfo.PayMethod = 1
|
||||
orderInfo.Status = 110
|
||||
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "PayMethod"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "更新order.PayMethod状态失败", err
|
||||
}
|
||||
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "Status"); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "更新order.Status状态失败", err
|
||||
}
|
||||
//todo 后续需增加其他订单类型
|
||||
//(1)更新快递 订单状态
|
||||
temp_vendor_status := 4
|
||||
if _, err := dao.SetUserVendorOrderStatus(txDB, orderInfo.OrderID, temp_vendor_status); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return nil, "更新user_vendor_order状态失败", err
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
//再次从数据库获取order、userOrder
|
||||
orderNew, err := dao.GetOrderByID(db, orderID)
|
||||
if err != nil {
|
||||
return nil, "获取orderNew失败", err
|
||||
}
|
||||
userOrder, err := dao.GetUserVendorOrder(db, orderNew.UserID, orderNew.OrderID)
|
||||
if err != nil {
|
||||
return nil, "获取userOrder失败", err
|
||||
}
|
||||
//快递单 同步到qbd
|
||||
if orderNew.Status == 110 && userOrder.OrderStatus == 4 {
|
||||
if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
} else {
|
||||
return nil, "order/user_vendor_order更新状态出错", nil
|
||||
}
|
||||
} else {
|
||||
return nil, "order/user_vendor_order更新状态出错", nil
|
||||
}
|
||||
|
||||
}
|
||||
if isChoose == Choose {
|
||||
//(1)用户不使用余额或者余额=0 即直接微信支付
|
||||
if userBill.AccountBalance == 0 {
|
||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debug("err=================", err)
|
||||
return nil, "微信支付失败:", err
|
||||
}
|
||||
return WxPayParam, "", err
|
||||
}
|
||||
//(2)用户使用余额,剩余微信支付
|
||||
totalPrice := orderInfo.PayPrice //订单原价
|
||||
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
|
||||
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)
|
||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debug("err=================", err)
|
||||
return nil, "微信支付失败:", err
|
||||
if isChoose == Choose {
|
||||
//(1)用户不使用余额或者余额=0 即直接微信支付
|
||||
if userBill.AccountBalance == 0 {
|
||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
|
||||
if err != nil {
|
||||
return nil, "微信支付失败:", err
|
||||
}
|
||||
return WxPayParam, "", err
|
||||
}
|
||||
//(2)用户使用余额,剩余微信支付
|
||||
totalPrice := orderInfo.PayPrice //订单原价
|
||||
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
|
||||
needPay := totalPrice - userBill.AccountBalance //需支付金额
|
||||
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
|
||||
if err != nil {
|
||||
return nil, "微信支付失败:", err
|
||||
}
|
||||
return WxPayParam, "", err
|
||||
}
|
||||
return WxPayParam, "", err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
@@ -272,8 +272,12 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
|
||||
//充值会员 增加微信支付处理业务
|
||||
if (order.OrderType == 2 || order.OrderType == 5) && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
if err := OnWXPayFinished(order); err != nil {
|
||||
return err
|
||||
}
|
||||
return OnWXPayFinished(order)
|
||||
} else if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
}
|
||||
if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
globals.SugarLogger.Debug("得到微信回调结果,快递流程开始")
|
||||
txdb, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
@@ -293,12 +297,6 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
dao.Rollback(db, txdb)
|
||||
return err
|
||||
}
|
||||
//测试order 数据库是否更新成功
|
||||
order_test, err := dao.GetOrderByID(db, order.OrderID)
|
||||
globals.SugarLogger.Debug("再次从数据库拿order.TransactionID", order_test.TransactionID)
|
||||
globals.SugarLogger.Debug("再次从数据库拿order.Status", order_test.Status)
|
||||
////////////////////////////////////
|
||||
|
||||
globals.SugarLogger.Debug("获取UserVendorOrder")
|
||||
userOrder := model.UserVendorOrder{LocalWayBill: order.OrderID}
|
||||
if err := dao.GetEntity(db, &userOrder, "LocalWayBill"); err != nil {
|
||||
@@ -346,6 +344,12 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
}
|
||||
return err
|
||||
}
|
||||
//需要充值到余额方式 购买的
|
||||
if order.OrderType == 6 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
|
||||
if err := dao.UpdateUserBill(order.UserID, order.PayPrice); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ type Order struct {
|
||||
OrderID string `orm:"column(order_id)" json:"orderID"` // 订单号
|
||||
UserID string `orm:"column(user_id);size(48)" json:"userID"` // 用户ID
|
||||
Type int `json:"type"` // 支付还是提现 1-支付,2-提现
|
||||
OrderType int `json:"orderType"` // 订单类型,1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡
|
||||
OrderType int `json:"orderType"` // 订单类型,1-发任务,2-会员月卡,3-发快递,4-提现,5-会员年卡,6-使用充值到余额方式的订单
|
||||
Way string `json:"way"` // weixinapp ,weixinmini
|
||||
Status int `json:"status"` // 订单状态,待支付2,已支付5,支付成功110,支付失败115,150取消
|
||||
PayPrice int `json:"payPrice"` // 支付金额
|
||||
|
||||
Reference in New Issue
Block a user