Update ShowServicios.php

This commit is contained in:
lizandrogd
2025-03-04 19:33:40 -05:00
parent 422452fd61
commit eedf2e9e2b
+17 -4
View File
@@ -26,6 +26,7 @@ use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Twilio\Rest\Client; use Twilio\Rest\Client;
use AshAllenDesign\ShortURL\Facades\ShortURL; use AshAllenDesign\ShortURL\Facades\ShortURL;
use Illuminate\Support\Facades\DB;
class ShowServicios extends Component class ShowServicios extends Component
{ {
@@ -239,6 +240,9 @@ class ShowServicios extends Component
/* ---------------- Btn Comprar ---------------- */ /* ---------------- Btn Comprar ---------------- */
public function comprar() public function comprar()
{ {
DB::beginTransaction();
try {
$this->validate([ $this->validate([
'cantidad_tarjetaPlan' => 'required|numeric|min:1', 'cantidad_tarjetaPlan' => 'required|numeric|min:1',
]); ]);
@@ -406,7 +410,7 @@ class ShowServicios extends Component
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' Se desligaron todas las cuentas.'; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' Se desligaron todas las cuentas.';
$logsGeneral->tipo = 'compra_error'; $logsGeneral->tipo = 'compra_error';
$logsGeneral->historial_id= $historial->id; $logsGeneral->historial_id = $historial->id;
$logsGeneral->save(); $logsGeneral->save();
$this->alert('warning', 'No hay cuentas disponibles!', [ $this->alert('warning', 'No hay cuentas disponibles!', [
'position' => 'top' 'position' => 'top'
@@ -427,7 +431,7 @@ class ShowServicios extends Component
$logsGeneral = new Log_general(); $logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ', Saldo anterior: $' . $saldo_anterior . ', Nuevo saldo disponible: $' . $nuevo_saldo;
$logsGeneral->historial_id= $historial->id; $logsGeneral->historial_id = $historial->id;
$logsGeneral->tipo = 'compra'; $logsGeneral->tipo = 'compra';
$logsGeneral->save(); $logsGeneral->save();
@@ -440,7 +444,7 @@ class ShowServicios extends Component
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo un error con el cobro del servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo un error con el cobro del servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor;
$logsGeneral->tipo = 'compra_error'; $logsGeneral->tipo = 'compra_error';
$logsGeneral->historial_id= $historial->id; $logsGeneral->historial_id = $historial->id;
$logsGeneral->save(); $logsGeneral->save();
$eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete(); $eliminar = Historial_cuenta::where('historial_id', $historial->id)->delete();
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [ $this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
@@ -455,16 +459,25 @@ class ShowServicios extends Component
$logsGeneral->user_id = Auth::user()->id; $logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' No se desconto el saldo, ni se asignaron cuentas.'; $logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' Tuvo error de "No hay cuentas disponibles" Comprando el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor . ' No se desconto el saldo, ni se asignaron cuentas.';
$logsGeneral->tipo = 'compra_error'; $logsGeneral->tipo = 'compra_error';
$logsGeneral->historial_id= $historial->id; $logsGeneral->historial_id = $historial->id;
$logsGeneral->save(); $logsGeneral->save();
$this->alert('warning', 'No hay cuentas disponibles!', [ $this->alert('warning', 'No hay cuentas disponibles!', [
'position' => 'top' 'position' => 'top'
]); ]);
} }
DB::commit();
$this->tarjetaPlan = false; $this->tarjetaPlan = false;
$this->cantidad_tarjetaPlan = 1; $this->cantidad_tarjetaPlan = 1;
} catch (Exception $e) {
DB::rollBack();
$this->alert('error', 'Error al comprar: ' . $e->getMessage(), [
'position' => 'top'
]);
}
} }
public function credenciales($historial) public function credenciales($historial)