mirror of
https://github.com/v2board/v2board.git
synced 2025-06-16 22:57:47 +08:00
update: add inventory limit
This commit is contained in:
@ -249,6 +249,11 @@ class OrderService
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$planService = new PlanService($order->plan_id);
|
||||
if (!$planService->incrementInventory()) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
DB::commit();
|
||||
return true;
|
||||
}
|
||||
|
29
app/Services/PlanService.php
Normal file
29
app/Services/PlanService.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Plan;
|
||||
|
||||
class PlanService
|
||||
{
|
||||
public $plan;
|
||||
|
||||
public function __construct(int $planId)
|
||||
{
|
||||
$this->plan = Plan::lockForUpdate()->find($planId);
|
||||
}
|
||||
|
||||
public function incrementInventory()
|
||||
{
|
||||
if ($this->plan->inventory_limit !== NULL) {
|
||||
return $this->plan->increment('inventory_limit');
|
||||
}
|
||||
}
|
||||
|
||||
public function decrementInventory()
|
||||
{
|
||||
if ($this->plan->inventory_limit !== NULL) {
|
||||
return $this->plan->decrement('inventory_limit');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user