update: rewrite buy limit

This commit is contained in:
tokumeikoi
2022-07-08 02:36:33 +08:00
parent 2823f1bd47
commit 838fc7bdba
11 changed files with 90 additions and 27 deletions

View File

@ -85,7 +85,7 @@ class OrderController extends Controller
abort(500, __('Subscription plan does not exist'));
}
if ($plan->inventory_limit !== NULL && !$plan->inventory_limit) {
if (!$planService->haveCapacity()) {
abort(500, __('Current product is sold out'));
}
@ -160,10 +160,6 @@ class OrderController extends Controller
}
}
if (!$planService->decrementInventory()) {
abort(500, __('Failed to create order'));
}
if (!$order->save()) {
DB::rollback();
abort(500, __('Failed to create order'));