|
|
@@ -556,3 +556,51 @@ func checkAndSendQuotaNotify(relayInfo *relaycommon.RelayInfo, quota int, preCon
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+func checkAndSendSubscriptionQuotaNotify(relayInfo *relaycommon.RelayInfo) {
|
|
|
+ gopool.Go(func() {
|
|
|
+ if relayInfo == nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if relayInfo.SubscriptionId == 0 || relayInfo.SubscriptionAmountTotal <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userSetting := relayInfo.UserSetting
|
|
|
+ threshold := common.QuotaRemindThreshold
|
|
|
+ if userSetting.QuotaWarningThreshold != 0 {
|
|
|
+ threshold = int(userSetting.QuotaWarningThreshold)
|
|
|
+ }
|
|
|
+
|
|
|
+ usedAfter := relayInfo.SubscriptionAmountUsedAfterPreConsume + relayInfo.SubscriptionPostDelta
|
|
|
+ remaining := relayInfo.SubscriptionAmountTotal - usedAfter
|
|
|
+ if remaining >= int64(threshold) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ prompt := "您的订阅额度即将用尽"
|
|
|
+ topUpLink := fmt.Sprintf("%s/console/topup", system_setting.ServerAddress)
|
|
|
+
|
|
|
+ var content string
|
|
|
+ var values []interface{}
|
|
|
+ notifyType := userSetting.NotifyType
|
|
|
+ if notifyType == "" {
|
|
|
+ notifyType = dto.NotifyTypeEmail
|
|
|
+ }
|
|
|
+
|
|
|
+ if notifyType == dto.NotifyTypeBark {
|
|
|
+ content = "{{value}},剩余额度:{{value}},请及时充值"
|
|
|
+ values = []interface{}{prompt, logger.FormatQuota(int(remaining))}
|
|
|
+ } else if notifyType == dto.NotifyTypeGotify {
|
|
|
+ content = "{{value}},当前剩余额度为 {{value}},请及时充值。"
|
|
|
+ values = []interface{}{prompt, logger.FormatQuota(int(remaining))}
|
|
|
+ } else {
|
|
|
+ content = "{{value}},当前剩余额度为 {{value}},为了不影响您的使用,请及时充值。<br/>充值链接:<a href='{{value}}'>{{value}}</a>"
|
|
|
+ values = []interface{}{prompt, logger.FormatQuota(int(remaining)), topUpLink, topUpLink}
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := NotifyUser(relayInfo.UserId, relayInfo.UserEmail, relayInfo.UserSetting, dto.NewNotify(dto.NotifyTypeQuotaExceed, prompt, content, values)); err != nil {
|
|
|
+ common.SysError(fmt.Sprintf("failed to send subscription quota notify to user %d: %s", relayInfo.UserId, err.Error()))
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|