diff --git a/app/Console/Commands/validacionCompra.php b/app/Console/Commands/validacionCompra.php index b5d5234..46a018d 100644 --- a/app/Console/Commands/validacionCompra.php +++ b/app/Console/Commands/validacionCompra.php @@ -2,6 +2,7 @@ namespace App\Console\Commands; +use App\Models\Historial_cuenta; use App\Models\Historiale; use App\Models\Log_general; use App\Models\User; @@ -35,8 +36,8 @@ class validacionCompra extends Command public function handle() { $fecha_ahora = Carbon::now()->format('Y-m-d H:i:s'); // Fecha y hora actual - $hora_antes = Carbon::now()->subHours(100)->format('Y-m-d H:i:s'); // 24 horas antes - //$hora_antes = Carbon::now()->subMinutes(10)->format('Y-m-d H:i:s'); + //$hora_antes = Carbon::now()->subHours(100)->format('Y-m-d H:i:s'); // 24 horas antes + $hora_antes = Carbon::now()->subMinutes(15)->format('Y-m-d H:i:s'); $resultados = Historiale::select('vendedor_id') @@ -71,12 +72,13 @@ class validacionCompra extends Command ->exists(); // Corregido if ($validar_actual && $validar_anterior) { + echo "Compra duplicada: {$anterior->created_at} - {$registro->created_at}
"; $vendedor = User::find($resultado->vendedor_id); $email = $vendedor->email; $mensaje = "⚠️ Compra Duplicada ⚠️\nUsuario: {$email}\nFechas:\n- Anterior: {$anterior->created_at}\n- Actual: {$registro->created_at}\nDiferencia: {$diferencia} segundos"; $this->enviarTelegram($mensaje); $corregido = $this->corregir($anterior->id, $registro->id); - + //echo "Corregido: " . $corregido; if ($corregido === true) { // Aseguramos que la corrección fue exitosa $mensaje = "📌 Corregido 📌\n" . "🆔 Historial ID inactivo: " . addslashes($registro->id) . "\n" . @@ -89,14 +91,14 @@ class validacionCompra extends Command $this->enviarTelegram($mensaje); - /* Log_general::create([ + Log_general::create([ 'user_id' => $resultado->vendedor_id, 'historial_id' => $registro->id, 'tipo' => 'corregido', 'detalle' => 'Se ha corregido la compra duplicada, usuario: ' . $email . ' - ' . Carbon::parse($registro->created_at)->format('d M Y h:i A') . ' - ' . Carbon::parse($anterior->created_at)->format('d M Y h:i A'), - ]); */ + ]); } } @@ -149,13 +151,14 @@ class validacionCompra extends Command $actualizar_saldo->save(); // Cancelar historial actual - //$historial_actual->estado = 'cancelado'; + $historial_actual->estado = 'cancelado'; $historial_actual->save(); + $cuentahistorial = Historial_cuenta::where('historial_id', $historial_actual->id)->get(); // Eliminar cuentas asociadas - if ($historial_actual->cuentas) { - foreach ($historial_actual->cuentas as $cuenta) { - //$cuenta->delete(); + if (!$cuentahistorial->isEmpty()) { + foreach ($cuentahistorial as $cuenta) { + $cuenta->delete(); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 6f650a3..f345772 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -34,7 +34,8 @@ class Kernel extends ConsoleKernel // $schedule->exec('nohup php /var/www/sirpremium/artisan queue:work --sleep=3 --tries=3 > /dev/null 2>&1 &')->everyMinute(); - //$schedule->command('tarea:validarCompra')->everyMinute(); + $schedule->command('tarea:validarCompra')->everyTenMinutes(); + $schedule->call(function () {