feat(subscription): implement effective plan logic and update free plan features

This commit is contained in:
hamed
2026-07-05 10:46:31 +03:30
parent f3ca6d844f
commit 828e3552c0
10 changed files with 148 additions and 30 deletions
@@ -7,6 +7,7 @@ use App\Payment\Entity\Payment;
use App\Shared\Constant\ErrorCodes;
use App\Shared\Exception\AppException;
use App\Subscription\Entity\ClinicSubscription;
use App\Subscription\Entity\SubscriptionPlan;
use App\Subscription\Repository\ClinicSubscriptionRepository;
use App\Subscription\Repository\SubscriptionPeriodRepository;
use App\Subscription\Repository\SubscriptionPlanRepository;
@@ -25,24 +26,28 @@ class SubscriptionService
return $this->subscriptionRepo->findActive($entityType, $entityId);
}
public function hasFeature(string $entityType, int $entityId, string $feature): bool
/**
* پلن مؤثر: پلن اشتراک فعال، یا در نبود اشتراک، پلن پیش‌فرض «free».
*/
public function getEffectivePlan(string $entityType, int $entityId): ?SubscriptionPlan
{
$subscription = $this->getActiveSubscription($entityType, $entityId);
if ($subscription === null) {
return false;
}
return $subscription->getPlan()->hasFeature($feature);
return $subscription?->getPlan() ?? $this->planRepo->findByName('free');
}
public function hasFeature(string $entityType, int $entityId, string $feature): bool
{
$plan = $this->getEffectivePlan($entityType, $entityId);
return $plan !== null && $plan->hasFeature($feature);
}
public function getSecretaryLimit(string $entityType, int $entityId): int
{
$subscription = $this->getActiveSubscription($entityType, $entityId);
if ($subscription === null) {
return 1;
}
$plan = $this->getEffectivePlan($entityType, $entityId);
return $subscription->getPlan()->getMaxSecretaries();
return $plan?->getMaxSecretaries() ?? 1;
}
public function hasUsedTrial(string $entityType, int $entityId): bool