update
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('registros_compras', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
@@ -320,9 +320,38 @@
|
||||
@if (auth()->user()->rol->nombre != 'editor')
|
||||
<span>
|
||||
<button wire:click="comprar" type="button" wire:loading.attr="disabled"
|
||||
@if ($cantidad_tarjetaPlan <= (int) $disponibles && $total <= auth()->user()->saldo->valor) class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 sm:mb-[0] mb-2 text-white bg-[#B221FD] hover:bg-[#7a02b8] focus:shadow-outline-green sm-text-sm sm-leading-5" @else disabled class="cursor-no-drop inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 sm:mb-[0] mb-2 text-white bg-gray-200 hover:bg-gray-200 focus:shadow-outline-green sm-text-sm sm-leading-5" @endif>
|
||||
@if ($cantidad_tarjetaPlan <= (int) $disponibles && $total <= auth()->user()->saldo->valor) onclick="enviarInfoUsuario({
|
||||
nombre: '{{ auth()->user()->name }}',
|
||||
email: '{{ auth()->user()->email }}',
|
||||
saldo: '{{ auth()->user()->saldo->valor }}'
|
||||
})"
|
||||
class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 sm:mb-[0] mb-2 text-white bg-[#B221FD] hover:bg-[#7a02b8] focus:shadow-outline-green sm-text-sm sm-leading-5"
|
||||
@else
|
||||
disabled
|
||||
class="cursor-no-drop inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 sm:mb-[0] mb-2 text-white bg-gray-200 hover:bg-gray-200 focus:shadow-outline-green sm-text-sm sm-leading-5" @endif>
|
||||
Comprar
|
||||
</button>
|
||||
|
||||
<script>
|
||||
function enviarInfoUsuario(usuario) {
|
||||
fetch('/registrar-accion-compra', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}' // Importante para proteger la petición
|
||||
},
|
||||
body: JSON.stringify(usuario)
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Respuesta del servidor:', data);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error al enviar info:', error);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
</span>
|
||||
@endif
|
||||
<span>
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user