update
This commit is contained in:
@@ -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}<br>";
|
||||
$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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user