This commit is contained in:
lizandrogd
2025-09-02 20:39:40 -05:00
parent a5aafd738d
commit d0f5d0c697
+11 -2
View File
@@ -241,9 +241,15 @@ class ShowServicios extends Component
/* ---------------- Btn Comprar ---------------- */ /* ---------------- Btn Comprar ---------------- */
public function comprar() public function comprar()
{ {
$maxIntentos = 3; // cantidad de veces que se intentará
$intento = 0;
while ($intento < $maxIntentos) {
DB::beginTransaction(); DB::beginTransaction();
try { try {
$intento++;
$this->validate([ $this->validate([
'cantidad_tarjetaPlan' => 'required|numeric|min:1', 'cantidad_tarjetaPlan' => 'required|numeric|min:1',
]); ]);
@@ -548,14 +554,17 @@ class ShowServicios extends Component
// Hacer rollback de cualquier cambio realizado en la base de datos // Hacer rollback de cualquier cambio realizado en la base de datos
DB::rollBack(); DB::rollBack();
// Establecer variables a su estado inicial o a un valor que indique error if ($intento >= $maxIntentos) {
$this->credenciales = false; $this->credenciales = false;
$this->cuentas = []; $this->cuentas = [];
// Mostrar un mensaje de alerta al usuario
$this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente. Error: ' . $e->getMessage(), [ $this->alert('warning', 'Error al comprar: Esta cuenta ha sido tomada por otro usuario al mismo tiempo, intenta nuevamente. Error: ' . $e->getMessage(), [
'position' => 'top' 'position' => 'top'
]); ]);
return;
}
usleep(200000); // 200ms
}
} }
} }