diff --git a/app/Console/Commands/validacionCompra.php b/app/Console/Commands/validacionCompra.php index 70aa4d3..60f9ec8 100644 --- a/app/Console/Commands/validacionCompra.php +++ b/app/Console/Commands/validacionCompra.php @@ -60,52 +60,55 @@ class validacionCompra extends Command foreach ($registro_vendedores_duplicados as $index => $registro) { if ($index > 0) { $anterior = $registro_vendedores_duplicados[$index - 1]; - $diferencia = Carbon::parse($anterior->created_at)->diffInSeconds(Carbon::parse($registro->created_at)); + if ($anterior->valor == $registro->valor && $anterior->tarifa_id == $registro->tarifa_id && $anterior->promocion_id == $registro->promocion_id) { - if ($diferencia < 20) { - //echo "Diferencia: {$diferencia} segundos
Vendedor ID: {$anterior->nombre_cliente}- {$anterior->created_at} - {$registro->created_at}

"; - $validar_actual = Log_general::where('historial_id', $registro->id) - ->where('tipo', 'compra') - ->exists(); // Corregido - - $validar_anterior = Log_general::where('historial_id', $anterior->id) - ->where('tipo', 'compra') - ->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" . - "🆔 Historial ID activo: " . addslashes($anterior->id) . "\n" . - "👤 Saldo retornado: " . addslashes($registro->valor) . "\n" . - "👤 Usuario: " . addslashes($email) . "\n" . - "📅 Fechas:\n" . - " ➤ Anterior: " . addslashes(Carbon::parse($anterior->created_at)->format('d M Y h:i:s A')) . "\n" . - " ➤ Actual: " . addslashes(Carbon::parse($registro->created_at)->format('d M Y h:i:s A')) . ""; + $diferencia = Carbon::parse($anterior->created_at)->diffInSeconds(Carbon::parse($registro->created_at)); + if ($diferencia < 20) { + //echo "Diferencia: {$diferencia} segundos
Vendedor ID: {$anterior->nombre_cliente}- {$anterior->created_at} - {$registro->created_at}

"; + $validar_actual = Log_general::where('historial_id', $registro->id) + ->where('tipo', 'compra') + ->exists(); // Corregido + $validar_anterior = Log_general::where('historial_id', $anterior->id) + ->where('tipo', 'compra') + ->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" . + "🆔 Historial ID activo: " . addslashes($anterior->id) . "\n" . + "👤 Saldo retornado: " . addslashes($registro->valor) . "\n" . + "👤 Usuario: " . addslashes($email) . "\n" . + "📅 Fechas:\n" . + " ➤ Anterior: " . addslashes(Carbon::parse($anterior->created_at)->format('d M Y h:i:s A')) . "\n" . + " ➤ Actual: " . addslashes(Carbon::parse($registro->created_at)->format('d M Y h:i:s A')) . ""; + + + + $this->enviarTelegram($mensaje); + + 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') . ' - Saldo retornado:' . $registro->valor, + ]); + } - 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').' - Saldo retornado:'.$registro->valor, - ]); } } - } } } @@ -181,11 +184,11 @@ class validacionCompra extends Command } } - public function validarSaldosNegativos($anterior,$actual) + public function validarSaldosNegativos($anterior, $actual) { $consultaLog = Log_general::whereBetween('created_at', [$anterior, $actual]) - ->where('detalle', 'LIKE', '%disponible: $-%') - ->get(); + ->where('detalle', 'LIKE', '%disponible: $-%') + ->get(); //dd($consultaLog); if (!$consultaLog->isEmpty()) { foreach ($consultaLog as $log) {