<feat>退款

This commit is contained in:
Rzy 2024-08-09 17:24:03 +08:00
parent 7ed9cb048d
commit bb9ff190c3
4 changed files with 60 additions and 38 deletions

View File

@ -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}

View File

@ -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) {

View File

@ -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
}

View File

@ -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"`
}