Files
portal-api/app/Support/AutoEmailGate.php
T
baodev0andClaude Opus 5.5 30898ea46f feat: email gửi tay/nhắc gia hạn, gói hosting, sửa dữ liệu sản phẩm
- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt
- Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder
- Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway
- Backfill payment_method và ngày đơn hàng còn thiếu
- Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:32:05 +07:00

48 lines
1.1 KiB
PHP

<?php
namespace App\Support;
use App\Models\Setting;
use Illuminate\Support\Facades\Context;
final class AutoEmailGate
{
public const SCENARIO_DATA_KEY = '__mail_scenario';
private const MANUAL_CONTEXT_KEY = 'mail.manual_send';
public static function markManual(): void
{
Context::addHidden(self::MANUAL_CONTEXT_KEY, true);
}
public static function blocks(?string $scenario): bool
{
if ($scenario === null || Context::hasHidden(self::MANUAL_CONTEXT_KEY)) {
return false;
}
return in_array($scenario, self::disabledScenarios(), true);
}
public static function mailEnabled(): bool
{
return (bool) (self::emailSettings()['mail_enabled'] ?? true);
}
/**
* @return array<int, string>
*/
public static function disabledScenarios(): array
{
return (array) (self::emailSettings()['auto_disabled'] ?? []);
}
private static function emailSettings(): array
{
$value = Setting::where('key', 'email_settings')->value('value');
return (array) (json_decode($value ?? '', true) ?? []);
}
}