Browse Source

商品订单

kobe6258 4 months ago
parent
commit
76e5f4572c
4 changed files with 86 additions and 19 deletions
  1. 43 19
      controllers/order.go
  2. 2 0
      models/product_order.go
  3. 6 0
      models/trade_order.go
  4. 35 0
      models/user_subscription_access_list.go

+ 43 - 19
controllers/order.go

@@ -211,25 +211,49 @@ func (this *OrderController) ProductOrderList() {
 		return
 	}
 	var ListView []*models.ProductOrderView
-	for _, order := range List {
-		view := &models.ProductOrderView{
-			OrderID:          order.OrderID,
-			RealName:         order.RealName,
-			Mobile:           fmt.Sprintf("+%s %s", order.AreaCode, order.Mobile),
-			ProductType:      ProductTypeMap[order.ProductType],
-			ProductName:      order.ProductName,
-			TotalAmount:      order.TotalAmount,
-			TradeNO:          order.TradeNO,
-			RefundAmount:     order.RefundAmount,
-			PaymentWay:       PaymentWayMap[order.PaymentWay],
-			PaymentTime:      order.PaymentTime.Format(time.DateTime),
-			Status:           ProductOrderStatus[order.Status],
-			RefundStatus:     RefundStatusMap[order.RefundStatus],
-			RefundFinishTime: order.RefundFinishTime.Format(time.DateTime),
-			Remark:           order.Remark,
-			CreatedTime:      order.CreatedTime.Format(time.DateTime),
-		}
-		ListView = append(ListView, view)
+	var wg sync.WaitGroup
+	wg.Add(len(List))
+	for _, orderItem := range List {
+		go func(orderItem *models.ProductOrder) {
+			defer wg.Done()
+			view := &models.ProductOrderView{
+				OrderID:          orderItem.OrderID,
+				RealName:         orderItem.RealName,
+				Mobile:           fmt.Sprintf("+%s %s", orderItem.AreaCode, orderItem.Mobile),
+				ProductType:      ProductTypeMap[orderItem.ProductType],
+				ProductName:      orderItem.ProductName,
+				TotalAmount:      orderItem.TotalAmount,
+				TradeNO:          orderItem.TradeNO,
+				RefundAmount:     orderItem.RefundAmount,
+				PaymentWay:       PaymentWayMap[orderItem.PaymentWay],
+				PaymentTime:      orderItem.PaymentTime.Format(time.DateTime),
+				Status:           ProductOrderStatus[orderItem.Status],
+				RefundStatus:     RefundStatusMap[orderItem.RefundStatus],
+				RefundFinishTime: orderItem.RefundFinishTime.Format(time.DateTime),
+				Remark:           orderItem.Remark,
+				CreatedTime:      orderItem.CreatedTime.Format(time.DateTime),
+			}
+			if orderItem.TradeNO != "" {
+				tradeOrder, tradeErr := models.GetTradeOrderByNo(orderItem.TradeNO)
+				if tradeErr != nil {
+					utils.FileLog.Error("获取支付订单失败,支付订单号:" + orderItem.TradeNO + ",err:" + tradeErr.Error())
+				} else {
+					view.PaymentAmount = tradeOrder.Amount
+				}
+			}
+			if orderItem.Status == models.OrderStatusPaid {
+				access, accessErr := models.GetAccess(orderItem.ProductID, orderItem.TemplateUserID)
+				if accessErr != nil {
+					utils.FileLog.Error("获取用户订阅记录失败,templateUserId:" + string(orderItem.TemplateUserID) + "productId:" + string(orderItem.ProductID) + ",err:" + accessErr.Error())
+				}
+				if access.ProductType == models.ProductPackage {
+					view.ValidDuration = fmt.Sprintf("%s~%s", access.BeginDate.Format(time.DateOnly), access.EndDate.Format(time.DateOnly))
+				} else {
+					view.ValidDuration = "永久有效"
+				}
+			}
+			ListView = append(ListView, view)
+		}(orderItem)
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp := new(response.ProductOrderListResp)

+ 2 - 0
models/product_order.go

@@ -35,6 +35,8 @@ type ProductOrderView struct {
 	ProductType      string
 	ProductName      string
 	TotalAmount      string
+	ValidDuration    string
+	PaymentAmount    string
 	TradeNO          string
 	RefundAmount     string
 	PaymentWay       string

+ 6 - 0
models/trade_order.go

@@ -87,3 +87,9 @@ func GetTradeOrderCountByCondition(condition string) (total int, err error) {
 	err = o.Raw("select count(*) from trade_orders where 1=1 " + condition).QueryRow(&total)
 	return
 }
+
+func GetTradeOrderByNo(tradeNo string) (tradeOrder TradeOrder, err error) {
+	o := orm.NewOrm()
+	err = o.Raw("select * from trade_orders where transsaction_id=? ", tradeNo).QueryRow(&tradeOrder)
+	return
+}

+ 35 - 0
models/user_subscription_access_list.go

@@ -0,0 +1,35 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// UserSubscriptionAccessList 用户订阅访问列表
+type UserSubscriptionAccessList struct {
+	ID             int                 `gorm:"column:id;primaryKey"`
+	TemplateUserId int                 `gorm:"column:template_user_id"`
+	ProductID      int                 `gorm:"column:product_id"`
+	ProductName    string              `gorm:"column:product_name"`
+	ProductType    MerchantProductType `gorm:"column:product_type"`
+	BeginDate      time.Time           `gorm:"column:begin_date"`
+	EndDate        time.Time           `gorm:"column:end_date"`
+	Status         SubscribeStatus     `gorm:"column:status;type:enum('valid','expired');default:'valid'"`
+	CreatedTime    time.Time           `gorm:"column:created_time"`
+	UpdatedTime    time.Time           `gorm:"column:updated_time"`
+	ProductOrderNo string              `gorm:"-"`
+}
+
+type SubscribeStatus string
+
+const (
+	SubscribeValid   SubscribeStatus = "valid"
+	SubscribeExpired SubscribeStatus = "expired"
+	SubscribeClose   SubscribeStatus = "closed"
+)
+
+func GetAccess(productId int, templateUserId int) (access *UserSubscriptionAccessList, err error) {
+	o := orm.NewOrm()
+	err = o.Raw("select * from UserSubscriptionAccessList where template_user_id=? and  product_id =? ", templateUserId, productId).QueryRow(&access)
+	return
+}