refactor(webhook): Phase 3 Task 3.5 - remove notifyLowBalance/notifyZeroBalance from NotificationService

This commit is contained in:
Дмитрий
2026-05-24 16:32:18 +03:00
parent 96f2181e07
commit 06930b1830
-48
View File
@@ -5,11 +5,9 @@ declare(strict_types=1);
namespace App\Services;
use App\Mail\InvoicePaidNotification;
use App\Mail\LowBalanceNotification;
use App\Mail\NewLeadNotification;
use App\Mail\ReminderDueNotification;
use App\Mail\TopupSuccessNotification;
use App\Mail\ZeroBalanceNotification;
use App\Mail\ZeroBalancePausedMail;
use App\Models\Deal;
use App\Models\InAppNotification;
@@ -147,52 +145,6 @@ class NotificationService
}
}
/**
* Уведомление о низком балансе. Триггер: ProcessWebhookJob после
* lead_charge, если balance_leads <= threshold.
*
* Получатели: все активные user'ы тенанта с new_lead.email=true
* (на MVP: те же что и для new_lead обычно владелец и менеджеры).
* По prefs `low_balance.email`.
*/
public function notifyLowBalance(Tenant $tenant, int $thresholdLeads): void
{
$title = "Низкий баланс — {$tenant->balance_leads} лидов осталось";
$body = "Порог уведомления: {$thresholdLeads} лидов";
foreach ($this->recipientsForEvent($tenant, self::EVENT_LOW_BALANCE, self::CHANNEL_EMAIL) as $user) {
$this->sendEmail($user, self::EVENT_LOW_BALANCE, new LowBalanceNotification($user, $tenant, $thresholdLeads));
}
foreach ($this->recipientsForEvent($tenant, self::EVENT_LOW_BALANCE, self::CHANNEL_INAPP) as $user) {
$this->notifyInApp($user, self::EVENT_LOW_BALANCE, $title, $body, [
'tenant_id' => $tenant->id,
'balance_leads' => $tenant->balance_leads,
'threshold_leads' => $thresholdLeads,
]);
}
}
/**
* Уведомление о нулевом балансе и отклонении лидов.
* Триггер: ProcessWebhookJob::logRejection(zero_balance) в первом
* RejectedDealsLog за последний час (anti-spam: не более 1 email/час
* на тенант, проверка в caller).
*/
public function notifyZeroBalance(Tenant $tenant): void
{
$title = 'Баланс закончился — лиды отклоняются';
$body = 'Пополните баланс в разделе Биллинг';
foreach ($this->recipientsForEvent($tenant, self::EVENT_ZERO_BALANCE, self::CHANNEL_EMAIL) as $user) {
$this->sendEmail($user, self::EVENT_ZERO_BALANCE, new ZeroBalanceNotification($user, $tenant));
}
foreach ($this->recipientsForEvent($tenant, self::EVENT_ZERO_BALANCE, self::CHANNEL_INAPP) as $user) {
$this->notifyInApp($user, self::EVENT_ZERO_BALANCE, $title, $body, [
'tenant_id' => $tenant->id,
]);
}
}
/**
* Уведомление об auto-pause проекта на нулевом балансе (Plan 4 Task 6).
*