v2board/app/Services/PlanService.php

24 lines
472 B
PHP
Raw Normal View History

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 02:36:33 +08:00
if ($this->plan->capacity_limit === 0) return true;
$count = User::where('plan_id', $this->plan->plan_id)->count();
return $this->plan->capacity_limit - $count;
2022-06-30 03:18:30 +08:00
}
}