2022-06-30 03:18:30 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\Plan;
|
2022-07-08 02:36:33 +08:00
|
|
|
use App\Models\User;
|
2022-06-30 03:18:30 +08:00
|
|
|
|
|
|
|
class PlanService
|
|
|
|
{
|
|
|
|
public $plan;
|
|
|
|
|
|
|
|
public function __construct(int $planId)
|
|
|
|
{
|
|
|
|
$this->plan = Plan::lockForUpdate()->find($planId);
|
|
|
|
}
|
|
|
|
|
2022-07-08 02:36:33 +08:00
|
|
|
public function haveCapacity(): bool
|
2022-06-30 03:18:30 +08:00
|
|
|
{
|
2022-07-08 12:07:36 +08:00
|
|
|
if ($this->plan->capacity_limit === NULL) return true;
|
2022-07-08 02:36:33 +08:00
|
|
|
$count = User::where('plan_id', $this->plan->plan_id)->count();
|
|
|
|
return $this->plan->capacity_limit - $count;
|
2022-06-30 03:18:30 +08:00
|
|
|
}
|
|
|
|
}
|