From bb9ff190c351433e9634e9c0d893a1f528ce4eb3 Mon Sep 17 00:00:00 2001 From: Rzy <465386466@qq.com> Date: Fri, 9 Aug 2024 17:24:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constants/errorcode/error_code.go | 42 +++++++++++++++------------ app/services/thirdpay/do/pay.go | 9 ++++-- app/services/thirdpay/do/pay_check.go | 40 +++++++++++++++---------- app/services/thirdpay/types/types.go | 7 +++++ 4 files changed, 60 insertions(+), 38 deletions(-) diff --git a/app/constants/errorcode/error_code.go b/app/constants/errorcode/error_code.go index c4f2cc6..a1a2bea 100644 --- a/app/constants/errorcode/error_code.go +++ b/app/constants/errorcode/error_code.go @@ -58,14 +58,17 @@ const ( PayChannelExtJsonError = 1302 //订单 - OrdersNotFound = 1401 - OrdersExist = 1402 - OrderTypeNotFount = 1403 - OrderIsDelete = 1405 - OrderStatusErr = 1406 - OrderClosed = 1407 - OrderFailed = 1408 - OrderPayed = 1409 + OrdersNotFound = 1401 + OrdersExist = 1402 + OrderTypeNotFount = 1403 + OrderIsDelete = 1405 + OrderStatusErr = 1406 + OrderClosed = 1407 + OrderFailed = 1408 + OrderPayed = 1409 + RefundOrderNotFound = 1410 + OrderStatusRefundNotSupport = 1411 + //请求日志 RequestLogErrors = 1500 RequestLogNotFound = 1501 @@ -132,17 +135,18 @@ var MsgZH = map[int]string{ RequestLogNotFound: "未找到日志信息", RequestResponseValid: "上游返回格式无效", - OrdersNotFound: "未找到订单", - OrdersExist: "订单已存在", - OrderTypeNotFount: "未知的支付方式", - OrderIsDelete: "订单已删除", - OrderStatusErr: "订单状态错误", - OrderClosed: "订单已关闭,无法继续支付", - OrderFailed: "订单支付失败,请重新发起", - OrderPayed: "订单已支付成功,请勿重复支付", - NotifySendFail: "回调发送失败", - - PrePayFail: "预支付失败", + OrdersNotFound: "未找到订单", + OrdersExist: "订单已存在", + OrderTypeNotFount: "未知的支付方式", + OrderIsDelete: "订单已删除", + OrderStatusErr: "订单状态错误", + OrderClosed: "订单已关闭,无法继续支付", + OrderFailed: "订单支付失败,请重新发起", + OrderPayed: "订单已支付成功,请勿重复支付", + NotifySendFail: "回调发送失败", + RefundOrderNotFound: "退款订单未找到", + OrderStatusRefundNotSupport: "订单状态不支持退款", + PrePayFail: "预支付失败", } var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH} diff --git a/app/services/thirdpay/do/pay.go b/app/services/thirdpay/do/pay.go index 40a88d0..8f23025 100644 --- a/app/services/thirdpay/do/pay.go +++ b/app/services/thirdpay/do/pay.go @@ -56,7 +56,7 @@ func (w *Pay) CreateOrder(order_type int) { w.PayCode = errorcode.PayChannelNotFound return } - w.Order, w.PayCode = services.OrderCreate(&ordersmodel.Orders{ + order := &ordersmodel.Orders{ MerchantId: w.PayParam.Merchant.Id, PayChannelId: w.PayParam.Channel.Id, AppId: w.PayParam.App_id, @@ -66,8 +66,11 @@ func (w *Pay) CreateOrder(order_type int) { ExtJson: w.PayParam.ExtJson, Desc: w.PayParam.Desc, Status: common.ORDER_STATUS_WAITPAY, - }, - ) + } + if order_type == common.ORDER_TYPE_REFUND { + order.RefundOrderId = w.RelationOrder.Id + } + w.Order, w.PayCode = services.OrderCreate(order) } func (w *Pay) PayUrl() (url string) { diff --git a/app/services/thirdpay/do/pay_check.go b/app/services/thirdpay/do/pay_check.go index 3490dcb..7640c22 100644 --- a/app/services/thirdpay/do/pay_check.go +++ b/app/services/thirdpay/do/pay_check.go @@ -61,7 +61,9 @@ func (w *PayCheck) CheckMerchant() { } func (w *PayCheck) CheckOrderPay() { - w.GetOrder() + w.GetOrder(&types.OrderFindOne{ + OutTradeNo: w.Reqs.OutTradeNo, + }) if w.OldOrder != nil { switch w.OldOrder.Status { case common.ORDER_STATUS_CLOSE: @@ -78,27 +80,33 @@ func (w *PayCheck) CheckOrderPay() { } func (w *PayCheck) CheckOrderRefund() { - w.GetOrder() + w.GetOrder(&types.OrderFindOne{ + OutTradeNo: w.Reqs.RefundOutTradeNo, + OrderId: w.Reqs.RefundOrderId, + }) if w.OldOrder == nil { - w.CheckCode = errorcode.OrdersNotFound + w.CheckCode = errorcode.RefundOrderNotFound + return } - switch w.OldOrder.Status { - case common.ORDER_STATUS_CLOSE: - w.CheckCode = errorcode.OrderClosed - case common.ORDER_STATUS_FAILED: - w.CheckCode = errorcode.OrderFailed - case common.ORDER_STATUS_WAITPAY: - w.CheckCode = errorcode.OrderStatusErr - case common.ORDER_STATUS_PAYING: - w.CheckCode = errorcode.OrderStatusErr - default: + if w.OldOrder.Status != common.ORDER_STATUS_PAYED { + w.CheckCode = errorcode.OrderStatusRefundNotSupport } return } -func (w *PayCheck) GetOrder() { +func (w *PayCheck) GetOrder(orderCol *types.OrderFindOne) { cond := builder.NewCond() - cond = cond.And(builder.Eq{"out_trade_no": w.Reqs.OutTradeNo}, builder.Eq{"app_id": w.AppCheck.AppId}) + cond = cond.And(builder.Eq{"app_id": w.AppCheck.AppId}) + if orderCol.OrderId == "" && orderCol.OutTradeNo == "" { + w.CheckCode = errorcode.OrdersNotFound + return + } + if orderCol.OrderId != "" { + cond = cond.And(builder.Eq{"order_id": orderCol.OrderId}) + } + if orderCol.OutTradeNo != "" { + cond = cond.And(builder.Eq{"out_trade_no": orderCol.OutTradeNo}) + } order, code := services.OrderFindOne(&ordersmodel.Orders{}, cond) if code == errorcode.SystemError { w.CheckCode = code @@ -107,5 +115,5 @@ func (w *PayCheck) GetOrder() { if code == errorcode.Success { w.OldOrder = order } - + return } diff --git a/app/services/thirdpay/types/types.go b/app/services/thirdpay/types/types.go index dcf4e1a..8da7342 100644 --- a/app/services/thirdpay/types/types.go +++ b/app/services/thirdpay/types/types.go @@ -4,5 +4,12 @@ import "PaymentCenter/app/http/entities/front" type Reqs struct { front.PayCommonReqBody + OutTradeNo string `json:"out_trade_no"` + RefundOutTradeNo string `json:"refund_out_trade_no"` + RefundOrderId string `json:"refundOrder_id"` +} + +type OrderFindOne struct { + OrderId string OutTradeNo string `json:"out_trade_no"` }