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