Update ShowServicios.php
This commit is contained in:
@@ -27,6 +27,7 @@ use Illuminate\Support\Facades\Notification;
|
||||
use Twilio\Rest\Client;
|
||||
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class ShowServicios extends Component
|
||||
{
|
||||
@@ -550,20 +551,38 @@ class ShowServicios extends Component
|
||||
|
||||
$this->tarjetaPlan = false;
|
||||
$this->cantidad_tarjetaPlan = 1;
|
||||
} catch (Exception $e) {
|
||||
// Hacer rollback de cualquier cambio realizado en la base de datos
|
||||
|
||||
// si todo salió bien → salir del bucle
|
||||
break;
|
||||
} catch (QueryException $e) {
|
||||
DB::rollBack();
|
||||
|
||||
if ($intento >= $maxIntentos) {
|
||||
$this->credenciales = false;
|
||||
$this->cuentas = [];
|
||||
// PostgreSQL/MariaDB lanza 23505 cuando hay conflicto de índice único
|
||||
if ($e->getCode() == '23505') {
|
||||
// ⚡ Reintentar, otra transacción tomó la misma cuenta
|
||||
if ($intento >= $maxIntentos) {
|
||||
$this->alert('warning', 'Error: Otra persona tomó la cuenta al mismo tiempo. Intenta nuevamente.', [
|
||||
'position' => 'top'
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente. Error: ' . $e->getMessage(), [
|
||||
'position' => 'top'
|
||||
]);
|
||||
return;
|
||||
usleep(200000); // 200ms antes de reintentar
|
||||
continue;
|
||||
}
|
||||
usleep(200000); // 200ms
|
||||
|
||||
// Otros errores no son de concurrencia
|
||||
$this->alert('error', 'Error inesperado en la compra: ' . $e->getMessage(), [
|
||||
'position' => 'top'
|
||||
]);
|
||||
return;
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
$this->alert('error', 'Error inesperado: ' . $e->getMessage(), [
|
||||
'position' => 'top'
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user