This commit is contained in:
Lizandro Guarnizo
2025-04-14 18:08:49 -05:00
parent c83cd1a72f
commit d1c5dbc90e
7 changed files with 111 additions and 9 deletions
+14 -5
View File
@@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\Models\Historial_cuenta;
use App\Models\Historiale;
use App\Models\Log_general;
use App\Models\RegistroCompra;
use App\Models\Saldo;
use App\Models\User;
use Carbon\Carbon;
@@ -40,7 +41,6 @@ class validacionCompra extends Command
//$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');
$this->validarSaldosNegativos($hora_antes, $fecha_ahora);
$resultados = Historiale::select('vendedor_id')
@@ -66,7 +66,16 @@ class validacionCompra extends Command
$diferencia = Carbon::parse($anterior->created_at)->diffInSeconds(Carbon::parse($registro->created_at));
if ($diferencia < 10) {
$segundos_antes_anterior = Carbon::parse($anterior->created_at)->subSeconds(10);
$segundos_antes_registro = Carbon::parse($registro->created_at)->subSeconds(10);
$validaranterior = RegistroCompra::where('user_id', $anterior->vendedor_id)->whereBetween('created_at', [$segundos_antes_anterior, $anterior->created_at])->exists();
$validarregistro = RegistroCompra::where('user_id', $registro->vendedor_id)->whereBetween('created_at', [$segundos_antes_registro, $registro->created_at])->exists();
if ($diferencia < 10 && !$validaranterior && !$validarregistro ) {
//echo "Diferencia: {$diferencia} segundos<br>Vendedor ID: {$anterior->nombre_cliente}- {$anterior->created_at} - {$registro->created_at}<br><br>";
$validar_actual = Log_general::where('historial_id', $registro->id)
->where('tipo', 'compra')
@@ -105,7 +114,7 @@ class validacionCompra extends Command
'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 .'- Saldo actual: '.$vendedor->saldo->valor,
Carbon::parse($anterior->created_at)->format('d M Y h:i A') . ' - Saldo retornado:' . $registro->valor . '- Saldo actual: ' . $vendedor->saldo->valor,
]);
}
@@ -158,8 +167,8 @@ class validacionCompra extends Command
// Devolver saldo
$nuevo_saldo = $actualizar_saldo->saldo->valor + $historial_actual->valor;
Saldo::where('usuario_id', $usuario_anterior)->update(['valor' => $nuevo_saldo]);
// Cancelar historial actual
$historial_actual->estado = 'cancelado';
$historial_actual->save();
-3
View File
@@ -38,9 +38,6 @@ class Kernel extends ConsoleKernel
$schedule->command('tarea:validarCompra')->everyFiveMinutes();
$schedule->call(function () {
$fechaHoy = Carbon::now();
$fechaManana = $fechaHoy->copy()->addDay(); // Obtenemos la fecha de mañana sumando un día a la fecha actual
+13
View File
@@ -11,6 +11,7 @@ use App\Notifications\Vencimiento;
use Illuminate\Support\Facades\Crypt;
use App\Models\Promociones;
use App\Models\recarga;
use App\Models\RegistroCompra;
use App\Models\Role;
use App\Models\Saldo;
use App\Models\slider;
@@ -764,4 +765,16 @@ $consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cli
}
}
public function click_compra(Request $request) {
// Aquí puedes guardar, registrar o procesar la info
RegistroCompra::create([
'user_id' => auth()->id(),
'nombre' => $request->nombre,
'email' => $request->email,
'saldo' => $request->saldo,
]);
return response()->json(['success' => true]);
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class RegistroCompra extends Model
{
use HasFactory;
protected $fillable = ['user_id', 'nombre', 'email', 'saldo'];
public function user()
{
return $this->belongsTo(User::class);
}
}