Parcourir la source

修复支付订单bug

kobe6258 il y a 4 mois
Parent
commit
c4917dd777

+ 25 - 3
domian/merchant/user_access_service.go

@@ -11,14 +11,27 @@ type UserAccessDTO struct {
 	TemplateUserId int
 	ProductID      int
 	ProductType    string
+	BeginDate      string
+	EndDate        string
 }
 
+var (
+	productMap = map[string]merchant.MerchantProductType{
+		"package": merchant.Package,
+		"video":   merchant.Video,
+		"audio":   merchant.Audio,
+		"report":  merchant.Report,
+	}
+)
+
 func convertToUserAccessDTO(userSubscriptionAccessList merchant.UserSubscriptionAccessList) UserAccessDTO {
 	return UserAccessDTO{
 		ID:             userSubscriptionAccessList.ID,
 		TemplateUserId: userSubscriptionAccessList.TemplateUserId,
 		ProductID:      userSubscriptionAccessList.ProductID,
-		ProductType:    userSubscriptionAccessList.ProductType,
+		ProductType:    string(userSubscriptionAccessList.ProductType),
+		BeginDate:      userSubscriptionAccessList.BeginDate.Format(time.DateOnly),
+		EndDate:        userSubscriptionAccessList.EndDate.Format(time.DateOnly),
 	}
 }
 func OpenProduct(templateUserId int, productOrderNo string, product MerchantProductDTO) error {
@@ -26,7 +39,7 @@ func OpenProduct(templateUserId int, productOrderNo string, product MerchantProd
 		TemplateUserId: templateUserId,
 		ProductID:      product.Id,
 		ProductName:    product.Title,
-		ProductType:    product.Type,
+		ProductType:    productMap[product.Type],
 		BeginDate:      time.Now(),
 		Status:         merchant.SubscribeValid,
 		ProductOrderNo: productOrderNo,
@@ -42,7 +55,7 @@ func CloseProduct(templateUserId int, productOrderNo string, product MerchantPro
 		TemplateUserId: templateUserId,
 		ProductID:      product.Id,
 		ProductName:    product.Title,
-		ProductType:    product.Type,
+		ProductType:    productMap[product.Type],
 		Status:         merchant.SubscribeClose,
 		ProductOrderNo: productOrderNo,
 	}
@@ -61,6 +74,15 @@ func SubscribeList(templateUserId int, productType string, pageInfo page.PageInf
 	}
 	return
 }
+func GetUserSubscribe(templateUserId int, productId int) (dto UserAccessDTO, err error) {
+	var subscribe merchant.UserSubscriptionAccessList
+	subscribe, err = merchant.GetUserSubscribeById(templateUserId, productId)
+	if err != nil {
+		return
+	}
+	dto = convertToUserAccessDTO(subscribe)
+	return
+}
 
 func GetTotalUserPageCountByProductType(productType string, id int) (int64, int64) {
 	return merchant.GetTotalUserPageCountByProductType(productType, id)

+ 20 - 1
domian/order/product_order.go

@@ -4,6 +4,7 @@ import (
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/exception"
 	"eta/eta_mini_ht_api/common/utils/page"
+	"eta/eta_mini_ht_api/domian/merchant"
 	productDao "eta/eta_mini_ht_api/models/merchant"
 	orderDao "eta/eta_mini_ht_api/models/order"
 	"fmt"
@@ -36,6 +37,7 @@ type ProductOrderDTO struct {
 
 type ProductOrderDetailDTO struct {
 	ProductOrderDTO
+	ValidDuration    string
 	TransactionID    int
 	PaymentTime      string
 	RefundFinishTime string
@@ -64,7 +66,12 @@ var (
 		"audio":   productDao.Audio,
 		"package": productDao.Package,
 	}
-
+	productTransMap = map[productDao.MerchantProductType]string{
+		productDao.Package: "package",
+		productDao.Video:   "video",
+		productDao.Audio:   "audio",
+		productDao.Report:  "report",
+	}
 	productOrderStatusMap = map[string]orderDao.OrderStatus{
 		"closed":  orderDao.OrderStatusClosed,
 		"paid":    orderDao.OrderStatusPaid,
@@ -158,6 +165,18 @@ func convertProductOrderDetailDTO(order orderDao.ProductOrder) (orderDetailDTO P
 			orderDetailDTO.PaymentTimeRemain = int64(duration.Seconds())
 		}
 	}
+	if order.Status == orderDao.OrderStatusPaid {
+		access, err := merchant.GetUserSubscribe(order.TemplateUserID, order.ProductID)
+		if err != nil {
+			logger.Error("获取用户订阅信息失败:%v,templateUserId:%d,productId :%d", err, order.TemplateUserID, order.ProductID)
+		}
+		if access.ProductType == productTransMap[productDao.Package] {
+			orderDetailDTO.ValidDuration = "永久有效"
+		} else {
+			orderDetailDTO.ValidDuration = fmt.Sprintf("%s~%s", access.BeginDate, access.EndDate)
+		}
+
+	}
 	return
 }
 

+ 17 - 13
models/merchant/user_subscription_access_list.go

@@ -26,17 +26,17 @@ var (
 
 // 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    string          `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:"-"`
+	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:"-"`
 }
 
 func (UserSubscriptionAccessList) TableName() string {
@@ -53,7 +53,7 @@ func (access *UserSubscriptionAccessList) BeforeCreate(_ *gorm.DB) (err error) {
 	access.CreatedTime = time.Now()
 	flow := UserSubscriptionAccessFlow{
 		ProductID:      access.ProductID,
-		ProductType:    access.ProductType,
+		ProductType:    string(access.ProductType),
 		ProductOrderId: access.ProductOrderNo,
 		OpenType:       subscribeStatusMap[access.Status],
 		CreatedTime:    time.Now(),
@@ -98,7 +98,11 @@ func SubscribeList(templateUserId int, productType string, latestId int64, offse
 	err = db.Model(&UserSubscriptionAccessList{}).Where("id<=? and template_user_id=? AND product_type=? and status=?", latestId, templateUserId, productType, SubscribeValid).Order("begin_date desc").Offset(offset).Limit(pageSize).Find(&list).Error
 	return
 }
-
+func GetUserSubscribeById(templateUserId int, productId int) (list UserSubscriptionAccessList, err error) {
+	db := models.Main()
+	err = db.Select("id,template_user_id,product_id,product_name,begin_date,end_date,status").Where(" template_user_id=? AND product_id=? and status=?", templateUserId, productId).First(&list).Error
+	return
+}
 func GetTotalUserPageCountByProductType(productType string, templateUserId int) (count int64, latestId int64) {
 	db := models.Main()
 	err := db.Model(&UserSubscriptionAccessList{}).Select("count(*)").Where("template_user_id=? AND product_type=? and status=?", templateUserId, productType, SubscribeValid).Scan(&count).Error