From d1c5dbc90e95ce6723a8ef05479d801575579631 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 14 Apr 2025 18:08:49 -0500 Subject: [PATCH] update --- app/Console/Commands/validacionCompra.php | 19 +++++++--- app/Console/Kernel.php | 3 -- app/Http/Controllers/MenuController.php | 13 +++++++ app/Models/RegistroCompra.php | 18 ++++++++++ ..._174441_create_registros_compras_table.php | 35 +++++++++++++++++++ .../views/livewire/show-servicios.blade.php | 31 +++++++++++++++- routes/web.php | 1 + 7 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 app/Models/RegistroCompra.php create mode 100644 database/migrations/2025_04_14_174441_create_registros_compras_table.php diff --git a/app/Console/Commands/validacionCompra.php b/app/Console/Commands/validacionCompra.php index 8982ace..e0fb6d0 100644 --- a/app/Console/Commands/validacionCompra.php +++ b/app/Console/Commands/validacionCompra.php @@ -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
Vendedor ID: {$anterior->nombre_cliente}- {$anterior->created_at} - {$registro->created_at}

"; $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(); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 9b13776..3ece9a7 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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 diff --git a/app/Http/Controllers/MenuController.php b/app/Http/Controllers/MenuController.php index c27bdba..0a87a7c 100755 --- a/app/Http/Controllers/MenuController.php +++ b/app/Http/Controllers/MenuController.php @@ -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]); +} } diff --git a/app/Models/RegistroCompra.php b/app/Models/RegistroCompra.php new file mode 100644 index 0000000..cb33022 --- /dev/null +++ b/app/Models/RegistroCompra.php @@ -0,0 +1,18 @@ +belongsTo(User::class); + } +} diff --git a/database/migrations/2025_04_14_174441_create_registros_compras_table.php b/database/migrations/2025_04_14_174441_create_registros_compras_table.php new file mode 100644 index 0000000..febe3a0 --- /dev/null +++ b/database/migrations/2025_04_14_174441_create_registros_compras_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('user_id'); + $table->string('nombre'); + $table->string('email'); + $table->decimal('saldo', 15, 2); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('registros_compras'); + } +}; diff --git a/resources/views/livewire/show-servicios.blade.php b/resources/views/livewire/show-servicios.blade.php index 65b5f2a..8c468a9 100755 --- a/resources/views/livewire/show-servicios.blade.php +++ b/resources/views/livewire/show-servicios.blade.php @@ -320,9 +320,38 @@ @if (auth()->user()->rol->nombre != 'editor') + + + @endif diff --git a/routes/web.php b/routes/web.php index d71084f..c1eca99 100755 --- a/routes/web.php +++ b/routes/web.php @@ -66,6 +66,7 @@ Route::middleware(["auth", "solo_usuario_administrador"])->group(function () { Route::get('/mantenimiento', [MenuController::class, 'mantenimiento'])->name('mantenimiento'); }); +Route::post('/registrar-accion-compra', [MenuController::class, 'click_compra'])->name('click_compra');