<feat>退款单判重和第三方消息处理返回
This commit is contained in:
parent
05b0663c21
commit
7a45794fbc
|
@ -70,6 +70,9 @@ const (
|
||||||
OrderPayed = 1409
|
OrderPayed = 1409
|
||||||
RefundOrderNotFound = 1410
|
RefundOrderNotFound = 1410
|
||||||
OrderStatusRefundNotSupport = 1411
|
OrderStatusRefundNotSupport = 1411
|
||||||
|
OrderAppidNotEqRefundAppid = 1412
|
||||||
|
OrderNotSupportRefundPart = 1413
|
||||||
|
OrderRefundAmountError = 1414
|
||||||
|
|
||||||
//请求日志
|
//请求日志
|
||||||
RequestLogErrors = 1500
|
RequestLogErrors = 1500
|
||||||
|
@ -82,6 +85,8 @@ const (
|
||||||
//订单结果
|
//订单结果
|
||||||
PrePayFail = 1701
|
PrePayFail = 1701
|
||||||
PreRefundFail = 1702
|
PreRefundFail = 1702
|
||||||
|
|
||||||
|
ThirdRefundFail = 1710
|
||||||
)
|
)
|
||||||
|
|
||||||
var MsgEN = map[int]string{
|
var MsgEN = map[int]string{
|
||||||
|
@ -150,8 +155,13 @@ var MsgZH = map[int]string{
|
||||||
NotifySendFail: "回调发送失败",
|
NotifySendFail: "回调发送失败",
|
||||||
RefundOrderNotFound: "退款订单未找到",
|
RefundOrderNotFound: "退款订单未找到",
|
||||||
OrderStatusRefundNotSupport: "订单状态不支持退款",
|
OrderStatusRefundNotSupport: "订单状态不支持退款",
|
||||||
|
OrderAppidNotEqRefundAppid: "订单app_id与退款订单app_id不一致",
|
||||||
PrePayFail: "预支付失败",
|
PrePayFail: "预支付失败",
|
||||||
PreRefundFail: "创建退款单失败",
|
PreRefundFail: "创建退款单失败",
|
||||||
|
OrderNotSupportRefundPart: "订单暂不支持部分退款",
|
||||||
|
OrderRefundAmountError: "退款金额错误",
|
||||||
|
|
||||||
|
ThirdRefundFail: "第三方退款失败",
|
||||||
}
|
}
|
||||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,9 @@ func ApiRes(c *gin.Context, data interface{}, code int, msg ...string) {
|
||||||
data = struct{}{}
|
data = struct{}{}
|
||||||
}
|
}
|
||||||
// 获取错误信息
|
// 获取错误信息
|
||||||
|
message = errorcode.GetMsg(code, "")
|
||||||
if len(msg) > 0 {
|
if len(msg) > 0 {
|
||||||
message = msg[0]
|
message = fmt.Sprintf("%s:%s", message, msg[0])
|
||||||
} else {
|
|
||||||
message = errorcode.GetMsg(code, "")
|
|
||||||
}
|
}
|
||||||
// 获取日志ID
|
// 获取日志ID
|
||||||
log, exists := GetApiLogId(c)
|
log, exists := GetApiLogId(c)
|
||||||
|
|
|
@ -29,7 +29,7 @@ func PayUrl(c *gin.Context) {
|
||||||
}
|
}
|
||||||
pay := thirdpay.ThirdPayUrl(check)
|
pay := thirdpay.ThirdPayUrl(check)
|
||||||
if pay.PayCode != errorcode.Success {
|
if pay.PayCode != errorcode.Success {
|
||||||
controllers.ApiRes(c, nil, pay.PayCode)
|
controllers.ApiRes(c, nil, pay.PayCode, pay.ThirdMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func Refund(c *gin.Context) {
|
||||||
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
|
||||||
refund, errCode := thirdpay.ThirdPayRefund(c.Request.Context(), req, appCheckInfo, c.ClientIP())
|
refund, errCode := thirdpay.ThirdPayRefund(c.Request.Context(), req, appCheckInfo, c.ClientIP())
|
||||||
if errCode != errorcode.Success {
|
if errCode != errorcode.Success {
|
||||||
controllers.ApiRes(c, nil, errCode)
|
controllers.ApiRes(c, nil, errCode, refund.ThirdMsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := thirdpay.NewOrdersResp(refund.Order)
|
data := thirdpay.NewOrdersResp(refund.Order)
|
||||||
|
|
|
@ -167,7 +167,6 @@ func ValidatePayRequest() gin.HandlerFunc {
|
||||||
c.Set("appCheckInfo", appCheck)
|
c.Set("appCheckInfo", appCheck)
|
||||||
//解密
|
//解密
|
||||||
if appCheck.App.KeyType != pojo.NO_CRYPT {
|
if appCheck.App.KeyType != pojo.NO_CRYPT {
|
||||||
|
|
||||||
postBody, errCode = api.DeCrypt(appCheck.App, requestData.Data, requestData.Key)
|
postBody, errCode = api.DeCrypt(appCheck.App, requestData.Data, requestData.Key)
|
||||||
if errCode != errorcode.Success {
|
if errCode != errorcode.Success {
|
||||||
controllers.ApiRes(c, nil, errCode)
|
controllers.ApiRes(c, nil, errCode)
|
||||||
|
|
|
@ -129,7 +129,7 @@ func OrderUpdate(order *ordersmodel.Orders, col ...string) (code int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func OrderFindOne(order *ordersmodel.Orders, conn builder.Cond, col ...string) (merchantInfo *ordersmodel.Orders, code int) {
|
func OrderFindOne(order *ordersmodel.Orders, conn builder.Cond, col ...string) (orderInfo *ordersmodel.Orders, code int) {
|
||||||
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||||
// 拼接查询条件
|
// 拼接查询条件
|
||||||
orderInfo, err := repo.OrderFindOne(order, conn, col...)
|
orderInfo, err := repo.OrderFindOne(order, conn, col...)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"PaymentCenter/app/services"
|
"PaymentCenter/app/services"
|
||||||
"PaymentCenter/app/third/paymentService/payCommon"
|
"PaymentCenter/app/third/paymentService/payCommon"
|
||||||
"context"
|
"context"
|
||||||
|
"xorm.io/builder"
|
||||||
|
|
||||||
"PaymentCenter/app/models/ordersmodel"
|
"PaymentCenter/app/models/ordersmodel"
|
||||||
"PaymentCenter/app/third/paymentService"
|
"PaymentCenter/app/third/paymentService"
|
||||||
|
@ -31,6 +32,7 @@ type Pay struct {
|
||||||
Order *ordersmodel.Orders
|
Order *ordersmodel.Orders
|
||||||
PayCode int
|
PayCode int
|
||||||
Url string
|
Url string
|
||||||
|
ThirdMsg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPayWithPayCheck(paycheck *PayCheck) *Pay {
|
func NewPayWithPayCheck(paycheck *PayCheck) *Pay {
|
||||||
|
@ -51,11 +53,26 @@ func NewPayWithPayCheck(paycheck *PayCheck) *Pay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Pay) CheckRefundOrder() bool {
|
||||||
|
cond := builder.NewCond()
|
||||||
|
cond = cond.And(builder.Eq{"app_id": w.PayParam.App_id}, builder.Eq{"out_trade_no": w.PayParam.OutTradeNo})
|
||||||
|
order, code := services.OrderFindOne(&ordersmodel.Orders{}, cond)
|
||||||
|
if code != errorcode.Success {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if order.Status == common.ORDER_STATUS_FAILED {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
w.Order = order
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Pay) CreateOrder(order_type int) {
|
func (w *Pay) CreateOrder(order_type int) {
|
||||||
if _, ok := common.OrderTypeList[order_type]; !ok { //判断是否是支持的支付渠道
|
if _, ok := common.OrderTypeList[order_type]; !ok { //判断是否是支持的支付渠道
|
||||||
w.PayCode = errorcode.PayChannelNotFound
|
w.PayCode = errorcode.PayChannelNotFound
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
order := &ordersmodel.Orders{
|
order := &ordersmodel.Orders{
|
||||||
MerchantId: w.PayParam.Merchant.Id,
|
MerchantId: w.PayParam.Merchant.Id,
|
||||||
PayChannelId: w.PayParam.Channel.Id,
|
PayChannelId: w.PayParam.Channel.Id,
|
||||||
|
@ -106,6 +123,7 @@ func (w *Pay) PayUrl() (url string) {
|
||||||
w.Url = res.Result
|
w.Url = res.Result
|
||||||
} else {
|
} else {
|
||||||
w.PayCode = errorcode.PrePayFail
|
w.PayCode = errorcode.PrePayFail
|
||||||
|
w.ThirdMsg = res.ErrorMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -140,7 +158,7 @@ func (w *Pay) Refund() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.PayCode = errorcode.PreRefundFail
|
w.PayCode = errorcode.ThirdRefundFail
|
||||||
|
w.ThirdMsg = res.ErrorMsg
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (w *PayCheck) CheckMerchant() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *PayCheck) CheckOrderPay() {
|
func (w *PayCheck) CheckOrderPay() {
|
||||||
w.GetOrder(&types.OrderFindOne{
|
w.GetOldOrder(&types.OrderFindOne{
|
||||||
OutTradeNo: w.Reqs.OutTradeNo,
|
OutTradeNo: w.Reqs.OutTradeNo,
|
||||||
})
|
})
|
||||||
if w.OldOrder != nil {
|
if w.OldOrder != nil {
|
||||||
|
@ -79,8 +79,8 @@ func (w *PayCheck) CheckOrderPay() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *PayCheck) CheckOrderRefund() {
|
func (w *PayCheck) CheckOrderRefund() (order *ordersmodel.Orders) {
|
||||||
w.GetOrder(&types.OrderFindOne{
|
w.GetOldOrder(&types.OrderFindOne{
|
||||||
OutTradeNo: w.Reqs.RefundOutTradeNo,
|
OutTradeNo: w.Reqs.RefundOutTradeNo,
|
||||||
OrderId: w.Reqs.RefundOrderId,
|
OrderId: w.Reqs.RefundOrderId,
|
||||||
})
|
})
|
||||||
|
@ -91,10 +91,31 @@ func (w *PayCheck) CheckOrderRefund() {
|
||||||
if w.OldOrder.Status != common.ORDER_STATUS_PAYED {
|
if w.OldOrder.Status != common.ORDER_STATUS_PAYED {
|
||||||
w.CheckCode = errorcode.OrderStatusRefundNotSupport
|
w.CheckCode = errorcode.OrderStatusRefundNotSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if w.OldOrder.Amount < w.Reqs.Amount {
|
||||||
|
w.CheckCode = errorcode.OrderRefundAmountError
|
||||||
|
}
|
||||||
|
//暂不支持部分退款
|
||||||
|
if w.OldOrder.Amount > w.Reqs.Amount {
|
||||||
|
w.CheckCode = errorcode.OrderNotSupportRefundPart
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *PayCheck) GetOrder(orderCol *types.OrderFindOne) {
|
func (w *PayCheck) GetOldOrder(orderCol *types.OrderFindOne) {
|
||||||
|
order, code := w.GetOrder(orderCol)
|
||||||
|
if code == errorcode.SystemError {
|
||||||
|
w.CheckCode = code
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if code == errorcode.Success {
|
||||||
|
w.OldOrder = order
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *PayCheck) GetOrder(orderCol *types.OrderFindOne) (order *ordersmodel.Orders, code int) {
|
||||||
cond := builder.NewCond()
|
cond := builder.NewCond()
|
||||||
cond = cond.And(builder.Eq{"app_id": w.AppCheck.AppId})
|
cond = cond.And(builder.Eq{"app_id": w.AppCheck.AppId})
|
||||||
if orderCol.OrderId == "" && orderCol.OutTradeNo == "" {
|
if orderCol.OrderId == "" && orderCol.OutTradeNo == "" {
|
||||||
|
@ -107,13 +128,7 @@ func (w *PayCheck) GetOrder(orderCol *types.OrderFindOne) {
|
||||||
if orderCol.OutTradeNo != "" {
|
if orderCol.OutTradeNo != "" {
|
||||||
cond = cond.And(builder.Eq{"out_trade_no": orderCol.OutTradeNo})
|
cond = cond.And(builder.Eq{"out_trade_no": orderCol.OutTradeNo})
|
||||||
}
|
}
|
||||||
order, code := services.OrderFindOne(&ordersmodel.Orders{}, cond)
|
order, code = services.OrderFindOne(&ordersmodel.Orders{}, cond)
|
||||||
if code == errorcode.SystemError {
|
|
||||||
w.CheckCode = code
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if code == errorcode.Success {
|
|
||||||
w.OldOrder = order
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,13 +59,8 @@ func ThirdPayRefund(ctx context.Context, refundReq *front.RefundReqs, appCheck *
|
||||||
if check.CheckCode != errorcode.Success {
|
if check.CheckCode != errorcode.Success {
|
||||||
return nil, check.CheckCode
|
return nil, check.CheckCode
|
||||||
}
|
}
|
||||||
refund = thirdpay.NewPayWithPayCheck(check)
|
refund, errorCode = ThirdRefund(check)
|
||||||
refund.CreateOrder(common.ORDER_TYPE_REFUND)
|
return
|
||||||
if refund.PayCode != errorcode.Success {
|
|
||||||
return refund, refund.PayCode
|
|
||||||
}
|
|
||||||
refund.Refund()
|
|
||||||
return refund, errorcode.Success
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
|
func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
|
||||||
|
@ -81,3 +76,16 @@ func ThirdPay(check *thirdpay.PayCheck) (pay *thirdpay.Pay) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ThirdRefund(check *thirdpay.PayCheck) (refund *thirdpay.Pay, errCode int) {
|
||||||
|
refund = thirdpay.NewPayWithPayCheck(check)
|
||||||
|
if refund.CheckRefundOrder() {
|
||||||
|
refund.CreateOrder(common.ORDER_TYPE_REFUND)
|
||||||
|
if refund.PayCode != errorcode.Success {
|
||||||
|
return refund, refund.PayCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refund.Refund()
|
||||||
|
return refund, refund.PayCode
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue