Browse Source

增加系统配置接口

kobe6258 4 months ago
parent
commit
cba4846a60

+ 2 - 2
controllers/web_hook/htfutures_trade_controller.go

@@ -30,9 +30,9 @@ func (h *HTFuturesTradeController) InformPaymentResult() {
 		h.GetPostParams(s)
 		logger.Info("支付结果通知: %v", s)
 		if s.Success {
-			productOrderNo, _ := orderService.DealPayment(s.TradeOrderNo, orderService.PaySuccess)
+			productOrder, _ := orderService.DealPayment(s.TradeOrderNo, orderService.PaySuccess)
 			//privateKey, err := authUtils.ParsePrivateKey(htConfig.GetWebhookPrivateKey())
-			_ = product.OpenProduct(productOrderNo)
+			_ = product.OpenProduct(productOrder)
 		} else {
 			_, _ = orderService.DealPayment(s.TradeOrderNo, orderService.PayFail)
 		}

+ 41 - 0
domian/merchant/user_access_service.go

@@ -1,8 +1,12 @@
 package merchant
 
 import (
+	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/utils/page"
+	"eta/eta_mini_ht_api/domian/user"
 	"eta/eta_mini_ht_api/models/merchant"
+	subscribeDao "eta/eta_mini_ht_api/models/merchant"
+	"sync"
 	"time"
 )
 
@@ -51,7 +55,44 @@ func OpenProduct(templateUserId int, productOrderNo string, product MerchantProd
 	}
 	return merchant.InsertOrUpdateUserSubscribe(userAccess)
 }
+func ExpireProduct(deadLine string) (err error) {
+	total := user.GetNeedExpiredAccessCount(deadLine)
+	if total == 0 {
+		logger.Info("没有需要过期的产品")
+		return
+	}
+	for total > 0 {
+		list, _ := user.GetExpiredAccessList(100, deadLine)
+		if len(list) > 0 {
+			var wg sync.WaitGroup
+			wg.Add(len(list))
+			for _, access := range list {
+				go func(access subscribeDao.UserSubscriptionAccessList) {
+					defer wg.Done()
+					access.Status = subscribeDao.SubscribeExpired
+					expireErr := subscribeDao.ExpireUserAccess(access)
+					if expireErr != nil {
+						logger.Error("更新产品过期状态失败:%v,用户:%d,产品:%d", expireErr, access.TemplateUserId, access.ProductID)
+					}
+				}(access)
+			}
+			wg.Wait()
+		}
+		total = user.GetNeedExpiredAccessCount(deadLine)
+	}
 
+	//if err != nil {
+	//	logger.Error("获取产品订单信息失败:%v", err)
+	//	return
+	//}
+	//product, err := merchantService.GetMerchantProductById(productOrder.ProductID)
+	//if err != nil {
+	//	logger.Error("获取产品信息失败:%v", err)
+	//	return
+	//}
+	//return merchantService.CloseProduct(productOrderNo, product)
+	return
+}
 func CloseProduct(templateUserId int, productOrderNo string, product MerchantProductDTO) error {
 	userAccess := merchant.UserSubscriptionAccessList{
 		TemplateUserId: templateUserId,

+ 1 - 1
domian/order/product_order.go

@@ -111,7 +111,7 @@ func ConvertProductOrderDTO(order orderDao.ProductOrder) (orderDTO ProductOrderD
 		ID:             order.ID,
 		OrderID:        order.OrderID,
 		UserID:         order.UserID,
-		TemplateUserID: order.UserID,
+		TemplateUserID: order.TemplateUserID,
 		ProductID:      order.ProductID,
 		TradeNo:        order.TradeNO,
 		TotalAmount:    order.TotalAmount,

+ 15 - 2
domian/user/user_subscription_service.go

@@ -7,6 +7,19 @@ import (
 func GetUserSubscribe(productIds []int, userId int) (list []subscribeDao.UserSubscriptionAccessList, err error) {
 	return subscribeDao.GetUserSubscribe(productIds, userId)
 }
-func GetNeedExpiredAccessCount() (count int) {
-	return subscribeDao.GetNeedExpiredAccessCount()
+func GetNeedExpiredAccessCount(deadLine string) (count int) {
+	return subscribeDao.GetNeedExpiredAccessCount(deadLine)
+}
+
+type accessDTO struct {
+	ID             int
+	TemplateUserId int
+	ProductID      int
+	ProductName    string
+	ProductType    string
+	Status         string
+}
+
+func GetExpiredAccessList(num int, deadLine string) (list []subscribeDao.UserSubscriptionAccessList, err error) {
+	return subscribeDao.GetExpiredAccessList(num, deadLine)
 }

+ 17 - 3
models/merchant/user_subscription_access_list.go

@@ -92,7 +92,12 @@ func CloseUserAccess(access UserSubscriptionAccessList) (err error) {
 	// 执行批量插入或更新操作
 	return
 }
-
+func ExpireUserAccess(access UserSubscriptionAccessList) (err error) {
+	db := models.Main()
+	err = db.Model(&access).Where("template_user_id=? AND product_id=?", access.TemplateUserId, access.ProductID).Update("status", SubscribeClose).Error
+	// 执行批量插入或更新操作
+	return
+}
 func SubscribeList(templateUserId int, productType string, latestId int64, offset int, pageSize int) (list []UserSubscriptionAccessList, err error) {
 	db := models.Main()
 	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
@@ -118,9 +123,18 @@ func GetTotalUserPageCountByProductType(productType string, templateUserId int)
 	return
 }
 
-func GetNeedExpiredAccessCount() (count int) {
+func GetNeedExpiredAccessCount(deadLine string) (count int) {
+	db := models.Main()
+	err := db.Model(&UserSubscriptionAccessList{}).Select("count(*)").Where(" product_type=? and status=? and end_date <=?", Package, SubscribeValid, deadLine).Scan(&count).Error
+	if err != nil {
+		logger.Error("查询用户订阅总数失败:%s", err)
+	}
+	return
+}
+
+func GetExpiredAccessList(num int, deadLine string) (list []UserSubscriptionAccessList, err error) {
 	db := models.Main()
-	err := db.Model(&UserSubscriptionAccessList{}).Select("count(*)").Where(" product_type=? and status=? ", Package, SubscribeValid).Scan(&count).Error
+	err = db.Model(&UserSubscriptionAccessList{}).Select("*").Where(" product_type=? and status=? and end_date <=? limit 0,?", Package, SubscribeValid, deadLine, num).Find(&list).Error
 	if err != nil {
 		logger.Error("查询用户订阅总数失败:%s", err)
 	}

+ 1 - 14
service/product/product_service.go

@@ -187,20 +187,7 @@ func CloseProduct(templateUserId int, productOrderNo string) (err error) {
 }
 
 // 过期产品
-func ExpireProduct() (err error) {
-	_ = user.GetNeedExpiredAccessCount()
-	//if err != nil {
-	//	logger.Error("获取产品订单信息失败:%v", err)
-	//	return
-	//}
-	//product, err := merchantService.GetMerchantProductById(productOrder.ProductID)
-	//if err != nil {
-	//	logger.Error("获取产品信息失败:%v", err)
-	//	return
-	//}
-	//return merchantService.CloseProduct(productOrderNo, product)
-	return
-}
+
 func GetRelatePackage(info ProductDTO) (prodList []ProductDTO, err error) {
 	switch info.Type {
 	case "audio", "video":

+ 10 - 3
task/product/product_expire_task.go

@@ -3,8 +3,9 @@ package sms
 import (
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"eta/eta_mini_ht_api/common/contants"
-	productService "eta/eta_mini_ht_api/service/product"
+	productService "eta/eta_mini_ht_api/domian/merchant"
 	"eta/eta_mini_ht_api/task/base"
+	"time"
 )
 
 var (
@@ -15,8 +16,14 @@ var (
 // Execute Task ETA取研报的数据
 func (st *OrderTask) Execute(taskDetail *base.TaskDetail) error {
 	logger.Info(contants.TaskFormat, "处理到期产品开始")
-
-	err := productService.ExpireProduct()
+	dateTime := time.Now()
+	var deadLine string
+	if dateTime.Hour() <= 23 {
+		deadLine = dateTime.Add(time.Hour * 24).Format(time.DateOnly)
+	} else {
+		deadLine = dateTime.Format(time.DateOnly)
+	}
+	err := productService.ExpireProduct(deadLine)
 	if err != nil {
 		logger.Error("处理到期产品失败:%v", err)
 	}