up
This commit is contained in:
@@ -241,9 +241,15 @@ class ShowServicios extends Component
|
||||
/* ---------------- Btn Comprar ---------------- */
|
||||
public function comprar()
|
||||
{
|
||||
$maxIntentos = 3; // cantidad de veces que se intentará
|
||||
$intento = 0;
|
||||
|
||||
while ($intento < $maxIntentos) {
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$intento++;
|
||||
$this->validate([
|
||||
'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
|
||||
DB::rollBack();
|
||||
|
||||
// Establecer variables a su estado inicial o a un valor que indique error
|
||||
if ($intento >= $maxIntentos) {
|
||||
$this->credenciales = false;
|
||||
$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(), [
|
||||
'position' => 'top'
|
||||
]);
|
||||
return;
|
||||
}
|
||||
usleep(200000); // 200ms
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user