- Hora exacta: tolerancia 0 (timestamp comprobante = timestamp email) - Remitente bloquea: si el email trae el nombre del remitente y no coincide, rechaza - Nuevo paso antes de mostrar datos bancarios: bot pide nombre completo del titular - Nombres aceptados se guardan en solicitudes_recarga.nombre_remitente - Próxima recarga: muestra botones con nombres anteriores confirmados o ingresa uno nuevo - Funciona igual en Telegram y web chat Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class SolicitudRecarga extends Model
|
|
{
|
|
protected $table = 'solicitudes_recarga';
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = ['user_id', 'monto', 'canal', 'estado', 'nombre_remitente'];
|
|
|
|
protected $casts = ['created_at' => 'datetime'];
|
|
|
|
public static function crear(int $userId, int $monto, string $canal, ?string $nombreRemitente = null): static
|
|
{
|
|
static::where('user_id', $userId)
|
|
->where('estado', 'pendiente')
|
|
->update(['estado' => 'expirada']);
|
|
|
|
return static::create([
|
|
'user_id' => $userId,
|
|
'monto' => $monto,
|
|
'canal' => $canal,
|
|
'estado' => 'pendiente',
|
|
'nombre_remitente' => $nombreRemitente,
|
|
]);
|
|
}
|
|
|
|
public static function pendiente(int $userId): ?static
|
|
{
|
|
return static::where('user_id', $userId)
|
|
->where('estado', 'pendiente')
|
|
->where('created_at', '>=', now()->subMinutes(30))
|
|
->latest('id')
|
|
->first();
|
|
}
|
|
|
|
public static function nombresPrevios(int $userId): array
|
|
{
|
|
return static::where('user_id', $userId)
|
|
->where('estado', 'confirmada')
|
|
->whereNotNull('nombre_remitente')
|
|
->orderByDesc('id')
|
|
->limit(10)
|
|
->pluck('nombre_remitente')
|
|
->unique()
|
|
->values()
|
|
->toArray();
|
|
}
|
|
|
|
public function confirmar(): void
|
|
{
|
|
$this->update(['estado' => 'confirmada']);
|
|
}
|
|
}
|