2022-06-30 03:18:30 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\Plan;
|
|
|
|
|
|
|
|
class PlanService
|
|
|
|
{
|
|
|
|
public $plan;
|
|
|
|
|
|
|
|
public function __construct(int $planId)
|
|
|
|
{
|
|
|
|
$this->plan = Plan::lockForUpdate()->find($planId);
|
|
|
|
}
|
|
|
|
|
2022-06-30 03:20:13 +08:00
|
|
|
public function incrementInventory(): bool
|
2022-06-30 03:18:30 +08:00
|
|
|
{
|
2022-07-03 03:11:57 +08:00
|
|
|
if ($this->plan->inventory_limit === NULL) return true;
|
2022-06-30 03:20:13 +08:00
|
|
|
return $this->plan->increment('inventory_limit');
|
2022-06-30 03:18:30 +08:00
|
|
|
}
|
|
|
|
|
2022-06-30 03:20:13 +08:00
|
|
|
public function decrementInventory(): bool
|
2022-06-30 03:18:30 +08:00
|
|
|
{
|
2022-07-03 03:11:57 +08:00
|
|
|
if ($this->plan->inventory_limit === NULL) return true;
|
2022-06-30 03:20:13 +08:00
|
|
|
return $this->plan->decrement('inventory_limit');
|
2022-06-30 03:18:30 +08:00
|
|
|
}
|
|
|
|
}
|