Merge branch 'rsm' of e.coding.net:rosydev/jx-callback into rsm

# Conflicts:
#	globals/beegodb/beegodb.go
This commit is contained in:
邹宗楠
2022-08-04 09:54:39 +08:00
11 changed files with 303 additions and 116 deletions

View File

@@ -3,6 +3,7 @@ package cms
import ( import (
"fmt" "fmt"
"git.rosy.net.cn/jx-callback/business/jxstore/event" "git.rosy.net.cn/jx-callback/business/jxstore/event"
"git.rosy.net.cn/jx-callback/business/q_bida"
"github.com/astaxie/beego/client/orm" "github.com/astaxie/beego/client/orm"
"strings" "strings"
"time" "time"
@@ -81,11 +82,22 @@ func CreateOrder(ctx *jxcontext.Context, type1, orderType int, way string, price
return order.OrderID, errCode, err return order.OrderID, errCode, err
} }
func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string) (result *financial.WxPayParam, err error) { func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, appId string, payPrice int) (result *financial.WxPayParam, err error) {
var ( var (
temp_PayPrice int
temp_PayMethod int
txDB orm.TxOrmer
db = dao.GetDB() db = dao.GetDB()
)
orderInfo, err := dao.GetOrderByID(dao.GetDB(), orderID)
if err != nil {
return nil, err
}
var (
order = &model.Order{ order = &model.Order{
OrderID: orderID, OrderID: orderID,
PayPrice: orderInfo.PayPrice,
UserID: orderInfo.UserID,
} }
payHandler = &financial.PayHandler{ payHandler = &financial.PayHandler{
PayType: payType, PayType: payType,
@@ -93,32 +105,51 @@ 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 {
temp_PayPrice = payPrice
temp_PayMethod = 5
} else {
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……") globals.SugarLogger.Debugf("pay begin……")
err = dao.GetEntity(db, order, "OrderID") //err = dao.GetEntity(db, order, "OrderID")
if order.ID == 0 { //if order.OrderID == "" {
return result, fmt.Errorf("未找到此订单!") // return result, fmt.Errorf("未找到此订单!")
} //}
payHandler.Order = order
globals.SugarLogger.Debug("order.payprice==================", payHandler.Order.PayPrice)
//如果用户没有对应账单信息就给他生成一条
txDB, _ := dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db, txDB)
panic(r)
}
}()
info, err := dao.GetOrderByID(db, orderID)
if err != nil {
return nil, err
}
globals.SugarLogger.Debug("Order再次从数据库获得order详情", info.PayPrice, info.PayMethod)
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)
globals.SugarLogger.Debug("errrrrr=========================", err) globals.SugarLogger.Debug("the last step o f this program,return err……", err)
dao.Commit(db, txDB)
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
} }
@@ -126,18 +157,19 @@ func Pay(ctx *jxcontext.Context, orderID string, payType int, vendorPayType, app
var ( var (
NotPay = 2 //订单待支付 NotPay = 2 //订单待支付
AlreadyPay = 1 //订单已支付 AlreadyPay = 1 //订单已支付
Choose = 1 //选中余额支付
NotChoose = -1 //未选中余额支付
) )
//余额支付 微信补差值 //余额支付 微信补差值
func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, 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 //txDB orm.TxOrmer
) )
//获取订单信息 //获取订单信息
globals.SugarLogger.Debug("begin get order_info") globals.SugarLogger.Debug("begin get order_info")
orderInfo, err := dao.GetOrderByID(db, orderID) orderInfo, err := dao.GetOrderByID(db, orderID)
//tempPrice := orderInfo.PayPrice
if err != nil { if err != nil {
return nil, "获取订单信息失败", err return nil, "获取订单信息失败", err
} }
@@ -148,51 +180,88 @@ func PayByBalance(ctx *jxcontext.Context, orderID string, restPrice, payType int
if err != nil { if err != nil {
return nil, "获取用户会员账户余额失败", err return nil, "获取用户会员账户余额失败", err
} }
if orderInfo.Status == NotPay { if orderInfo.Status == NotPay {
globals.SugarLogger.Debug("进入账单未支付") globals.SugarLogger.Debug("进入账单未支付")
globals.SugarLogger.Debug("user_bill.balance==================", userBill.AccountBalance) globals.SugarLogger.Debug("user_bill.balance==================", userBill.AccountBalance)
// (3)使用余额且 余额大于支付金额 // (3)使用余额且 余额大于支付金额
if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && restPrice == 0 { if userBill.AccountBalance > 0 && userBill.AccountBalance > orderInfo.PayPrice && isChoose == Choose {
//余额>0
globals.SugarLogger.Debug("进入余额支付部分") globals.SugarLogger.Debug("进入余额支付部分")
if userBill.AccountBalance > orderInfo.PayPrice && userBill.AccountBalance-orderInfo.PayPrice > 0 { txDB, _ := dao.Begin(db)
if err = financial.AddExpendUpdateAccount(txDB, userBill, model.BillTypePayByAccountBalance, orderInfo.PayPrice, 0); err != nil { defer func() {
return nil, "使用余额支付失败:", err if r := recover(); r != nil {
panic(r)
} }
//修改订单状态 }()
orderInfo.Status = model.OrderStatusSuccessPay //增加账单 余额减去相应金额
orderInfo.PayMethod = 1 //1-余额支付2-微信支付 flag := -1
globals.SugarLogger.Debug("增加账单 余额减去相应金额")
money := userBill.AccountBalance - orderInfo.PayPrice
if err = dao.UpdateUserBill(userBill.UserID, money); err != nil {
return nil, "余额支付失败", err
} else {
flag = 1 //支付成功
}
//更新订单状态
globals.SugarLogger.Debug("更新订单状态")
temp_method := 1
temp_status := 110
if _, err := dao.SetOrderStatus(txDB, orderInfo.PayPrice, temp_method, temp_status, orderID); err != nil {
dao.Rollback(db, txDB)
return nil, "更新order状态失败", 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
}
//再次从数据库获取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 orderInfo.Status == 110 && flag == 1 {
if err := q_bida.CreateOrder2QBiDa(userOrder, orderInfo.OrderID); err != nil {
return nil, "", err
} }
} }
if restPrice > 0 { dao.Commit(db, txDB)
}
if isChoose == Choose {
//1用户不使用余额或者余额=0 即直接微信支付 //1用户不使用余额或者余额=0 即直接微信支付
//if orderInfo.PayPrice == restPrice || userBill.AccountBalance == 0 { if userBill.AccountBalance == 0 {
// WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID) WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID, orderInfo.PayPrice)
// //orderInfo.PayMethod = 2 //微信支付方式
// if err != nil {
// globals.SugarLogger.Debug("err=================", err)
// return nil, "微信支付失败:", err
// }
// return WxPayParam, "", err
//}
//2用户使用余额剩余微信支付
if userBill.AccountBalance+restPrice != orderInfo.PayPrice {
return nil, "支付金额错误,请重新计算", err
}
if userBill.AccountBalance > 0 && userBill.AccountBalance < orderInfo.PayPrice {
globals.SugarLogger.Debug("进入混合支付部分")
orderInfo.PayMethod = 5 //混合支付
orderInfo.PayPrice = restPrice
globals.SugarLogger.Debug("orderInfo.PayPrice=================", orderInfo.PayPrice)
}
WxPayParam, err := Pay(ctx, orderInfo.OrderID, payType, vendorPayType, appID)
if err != nil { if err != nil {
globals.SugarLogger.Debug("err=================", err) globals.SugarLogger.Debug("err=================", err)
return nil, "微信支付失败:", err return nil, "微信支付失败:", err
} }
//orderInfo.PayPrice = tempPrice //存储原价
return WxPayParam, "", 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
}
return WxPayParam, "", err
}
}
} }
return nil, "", err return nil, "", err
} }

View File

@@ -0,0 +1,13 @@
package cms
import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"testing"
)
func Test_Set(t *testing.T) {
if _, err := dao.SetOrderStatus(110, 5, "165943225529BCVFdaX"); err != nil {
return
}
return
}

View File

@@ -7,16 +7,18 @@ import (
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"github.com/astaxie/beego/client/orm" "github.com/astaxie/beego/client/orm"
"time" "time"
) )
func AddMixPay(txDB orm.TxOrmer, orderID string, balancePrice, totalPrice, method int) error { func AddMixPay(txDB orm.TxOrmer, orderID string, balancePrice, totalPrice, status int) error {
mixPayInfo := &model.MixPay{ mixPayInfo := &model.MixPay{
OrderID: orderID, OrderID: orderID,
BalancePrice: balancePrice, BalancePrice: balancePrice,
TotalPrice: totalPrice, TotalPrice: totalPrice,
Method: method, Status: status,
WxPrice: totalPrice - balancePrice,
} }
dao.WrapAddIDCULEntity(mixPayInfo, jxcontext.AdminCtx.GetUserName()) dao.WrapAddIDCULEntity(mixPayInfo, jxcontext.AdminCtx.GetUserName())
return dao.CreateEntityTx(txDB, mixPayInfo) return dao.CreateEntityTx(txDB, mixPayInfo)
@@ -40,6 +42,7 @@ func AddBillExpend(txDB orm.TxOrmer, billID int64, billType, expendPrice, jobID
ExpendPrice: expendPrice, ExpendPrice: expendPrice,
JobID: jobID, JobID: jobID,
} }
globals.SugarLogger.Debug("进入AddBillExpend")
dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName()) dao.WrapAddIDCULEntity(billExpend, jxcontext.AdminCtx.GetUserName())
return dao.CreateEntityTx(txDB, billExpend) return dao.CreateEntityTx(txDB, billExpend)
} }
@@ -61,17 +64,13 @@ func AddUserBillDb(db *dao.DaoDB, billID int64, userID string) (err error) {
return dao.CreateEntity(db, userBillInsert) return dao.CreateEntity(db, userBillInsert)
} }
//
//func AddExpendMixPay(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
//err=AddMixPay()
//}
func GetUserBillDetail(ctx *jxcontext.Context, userID, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) { func GetUserBillDetail(ctx *jxcontext.Context, userID, fromTime, toTime string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
return dao.GetUserBillDetail(dao.GetDB(), userID, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset) return dao.GetUserBillDetail(dao.GetDB(), userID, utils.Str2Time(fromTime), utils.Str2Time(toTime), pageSize, offset)
} }
func AddExpendUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) { func AddExpendUpdateAccount(txDB orm.TxOrmer, userBill *model.UserBill, billType, price, jobID int) (err error) {
//1、账户支出增加一条记录 //1、账户支出增加一条记录
globals.SugarLogger.Debug("进入AddExpendUpdateAccount")
err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID) err = AddBillExpend(txDB, userBill.BillID, billType, price, jobID)
if err != nil { if err != nil {
return err return err

View File

@@ -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,
} }
@@ -259,7 +260,7 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
order.PayFinishedAt = t1 order.PayFinishedAt = t1
order.OriginalData = utils.Format4Output(call, true) order.OriginalData = utils.Format4Output(call, true)
payStatus := 0 payStatus := 0
order.PayMethod = 2 // 通联微信支付 //order.PayMethod = 2 // 通联微信支付
if call.TrxStatus == tonglianpayapi.TrxStatusSuccess { if call.TrxStatus == tonglianpayapi.TrxStatusSuccess {
order.Status = model.OrderStatusFinished order.Status = model.OrderStatusFinished
payStatus = model.OrderStatusSuccessPay payStatus = model.OrderStatusSuccessPay
@@ -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,17 +299,22 @@ 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)
@@ -312,6 +322,8 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
} }
} }
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:

View File

@@ -16,6 +16,7 @@ const (
BillTypePayByAccountBalance = 25 //余额支付 BillTypePayByAccountBalance = 25 //余额支付
BillTypePayByMixPay1 = 26 //混合支付中的 余额部分状态码 BillTypePayByMixPay1 = 26 //混合支付中的 余额部分状态码
BillTypePayByMixPay2 = 27 //混合支付中的 微信部分状态码 BillTypePayByMixPay2 = 27 //混合支付中的 微信部分状态码
BillMixPayRefund1 = 28 //混合支付 余额部分退款
BillTypeQuitGroup = 30 //退群 BillTypeQuitGroup = 30 //退群
BillTypeJdWaybillOverWeight = 40 //京东物流超重扣款 BillTypeJdWaybillOverWeight = 40 //京东物流超重扣款
@@ -51,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"` //微信支付部分
Method int `orm:"column(method)" json:"method"` //支付方式 1-余额支付2-微信支付5-余额+微信混合支付 Status int `orm:"column(status)" json:"status"` //订单状态 -1:退款/1:正常
} }
func (v *MixPay) TableIndex() [][]string { func (v *MixPay) TableIndex() [][]string {

View File

@@ -1,6 +1,7 @@
package dao package dao
import ( import (
"git.rosy.net.cn/jx-callback/globals"
"time" "time"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
@@ -135,3 +136,42 @@ func UpdateUserBill(userId string, money int) error {
_, err := ExecuteSQL(GetDB(), `UPDATE user_bill SET account_balance = ? WHERE user_id = ? `, []interface{}{money, userId}...) _, err := ExecuteSQL(GetDB(), `UPDATE user_bill SET account_balance = ? WHERE user_id = ? `, []interface{}{money, userId}...)
return err return err
} }
type MixPayDetail struct {
ID int `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdateAt time.Time `json:"update_at"`
LastOperator string `json:"lastOperator"`
OrderID string `json:"order_id"`
BalancePrice int `json:"balance_price"`
TotalPrice int `json:"total_price"`
WxPrice int `json:"wx_price"`
Status int `json:"status"`
}
//获取混合支付 余额部分信息
func GetMixPayDetail(orderID string) (details *model.MixPay, err error) {
//var info []*MixPayDetail
info := make([]*model.MixPay, 0)
var sqlParams []interface{}
sql := ""
if orderID != "" {
sql += "SELECT * FROM mix_pay WHERE order_id = ?"
sqlParams = append(sqlParams, orderID)
}
err = GetRows(GetDB(), &info, sql, sqlParams...)
if err != nil {
globals.SugarLogger.Debug("er===========", err)
return nil, err
}
return info[0], err
//if err == nil {
// details = &MixPayDetail{
// OrderID: info[0].OrderID,
// BalancePrice: info[0].BalancePrice,
// TotalPrice: info[0].TotalPrice,
// WxPrice: info[0].WxPrice,
// Status: info[0].Status,
// }
//}
}

View File

@@ -1,6 +1,7 @@
package dao package dao
import ( import (
"github.com/astaxie/beego/client/orm"
"time" "time"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
@@ -668,35 +669,20 @@ func GetUnionOrdersPage(db *DaoDB, vendorIDs, statuss []int, beginTime, endTime
} }
return page, err return page, err
} }
func SetOrderStatus(db *DaoDB, orderID string, status int) (msg string, err error) {
sqlParams := []interface{}{} //更新user_vendor_order 支付状态
sql := `UPDATE order o SET o.status = ? ` func SetUserVendorOrderStatus(tx orm.TxOrmer, localWayBillID string, status int) (msg string, err error) {
if status > 0 { if _, err := ExecuteSQL(GetDB(), "UPDATE `user_vendor_order` SET order_status = ? WHERE local_way_bill = ? ", []interface{}{status, localWayBillID}...); err != nil {
sqlParams = append(sqlParams, status) return "", err
}
if orderID != "" {
sql += `WHERE o.order_id = ?`
sqlParams = append(sqlParams, orderID)
}
orderInfos := &model.Order{}
if err := GetRow(db, orderInfos, sql, sqlParams); err != nil {
return "更新order状态失败", err
}
return "更新order状态成功", err
}
func SetUserVendorOrderStatus(db *DaoDB, localWayBillID string, status int) (msg string, err error) {
sqlParams := []interface{}{}
sql := `UPDATE user_vendor_order a SET a.order_status = ?`
if status > 0 {
sqlParams = append(sqlParams, status)
}
if localWayBillID != "" {
sql += `WHERE a.local_way_bill = ?`
sqlParams = append(sqlParams, localWayBillID)
}
Infos := &model.UserVendorOrder{}
if err := GetRow(db, Infos, sql, sqlParams); err != nil {
return "更新UserVendorOrder状态失败", err
} }
return "更新UserVendorOrder状态成功", err return "更新UserVendorOrder状态成功", err
} }
//更新order 价格和状态
func SetOrderStatus(tx orm.TxOrmer, payPrice, payMethod, status int, orderID string) (string, error) {
if _, err := ExecuteSQL(GetDB(), "UPDATE `order` SET pay_price = ?,pay_method= ?,status=? WHERE order_id = ? ", []interface{}{payPrice, payMethod, status, orderID}...); err != nil {
return "", err
}
return "更新Order状态成功", nil
}

View File

@@ -203,6 +203,7 @@ func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrd
SuccessCode = 0 SuccessCode = 0
tmp_orderNo = param.OrderNo tmp_orderNo = param.OrderNo
db = dao.GetDB() db = dao.GetDB()
//txDB orm.TxOrmer
) )
// 查询订单 // 查询订单
order, err := dao.GetUserVendorOrder(db, userId, param.OrderNo) order, err := dao.GetUserVendorOrder(db, userId, param.OrderNo)
@@ -222,7 +223,6 @@ func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrd
panic(r) panic(r)
} }
}() }()
order.OrderStatus = model.OrderStatusCancel order.OrderStatus = model.OrderStatusCancel
if _, err := dao.UpdateEntityTx(tx, order, "OrderStatus"); err != nil { if _, err := dao.UpdateEntityTx(tx, order, "OrderStatus"); err != nil {
tx.Rollback() tx.Rollback()
@@ -248,9 +248,36 @@ func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrd
if err != nil { if err != nil {
return FailCode, err return FailCode, err
} }
if orderWay.PayMethod == 1 && orderWay.Status == 110 { // 余额支付且已支付 globals.SugarLogger.Debug("回调获取order详情", orderWay)
// 支付方式为余额支付则需要修改order/userVendorOrder修改订单状态给用户账户价钱生成一个价钱数据 userBill, err := dao.GetUserBill(db, orderWay.UserID, "")
} else if orderWay.PayMethod == 2 && orderWay.Status == 110 { // 微信支付且已支付 if err != nil {
return FailCode, err
}
globals.SugarLogger.Debug("回调获取user_bill详情", userBill)
if orderWay.Status == 110 {
if orderWay.PayMethod == 1 { // 余额支付
txDB, _ := dao.Begin(db)
defer func() {
if r := recover(); r != nil {
panic(r)
}
dao.Commit(db, txDB)
}()
//余额增加金额
userBill.AccountBalance += orderWay.PayPrice
if _, err := dao.UpdateEntityTx(txDB, userBill, "AccountBalance"); err != nil {
dao.Rollback(db, txDB)
return FailCode, err
}
//用户运单状态更新
order.OrderStatus = model.OrderStatusCancel
if _, err := dao.UpdateEntityTx(txDB, order, "OrderStatus"); err != nil {
dao.Rollback(db, txDB)
return FailCode, err
}
}
if orderWay.PayMethod == 2 { // 微信支付
// 微信支付原路退款,发起退款申请 // 微信支付原路退款,发起退款申请
res, err := RefundOrderByTL(ctx, orderWay, order, order.OtherWayBill, int(order.ChannelFee*100), "申请退款") res, err := RefundOrderByTL(ctx, orderWay, order, order.OtherWayBill, int(order.ChannelFee*100), "申请退款")
if len(res.VendorRefundID) > 0 { if len(res.VendorRefundID) > 0 {
@@ -259,6 +286,38 @@ func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrd
return FailCode, err return FailCode, err
} }
} }
if orderWay.PayMethod == 5 { //混合支付
globals.SugarLogger.Debug("回调进入混合支付流程")
//余额增加相应金额
globals.SugarLogger.Debug("回调输出订单id", orderWay.OrderID)
mixPayInfo, err := dao.GetMixPayDetail(orderWay.OrderID)
if err != nil {
return FailCode, err
}
userBill.AccountBalance += mixPayInfo.BalancePrice
globals.SugarLogger.Debug("回调输出userBill.AccountBalance", userBill.AccountBalance)
if _, err := dao.UpdateEntity(db, userBill, "AccountBalance"); err != nil {
return FailCode, err
}
//更新mixPay 状态
mixPayInfo.Status = -1 //model.BillMixPayRefund1 //退款状态
if _, err := dao.UpdateEntity(db, mixPayInfo, "Status"); err != nil {
return FailCode, err
}
globals.SugarLogger.Debug("回调进入微信退款")
globals.SugarLogger.Debug("orderWay==============", orderWay)
globals.SugarLogger.Debug("order==============", order)
globals.SugarLogger.Debug("order.OtherWayBill==============", order.OtherWayBill)
res, err := RefundOrderByTL(ctx, orderWay, order, order.OtherWayBill, int(order.ChannelFee*100), "申请退款")
if len(res.VendorRefundID) > 0 {
return SuccessCode, err
} else {
return FailCode, err
}
}
}
} }
return SuccessCode, nil return SuccessCode, nil
} }
@@ -405,12 +464,15 @@ func CreateOrder2QBiDa(order *model.UserVendorOrder, orderId string) error {
// RefundOrderByTL 发起取消订单 // RefundOrderByTL 发起取消订单
func RefundOrderByTL(ctx *jxcontext.Context, orderPay *model.Order, order *model.UserVendorOrder, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) { func RefundOrderByTL(ctx *jxcontext.Context, orderPay *model.Order, order *model.UserVendorOrder, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
globals.SugarLogger.Debug("进入取消订单流程")
result, err := api.TLpayAPI.PayRefund(&tonglianpayapi.PayRefundParam{ result, err := api.TLpayAPI.PayRefund(&tonglianpayapi.PayRefundParam{
Trxamt: refundFee, Trxamt: refundFee,
Reqsn: utils.GetUUID(), Reqsn: utils.GetUUID(),
Remark: refundDesc, Remark: refundDesc,
OldTrxID: orderPay.TransactionID, OldTrxID: orderPay.TransactionID,
}) })
globals.SugarLogger.Debug("result===============", result)
globals.SugarLogger.Debug("errerrerr===============", err)
if err == nil { if err == nil {
orderPayRefund = &model.OrderPayRefund{ orderPayRefund = &model.OrderPayRefund{
RefundID: refundID, RefundID: refundID,
@@ -424,12 +486,14 @@ func RefundOrderByTL(ctx *jxcontext.Context, orderPay *model.Order, order *model
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName()) dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
db := dao.GetDB() db := dao.GetDB()
if result.TrxStatus == tonglianpayapi.TrxStatusSuccess { if result.TrxStatus == tonglianpayapi.TrxStatusSuccess {
globals.SugarLogger.Debug("dfjiaojfiaojfa")
orderPayRefund.Status = model.RefundStatusYes orderPayRefund.Status = model.RefundStatusYes
} else { } else {
globals.SugarLogger.Debug("gedgsedgresgwagwg")
orderPayRefund.Status = model.RefundStatusFailed orderPayRefund.Status = model.RefundStatusFailed
} }
orderPayRefund.OriginalData = utils.Format4Output(result, true) orderPayRefund.OriginalData = utils.Format4Output(result, true)
globals.SugarLogger.Debug("saferhgtrhew", orderPayRefund.OriginalData)
tx, _ := dao.Begin(db) tx, _ := dao.Begin(db)
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
@@ -447,11 +511,13 @@ func RefundOrderByTL(ctx *jxcontext.Context, orderPay *model.Order, order *model
dao.Rollback(db, tx) dao.Rollback(db, tx)
return nil, err return nil, err
} }
globals.SugarLogger.Debug("rtryjyttyejrthg")
orderPay.Status = model.OrderStatusCancel orderPay.Status = model.OrderStatusCancel
if _, err := dao.UpdateEntityTx(tx, orderPay); err != nil { if _, err := dao.UpdateEntityTx(tx, orderPay); err != nil {
dao.Rollback(db, tx) dao.Rollback(db, tx)
return nil, err return nil, err
} }
globals.SugarLogger.Debug("ferbdebere")
dao.Commit(db, tx) dao.Commit(db, tx)
} }

View File

@@ -20,12 +20,13 @@ type OrderController struct {
// @Param vendorPayType formData string true "平台支付类型" // @Param vendorPayType formData string true "平台支付类型"
// @Param orderType formData string true "订单类型member会员express快递recharge充值" // @Param orderType formData string true "订单类型member会员express快递recharge充值"
// @Param appId formData string true "appId" // @Param appId formData string true "appId"
// @Param isChoose formData int true "-1:未选中余额抵消 1余额抵消"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult
// @router /Pay [post] // @router /Pay [post]
func (c *OrderController) Pay() { func (c *OrderController) Pay() {
c.callPay(func(params *tOrderPayParams) (retVal interface{}, errCode string, err error) { c.callPay(func(params *tOrderPayParams) (retVal interface{}, errCode string, err error) {
retVal, err = cms.Pay(params.Ctx, params.OrderID, params.PayType, params.VendorPayType, params.AppId) retVal, err = cms.Pay(params.Ctx, params.OrderID, params.PayType, params.VendorPayType, params.AppId, params.IsChoose)
return retVal, "", err return retVal, "", err
}) })
} }
@@ -38,13 +39,13 @@ func (c *OrderController) Pay() {
// @Param vendorPayType formData string true "平台支付类型" // @Param vendorPayType formData string true "平台支付类型"
// @Param orderType formData string true "订单类型member会员express快递recharge充值" // @Param orderType formData string true "订单类型member会员express快递recharge充值"
// @Param appId formData string true "appId" // @Param appId formData string true "appId"
// @Param restPrice formData int true "需要微信支付的价格" // @Param isChoose formData int true "-1:未选中余额抵消 1余额抵消"
// @Success 200 {object} controllers.CallResult // @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult // @Failure 200 {object} controllers.CallResult
// @router /PayByBalance [post] // @router /PayByBalance [post]
func (c *OrderController) PayByBalance() { func (c *OrderController) PayByBalance() {
c.callPayByBalance(func(params *tOrderPayByBalanceParams) (retVal interface{}, errMsg string, err error) { c.callPayByBalance(func(params *tOrderPayByBalanceParams) (retVal interface{}, errMsg string, err error) {
retVal, _, err = cms.PayByBalance(params.Ctx, params.OrderID, params.RestPrice, params.PayType, params.VendorPayType, params.AppId) retVal, _, err = cms.PayByBalance(params.Ctx, params.OrderID, params.IsChoose, params.PayType, params.VendorPayType, params.AppId)
return retVal, "", err return retVal, "", err
}) })
} }

View File

@@ -134,7 +134,7 @@ func (c *QBiDaExpressController) CreateWayOrder() {
}) })
} }
// CancelWayVendorOrder 取消运单 // pay 取消运单
// @Title Q必达 // @Title Q必达
// @Description 取消运单 // @Description 取消运单
// @Param token header string true "管理员token" // @Param token header string true "管理员token"
@@ -159,7 +159,7 @@ func (c *QBiDaExpressController) CancelWayVendorOrder() {
}) })
} }
// QueryUserOrderList 获取用户订单列表QueryUserOrderList // pay 获取用户订单列表QueryUserOrderList
// @Title Q必达 // @Title Q必达
// @Description 获取用户订单列表 // @Description 获取用户订单列表
// @Param token header string true "管理员token" // @Param token header string true "管理员token"

View File

@@ -9,6 +9,8 @@ import (
func Init() { func Init() {
// set default database // set default database
orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("dbConnectStr"))
//orm.RegisterDataBase("jxd_dev_0", "mysql", "root:WebServer@1@tcp(test1.jxc4.com:3306)/jxd_dev_0?charset=utf8mb4&loc=Local&parseTime=true")
if beego.BConfig.RunMode == "rsm" { if beego.BConfig.RunMode == "rsm" {
orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("dbConnectStr")) orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("dbConnectStr"))
//用户 //用户
@@ -50,13 +52,11 @@ func Init() {
orm.RegisterModel(&model.OrderPayRefund{}) // 退款表 orm.RegisterModel(&model.OrderPayRefund{}) // 退款表
orm.RegisterModel(&model.UserVendorOrder{}) // 物流订单 orm.RegisterModel(&model.UserVendorOrder{}) // 物流订单
orm.RegisterModel(&model.WithdrawalRecord{}) // 提现申请 orm.RegisterModel(&model.WithdrawalRecord{}) // 提现申请
} else { }
orm.RegisterDataBase("default", "mysql", "root:WebServer@1@tcp(127.0.0.1:3306)/api?charset=utf8mb4&loc=Local&parseTime=true")
//打印机 //打印机
orm.RegisterModel(&model.PrintMsg{}) orm.RegisterModel(&model.PrintMsg{})
orm.RegisterModel(&model.Printer{}) orm.RegisterModel(&model.Printer{})
}
// create table // create table
orm.RunSyncdb("default", false, true) orm.RunSyncdb("default", false, true)
} }