From 3d1eac38013e570767a32767b701ca68deb4588a Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 6 Mar 2024 12:03:57 -0500 Subject: [PATCH] reclamar premio --- app/Http/Livewire/Bell.php | 33 +++++++++++++++++ app/Http/Livewire/ShowUsuarios.php | 2 +- ..._23_101443_create_notificaciones_table.php | 14 ++------ ...732_add_premio_to_notificaciones_table.php | 22 ++++++++++++ resources/views/livewire/bell.blade.php | 19 +++++++--- .../views/livewire/show-clientes.blade.php | 35 +++++-------------- 6 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 database/migrations/2024_03_06_103732_add_premio_to_notificaciones_table.php diff --git a/app/Http/Livewire/Bell.php b/app/Http/Livewire/Bell.php index 5137e30..f44ecb1 100755 --- a/app/Http/Livewire/Bell.php +++ b/app/Http/Livewire/Bell.php @@ -3,13 +3,18 @@ namespace App\Http\Livewire; use App\Models\Notificacion; +use App\Models\Saldo; use Illuminate\Support\Facades\Auth; use Livewire\Component; +use Jantinnerezo\LivewireAlert\LivewireAlert; class Bell extends Component { + use LivewireAlert; + public $numNoti = 0; public $menuNotificaciones = false; + public $reclamandoPremio = false; public function render() { @@ -35,4 +40,32 @@ class Bell extends Component $notificacion->update(['estado' => false]); } } + + public function reclamarPremio($id) + { + if ($this->reclamandoPremio) { + return; + } + + $this->reclamandoPremio = true; + + $notificacion = Notificacion::find($id); + + $consulta_saldo = Saldo::where('usuario_id', Auth::user()->id)->first(); + + if ($consulta_saldo) { + $consulta_saldo->update([ + 'valor' => $consulta_saldo->valor + $notificacion->premio + ]); + if ($notificacion) { + $notificacion->update(['estado' => false]); + } + } + + $this->reclamandoPremio = false; + + $this->alert('success', 'Haz reclamado el premio correctamente', [ + 'position' => 'top' + ]); + } } diff --git a/app/Http/Livewire/ShowUsuarios.php b/app/Http/Livewire/ShowUsuarios.php index 7313b2f..69f1396 100755 --- a/app/Http/Livewire/ShowUsuarios.php +++ b/app/Http/Livewire/ShowUsuarios.php @@ -209,7 +209,7 @@ class ShowUsuarios extends Component $recarga = new recarga; $recarga->payment_method_id = 'manual'; - $recarga->status = 'Aprovada'; + $recarga->status = 'approved'; $recarga->usuario_id = $this->user_saldo; $recarga->saldo_id = $this->consulta_saldo->id; $recarga->monto = $this->valor_recargar; diff --git a/database/migrations/2023_10_23_101443_create_notificaciones_table.php b/database/migrations/2023_10_23_101443_create_notificaciones_table.php index 1768efe..6d9f19e 100755 --- a/database/migrations/2023_10_23_101443_create_notificaciones_table.php +++ b/database/migrations/2023_10_23_101443_create_notificaciones_table.php @@ -6,11 +6,6 @@ use Illuminate\Support\Facades\Schema; return new class extends Migration { - /** - * Run the migrations. - * - * @return void - */ public function up() { Schema::create('notificaciones', function (Blueprint $table) { @@ -20,7 +15,7 @@ return new class extends Migration $table->string('titulo')->nullable(); $table->text('descripcion')->nullable(); $table->boolean('estado')->default(true); - $table->boolean('todos')->default(false); + $table->boolean('todos')->default(false); $table->foreign('remitente_id') ->references('id') @@ -33,16 +28,11 @@ return new class extends Migration ->on('users') ->onDelete('cascade') ->onUpdate('cascade'); - + $table->timestamps(); }); } - /** - * Reverse the migrations. - * - * @return void - */ public function down() { Schema::dropIfExists('notificaciones'); diff --git a/database/migrations/2024_03_06_103732_add_premio_to_notificaciones_table.php b/database/migrations/2024_03_06_103732_add_premio_to_notificaciones_table.php new file mode 100644 index 0000000..97d7546 --- /dev/null +++ b/database/migrations/2024_03_06_103732_add_premio_to_notificaciones_table.php @@ -0,0 +1,22 @@ +integer('premio')->nullable()->default(0)->after('todos'); + }); + } + + public function down() + { + Schema::table('notificaciones', function (Blueprint $table) { + $table->dropColumn('premio'); + }); + } +}; diff --git a/resources/views/livewire/bell.blade.php b/resources/views/livewire/bell.blade.php index d839698..e219851 100755 --- a/resources/views/livewire/bell.blade.php +++ b/resources/views/livewire/bell.blade.php @@ -1,6 +1,5 @@
-
+
@if ($numNoti != 0) {{ $numNoti > 9 ? '9+' : $numNoti }} @@ -13,7 +12,7 @@
    - @foreach ($consulta as $item) + @forelse ($consulta as $item)
  • {{ $item->titulo }} @@ -21,7 +20,15 @@

    {{ $item->descripcion }}

    - @if (!$item->todos || Auth::user()->rol->nombre == 'administrador' || Auth::user()->rol->nombre == 'super' || Auth::user()->rol->nombre == 'editor') + @if ($item->premio != null && $item->premio != 0) +

    + [${{ number_format($item->premio) }}] 🏆💵 +

    + + Reclamar premio + + @endif + @if (!$item->todos || Auth::user()->rol->nombre == 'administrador' || Auth::user()->rol->nombre == 'super' || Auth::user()->rol->nombre == 'editor' || $item->premio == 0) x @@ -30,7 +37,9 @@ @endif

  • - @endforeach + @empty +

    No tienes notificaciones

    + @endforelse
diff --git a/resources/views/livewire/show-clientes.blade.php b/resources/views/livewire/show-clientes.blade.php index 6ca588b..ff92dbf 100755 --- a/resources/views/livewire/show-clientes.blade.php +++ b/resources/views/livewire/show-clientes.blade.php @@ -802,36 +802,18 @@ @if (!empty($h->tarifa_id)) - + +
@endif