|
@@ -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,
|