Update: 2026-05-15 15:02:14
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Core\Cache;
|
||||
|
||||
final class QuotaMiddleware
|
||||
{
|
||||
@@ -22,17 +23,26 @@ final class QuotaMiddleware
|
||||
*/
|
||||
public static function checkInvoiceQuota(string $tenantId): array
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$cacheKey = "quota_sub_{$tenantId}";
|
||||
$sub = Cache::get($cacheKey);
|
||||
|
||||
// Fetch subscription with plan info
|
||||
$stmt = $db->prepare("
|
||||
SELECT s.*, sp.name_ar as plan_name, sp.ai_features, sp.jofotara_enabled
|
||||
FROM subscriptions s
|
||||
LEFT JOIN subscription_plans sp ON s.plan_id = sp.id
|
||||
WHERE s.tenant_id = ?
|
||||
");
|
||||
$stmt->execute([$tenantId]);
|
||||
$sub = $stmt->fetch();
|
||||
if ($sub === false || $sub === null) {
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Fetch subscription with plan info
|
||||
$stmt = $db->prepare("
|
||||
SELECT s.*, sp.name_ar as plan_name, sp.ai_features, sp.jofotara_enabled
|
||||
FROM subscriptions s
|
||||
LEFT JOIN subscription_plans sp ON s.plan_id = sp.id
|
||||
WHERE s.tenant_id = ?
|
||||
");
|
||||
$stmt->execute([$tenantId]);
|
||||
$sub = $stmt->fetch();
|
||||
|
||||
if ($sub) {
|
||||
Cache::set($cacheKey, $sub, 300); // Cache for 5 minutes
|
||||
}
|
||||
}
|
||||
|
||||
if (!$sub) {
|
||||
json_error('لا يوجد اشتراك فعّال لهذا المكتب. يرجى التواصل مع الإدارة.', 403);
|
||||
@@ -100,6 +110,9 @@ final class QuotaMiddleware
|
||||
WHERE tenant_id = ?
|
||||
");
|
||||
$stmt->execute([$tenantId]);
|
||||
|
||||
// Invalidate cache
|
||||
Cache::forget("quota_sub_{$tenantId}");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user