浏览代码

过滤下架产品

kobe6258 4 月之前
父节点
当前提交
99486ec082
共有 2 个文件被更改,包括 22 次插入7 次删除
  1. 19 5
      domian/order/trade_order.go
  2. 3 2
      models/order/trade_order.go

+ 19 - 5
domian/order/trade_order.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/models"
+	merchantDao "eta/eta_mini_ht_api/models/merchant"
 	"eta/eta_mini_ht_api/models/message"
 	"eta/eta_mini_ht_api/models/order"
 	"fmt"
@@ -221,17 +222,30 @@ func DealPayment(tradeOrderNo string, flag string) (productOrderDTO ProductOrder
 	if flag == PaySuccess {
 		isSuccess = true
 	}
-	err = order.DealPaymentOrder(tradeOrder, isSuccess)
-	if err != nil {
-		logger.Error("处理支付结果失败%v,支付订单:%s", err, tradeOrderNo)
-		return
-	}
 	var productOrder order.ProductOrder
 	productOrder, err = order.GetOrderByOrderNo(tradeOrder.ProductOrderID)
 	if err != nil {
 		logger.Error("获取产品订单失败%v,支付订单:%s", err, tradeOrderNo)
 		return
 	}
+	product, err := merchantDao.GetMerchantProductById(productOrder.ProductID)
+	if err != nil {
+		logger.Error("获取产品信息失败:%v,productId:%d", err, productOrder.ProductID)
+	}
+	var validDuration string
+	if product.Type == merchantDao.Package {
+		beginDate := time.Now().Format(time.DateOnly)
+		endDate := time.Now().Add(time.Duration(product.ValidDays * 24)).Format(time.DateOnly)
+		validDuration = fmt.Sprintf("%s~%s", beginDate, endDate)
+	} else {
+		validDuration = "永久有效"
+	}
+	err = order.DealPaymentOrder(tradeOrder, isSuccess, validDuration)
+	if err != nil {
+		logger.Error("处理支付结果失败%v,支付订单:%s", err, tradeOrderNo)
+		return
+	}
+
 	productOrderDTO = ConvertProductOrderDTO(productOrder)
 	return
 }

+ 3 - 2
models/order/trade_order.go

@@ -99,7 +99,7 @@ func DealRefundOrder(order TradeOrder, isSuccess bool) (err error) {
 	return
 }
 
-func DealPaymentOrder(order TradeOrder, isSuccess bool) (err error) {
+func DealPaymentOrder(order TradeOrder, isSuccess bool, validDuration string) (err error) {
 	var paymentStatus PaymentStatus
 	if isSuccess {
 		paymentStatus = PaymentStatusDone
@@ -124,7 +124,8 @@ func DealPaymentOrder(order TradeOrder, isSuccess bool) (err error) {
 	}
 	if isSuccess {
 		err = tx.Model(&ProductOrder{}).Where("order_id=?", order.ProductOrderID).Updates(map[string]interface{}{
-			"status": OrderStatusPaid,
+			"status":         OrderStatusPaid,
+			"valid_duration": validDuration,
 		}).Error
 	}