id)->lockForUpdate()->first(); if (!$locked) return false; if ((int)$locked->type === 2) { $grant(); return true; } $used = bcadd((string)($locked->budget_used ?? '0'), (string)$amount, 2); if ($locked->budget !== null && bccomp($used, (string)$locked->budget, 2) > 0) return false; $grant(); $locked->budget_used = $used; $locked->save(); return true; }); } }