whereKey($draw->id)->lockForUpdate()->firstOrFail(); if (! in_array($locked->status, [ DrawStatus::Cooldown->value, DrawStatus::Settling->value, ], true)) { throw new \RuntimeException('draw_not_ready_for_settlement'); } $hasPublishedResult = DrawResultBatch::query() ->where('draw_id', $locked->id) ->where('status', DrawResultBatchStatus::Published->value) ->exists(); if (! $hasPublishedResult) { throw new \RuntimeException('draw_result_not_published'); } $cooldownSkipped = $locked->status === DrawStatus::Cooldown->value; if ($cooldownSkipped) { $locked->forceFill([ 'status' => DrawStatus::Settling->value, 'cooling_end_time' => now(), ])->save(); } return [ 'draw' => $locked->fresh(), 'cooldown_skipped' => $cooldownSkipped, ]; }); } }