瀏覽代碼

修复支付订单bug

kobe6258 4 月之前
父節點
當前提交
6225f33921

+ 2 - 0
common/exception/exc_enums.go

@@ -143,6 +143,7 @@ const (
 	OrderErrorCode int = iota + 90000
 	IllegalOrderStatus
 	OrderPayTimeoutError
+	PayTradeOrderFailed
 )
 
 const (
@@ -257,6 +258,7 @@ var ErrorMap = map[int]string{
 	//order
 	IllegalOrderStatus:   "非法的订单状态",
 	OrderPayTimeoutError: "订单支付超时",
+	PayTradeOrderFailed:  "订单支付失败",
 	//product
 	ProductOffSale:   "商品已下架",
 	ProductTypeError: "非法的产品类型",

+ 13 - 0
controllers/payment/payment_controller.go

@@ -70,6 +70,19 @@ func (pc *PaymentController) PayOrder() {
 				}
 				return
 			}
+			if productOrder.TradeNo != "" {
+				tradeOrder, tradeErr := order.GetTradeOrderByNo(productOrder.TradeNo)
+				if tradeErr != nil {
+					err = exception.NewWithException(exception.PayTradeOrderFailed, tradeErr.Error())
+					pc.FailedResult("支付失败,获取原支付订单信息失败", result)
+					return
+				}
+				if tradeOrder.PaymentStatus != "failed" {
+					err = exception.New(exception.PayTradeOrderFailed)
+					pc.FailedResult("支付失败,商品订单支付中,请勿重复支付", result)
+					return
+				}
+			}
 			var officialUser userService.OfficialUserDTO
 			officialUser, err = user.GetUserByTemplateUserId(userInfo.Id)
 			if err != nil {

+ 2 - 0
domian/order/product_order.go

@@ -19,6 +19,7 @@ type ProductOrderDTO struct {
 	UserID             int
 	TemplateUserID     int
 	RealName           string
+	TradeNo            string
 	AreaCode           string
 	Mobile             string
 	ProductID          int
@@ -113,6 +114,7 @@ func convertProductOrderDTO(order orderDao.ProductOrder) (orderDTO ProductOrderD
 		UserID:         order.UserID,
 		TemplateUserID: order.UserID,
 		ProductID:      order.ProductID,
+		TradeNo:        order.TradeNO,
 		TotalAmount:    order.TotalAmount,
 		PaymentWay:     string(order.PaymentWay),
 		Status:         string(order.Status),

+ 6 - 0
domian/order/trade_order.go

@@ -100,3 +100,9 @@ func GetUnFailedTradeFlowByProductOrder(productOrderNo string) (dtoList []TradeO
 	}
 	return
 }
+func GetTradeOrderByNo(tradeOrderNo string) (dto TradeOrderDTO, err error) {
+	var tradeOrder order.TradeOrder
+	tradeOrder, err = order.GetTradeOrderByNo(tradeOrderNo)
+	dto = convertToDTO(tradeOrder)
+	return
+}

+ 5 - 0
models/order/trade_order.go

@@ -53,3 +53,8 @@ func GetUnFailedTradeFlowByProductOrder(no string) (list []TradeOrder, err error
 	err = db.Where("product_order_id=? and payment_status!=? order by updated_time,created_time desc", no, PaymentStatusFailed).Find(&list).Error
 	return
 }
+func GetTradeOrderByNo(no string) (order TradeOrder, err error) {
+	db := models.Main()
+	err = db.Where("transaction_id=? and payment_type =?", no, PaymentTypePay).First(&order).Error
+	return
+}

+ 4 - 0
service/order/order_service.go

@@ -196,3 +196,7 @@ func GetProductOrderByUser(templateUserId int, orderNo string) (order orderServi
 func CloseProductOrder(templateUserId int, productOrderNo string) (err error) {
 	return orderService.CloseProductOrder(templateUserId, productOrderNo)
 }
+
+func GetTradeOrderByNo(tradeOrderNo string) (dto orderService.TradeOrderDTO, err error) {
+	return orderService.GetTradeOrderByNo(tradeOrderNo)
+}