add 充值到余额订单

This commit is contained in:
richboo111
2022-08-08 14:04:42 +08:00
parent b393bd17b8
commit 9476a98b69
4 changed files with 85 additions and 117 deletions

View File

@@ -105,9 +105,7 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
VendorPayType: vendorPayType, VendorPayType: vendorPayType,
} }
) )
globals.SugarLogger.Debug("payPrice before1111=========================", payPrice)
//支付金额<原金额 //支付金额<原金额
globals.SugarLogger.Debug("order.PayPrice=========================", order.PayPrice)
if payPrice < order.PayPrice { if payPrice < order.PayPrice {
temp_PayPrice = payPrice temp_PayPrice = payPrice
temp_PayMethod = 5 temp_PayMethod = 5
@@ -115,39 +113,21 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
temp_PayPrice = orderInfo.PayPrice temp_PayPrice = orderInfo.PayPrice
temp_PayMethod = 2 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 { if _, err := dao.SetOrderStatus(txDB, temp_PayPrice, temp_PayMethod, orderInfo.Status, orderID); err != nil {
return nil, err 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……") 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("未找到此订单!")
} }
//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 = order
//payHandler.Order = info
globals.SugarLogger.Debug("payHandler.Order再次从数据库获得order详情", payHandler.Order.PayPrice, payHandler.Order.PayMethod)
//如果用户没有对应账单信息就给他生成一条 //如果用户没有对应账单信息就给他生成一条
// 给用户创建一个银行卡账户 // 给用户创建一个银行卡账户
globals.SugarLogger.Debug("create bill begin……") globals.SugarLogger.Debug("create bill begin……")
userBill, err := dao.GetUserBill(db, order.UserID, "") userBill, err := dao.GetUserBill(db, order.UserID, "")
if userBill == nil { if userBill == nil {
globals.SugarLogger.Debug("order.UserIDuserBill=======================", order.UserID, userBill)
err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID) err = financial.AddUserBill(txDB, jxutils.GenBillID(), order.UserID)
} }
err = payHandler.CreatePay(txDB, appId) 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) { func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int, vendorPayType, appID string) (*financial.WxPayParam, string, error) {
var ( var (
db = dao.GetDB() db = dao.GetDB()
//txDB orm.TxOrmer
) )
//获取订单信息 //获取订单信息
globals.SugarLogger.Debug("begin get order_info") globals.SugarLogger.Debug("begin get order_info")
@@ -177,15 +156,18 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
} }
globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType) globals.SugarLogger.Debug("orderInfo.OrderType===============", orderInfo.OrderType)
//获取用户 会员账户信息 //获取用户 会员账户信息
globals.SugarLogger.Debug("开始获取会员信息")
userBill, err := dao.GetUserBill(db, orderInfo.UserID, "") userBill, err := dao.GetUserBill(db, orderInfo.UserID, "")
if err != nil { if err != nil {
return nil, "获取用户会员账户余额失败", err return nil, "获取用户会员账户余额失败", err
} }
if orderInfo.Status == NotPay { if orderInfo.Status == NotPay {
globals.SugarLogger.Debug("进入账单未支付") //需要充值余额支付的方式//todo 后续添加
globals.SugarLogger.Debug("user_bill.balance==================", userBill.AccountBalance) //if orderInfo.OrderType == 6 {
//
//}
// (3)使用余额且 余额大于支付金额 // (3)使用余额且 余额大于支付金额
//快递混合支付
if orderInfo.OrderType == 3 {
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == Choose { if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == Choose {
globals.SugarLogger.Debug("进入余额支付部分") globals.SugarLogger.Debug("进入余额支付部分")
txDB, _ := dao.Begin(db) txDB, _ := dao.Begin(db)
@@ -195,15 +177,11 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
} }
}() }()
//增加账单 余额减去相应金额 //增加账单 余额减去相应金额
globals.SugarLogger.Debug("增加账单 余额减去相应金额")
money := userBill.AccountBalance - orderInfo.PayPrice money := userBill.AccountBalance - orderInfo.PayPrice
if err = dao.UpdateUserBill(userBill.UserID, money); err != nil { if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
return nil, "余额支付失败", err return nil, "余额支付失败", err
} }
//更新订单状态 //更新订单状态
globals.SugarLogger.Debug("更新order状态")
//temp_method := 1
//temp_status := 110
orderInfo.PayMethod = 1 orderInfo.PayMethod = 1
orderInfo.Status = 110 orderInfo.Status = 110
if _, err := dao.UpdateEntityTx(txDB, orderInfo, "PayMethod"); err != nil { if _, err := dao.UpdateEntityTx(txDB, orderInfo, "PayMethod"); err != nil {
@@ -214,13 +192,8 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
return nil, "更新order.Status状态失败", err 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 后续需增加其他订单类型 //todo 后续需增加其他订单类型
//(1)更新快递 订单状态 //(1)更新快递 订单状态
globals.SugarLogger.Debug("更新UserVendorOrder状态")
temp_vendor_status := 4 temp_vendor_status := 4
if _, err := dao.SetUserVendorOrderStatus(txDB, orderInfo.OrderID, temp_vendor_status); err != nil { if _, err := dao.SetUserVendorOrderStatus(txDB, orderInfo.OrderID, temp_vendor_status); err != nil {
dao.Rollback(db, txDB) dao.Rollback(db, txDB)
@@ -232,16 +205,12 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
if err != nil { if err != nil {
return nil, "获取orderNew失败", err return nil, "获取orderNew失败", err
} }
globals.SugarLogger.Debug("再次获取order数据进行检验", orderNew.PayMethod, orderNew.PayPrice)
userOrder, err := dao.GetUserVendorOrder(db, orderNew.UserID, orderNew.OrderID) userOrder, err := dao.GetUserVendorOrder(db, orderNew.UserID, orderNew.OrderID)
if err != nil { if err != nil {
return nil, "获取userOrder失败", err return nil, "获取userOrder失败", err
} }
globals.SugarLogger.Debug("再次获取user_vendor_order数据进行检验", userOrder.OrderStatus)
//快递单 同步到qbd //快递单 同步到qbd
globals.SugarLogger.Debug("输出一下", orderInfo.Status, userOrder.OrderStatus)
if orderNew.Status == 110 && userOrder.OrderStatus == 4 { if orderNew.Status == 110 && userOrder.OrderStatus == 4 {
globals.SugarLogger.Debug("进入qbd创建订单流程")
if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil { if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil {
return nil, "", err return nil, "", err
} }
@@ -255,7 +224,6 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
if userBill.AccountBalance == 0 { if userBill.AccountBalance == 0 {
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice) WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
if err != nil { if err != nil {
globals.SugarLogger.Debug("err=================", err)
return nil, "微信支付失败:", err return nil, "微信支付失败:", err
} }
return WxPayParam, "", err return WxPayParam, "", err
@@ -263,21 +231,17 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, isChoose, payType int,
//2用户使用余额剩余微信支付 //2用户使用余额剩余微信支付
totalPrice := orderInfo.PayPrice //订单原价 totalPrice := orderInfo.PayPrice //订单原价
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice { if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
globals.SugarLogger.Debug("进入混合支付部分")
//orderInfo.PayMethod = 5 //混合支付状态
needPay := totalPrice - userBill.AccountBalance //需支付金额 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) WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, needPay)
if err != nil { if err != nil {
globals.SugarLogger.Debug("err=================", err)
return nil, "微信支付失败:", err return nil, "微信支付失败:", err
} }
return WxPayParam, "", err return WxPayParam, "", err
} }
} }
} }
}
return nil, "", err return nil, "", err
} }

View File

@@ -272,8 +272,12 @@ 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 {
if err := OnWXPayFinished(order); err != nil {
return err
}
return OnWXPayFinished(order) return OnWXPayFinished(order)
} else if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess { }
if order.OrderType == 3 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
globals.SugarLogger.Debug("得到微信回调结果,快递流程开始") globals.SugarLogger.Debug("得到微信回调结果,快递流程开始")
txdb, _ := dao.Begin(db) txdb, _ := dao.Begin(db)
defer func() { defer func() {
@@ -293,12 +297,6 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
dao.Rollback(db, txdb) dao.Rollback(db, txdb)
return err 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") 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 {
@@ -346,6 +344,12 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
} }
return err return err
} }
//需要充值到余额方式 购买的
if order.OrderType == 6 && call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
if err := dao.UpdateUserBill(order.UserID, order.PayPrice); err != nil {
return err
}
}
} else { } else {
globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err) globals.SugarLogger.Debugf("onTLpayFinished msg:%s, err:%v", utils.Format4Output(call, true), err)
} }

View File

@@ -59,7 +59,7 @@ type Order struct {
OrderID string `orm:"column(order_id)" json:"orderID"` // 订单号 OrderID string `orm:"column(order_id)" json:"orderID"` // 订单号
UserID string `orm:"column(user_id);size(48)" json:"userID"` // 用户ID UserID string `orm:"column(user_id);size(48)" json:"userID"` // 用户ID
Type int `json:"type"` // 支付还是提现 1-支付2-提现 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 Way string `json:"way"` // weixinapp ,weixinmini
Status int `json:"status"` // 订单状态,待支付2已支付5支付成功110支付失败115,150取消 Status int `json:"status"` // 订单状态,待支付2已支付5支付成功110支付失败115,150取消
PayPrice int `json:"payPrice"` // 支付金额 PayPrice int `json:"payPrice"` // 支付金额

View File

@@ -70,7 +70,7 @@ func (c *OrderController) Cash() {
// @Description 创建订单 // @Description 创建订单
// @Param token header string true "认证token" // @Param token header string true "认证token"
// @Param type formData int true "支付类型/账单类型" // @Param type formData int true "支付类型/账单类型"
// @Param orderType formData int true "订单类型1为发任务2为冲会员3为发快递" // @Param orderType formData int true "订单类型1为发任务2为冲会员3为发快递6-需要充值到余额购买的方式"
// @Param way formData string true "认证方式" // @Param way formData string true "认证方式"
// @Param price formData int true "支付金额" // @Param price formData int true "支付金额"
// @Param lng formData float64 true "经纬度" // @Param lng formData float64 true "经纬度"