reclamar premio

This commit is contained in:
Felipe
2024-03-06 12:03:57 -05:00
parent df7522c2a9
commit 3d1eac3801
6 changed files with 80 additions and 45 deletions
+33
View File
@@ -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'
]);
}
}
+1 -1
View File
@@ -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;
@@ -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');
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('notificaciones', function (Blueprint $table) {
$table->integer('premio')->nullable()->default(0)->after('todos');
});
}
public function down()
{
Schema::table('notificaciones', function (Blueprint $table) {
$table->dropColumn('premio');
});
}
};
+14 -5
View File
@@ -1,6 +1,5 @@
<div class="flex justify-center items-center" x-data="{ menuNotificaciones: @entangle('menuNotificaciones') }">
<div class="fill-[{{ App\Models\Configuracione::Orderby('id', 'desc')->first()->color_boton }}] relative cursor-pointer"
wire:click="$refresh" @click="menuNotificaciones=!menuNotificaciones">
<div class="fill-[{{ App\Models\Configuracione::Orderby('id', 'desc')->first()->color_boton }}] relative cursor-pointer" wire:click="$refresh" @click="menuNotificaciones=!menuNotificaciones">
@if ($numNoti != 0)
<span class="absolute top-0 left-0 bg-red-500 rounded-full w-5 h-5 flex justify-center items-center text-xs text-white">
{{ $numNoti > 9 ? '9+' : $numNoti }}
@@ -13,7 +12,7 @@
<div x-cloak x-show="menuNotificaciones" @click.outside="menuNotificaciones = false" class="absolute top-14 right-2 md:right-32 rounded-lg border overflow-y-auto border-[{{ App\Models\Configuracione::Orderby('id', 'desc')->first()->color_boton }}] bg-white w-72 md:w-96 h-96 z-50">
<ul class="p-4">
@foreach ($consulta as $item)
@forelse ($consulta as $item)
<li class="px-2 py-1 mb-2 border border-gray-300 rounded-lg relative" wire:loading.class="opacity-50 cursor-wait">
<h4 class="font-bold text-base text-[{{ App\Models\Configuracione::Orderby('id', 'desc')->first()->color_boton }}]">
{{ $item->titulo }}
@@ -21,7 +20,15 @@
<p class="text-sm">
{{ $item->descripcion }}
</p>
@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)
<p class="text-sm py-2">
[${{ number_format($item->premio) }}] 🏆💵
</p>
<x-primary-button class="my-1" wire:click="reclamarPremio({{ $item->id }})" wire:loading.attr="disabled" wire:target="reclamarPremio">
Reclamar premio
</x-primary-button>
@endif
@if (!$item->todos || Auth::user()->rol->nombre == 'administrador' || Auth::user()->rol->nombre == 'super' || Auth::user()->rol->nombre == 'editor' || $item->premio == 0)
<span class="text-red-500 font-semibold absolute top-0 right-2 cursor-pointer select-none" wire:click="deleteNotificacion({{ $item->id }})" wire:loading.remove>
x
</span>
@@ -30,7 +37,9 @@
</span>
@endif
</li>
@endforeach
@empty
<p class="text-center text-gray-500 py-2">No tienes notificaciones</p>
@endforelse
</ul>
</div>
</div>
@@ -802,36 +802,18 @@
@if (!empty($h->tarifa_id))
<td class="hidden md:inline-table w-[1rem]">
<button
class="flex m-auto gap-2 items-center bg-[#B221FD] text-white px-4 py-1 rounded-lg"
wire:click="enviarNotificacion({{ $h->id }})">Notificar
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svgjs="http://svgjs.com/svgjs" class="w-4" x="0" y="0"
viewBox="0 0 511.996 511.996"
style="enable-background:new 0 0 512 512" xml:space="preserve"
class="">
<path
d="m511.996 127.512v-8.079c0-30.419-24.748-55.166-55.166-55.166h-401.664c-30.419 0-55.166 24.747-55.166 55.166v8.079.059 264.995c0 30.417 24.747 55.163 55.166 55.163h401.667c30.417 0 55.163-24.746 55.163-55.163v-264.995c0-.019 0-.039 0-.059zm-456.83-33.245h401.664c13.876 0 25.166 11.289 25.166 25.166v.007l-200.896 133.93c-13.372 8.915-36.83 8.914-50.2.001l-200.9-133.932v-.007c0-13.876 11.289-25.165 25.166-25.165zm401.667 323.462h-401.667c-13.877 0-25.166-11.288-25.166-25.163v-237.072l184.259 122.838c11.704 7.803 26.719 11.703 41.74 11.703 15.017 0 30.039-3.901 41.742-11.703l184.256-122.838v237.072c-.001 13.875-11.289 25.163-25.164 25.163z"
fill="#ffffff" data-original="#000000" class="">
<button class="flex m-auto gap-2 items-center bg-[#B221FD] text-white px-4 py-1 rounded-lg" wire:click="enviarNotificacion({{ $h->id }})">Notificar
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" class="w-4" x="0" y="0" viewBox="0 0 511.996 511.996" style="enable-background:new 0 0 512 512" xml:space="preserve" class="">
<path d="m511.996 127.512v-8.079c0-30.419-24.748-55.166-55.166-55.166h-401.664c-30.419 0-55.166 24.747-55.166 55.166v8.079.059 264.995c0 30.417 24.747 55.163 55.166 55.163h401.667c30.417 0 55.163-24.746 55.163-55.163v-264.995c0-.019 0-.039 0-.059zm-456.83-33.245h401.664c13.876 0 25.166 11.289 25.166 25.166v.007l-200.896 133.93c-13.372 8.915-36.83 8.914-50.2.001l-200.9-133.932v-.007c0-13.876 11.289-25.165 25.166-25.165zm401.667 323.462h-401.667c-13.877 0-25.166-11.288-25.166-25.163v-237.072l184.259 122.838c11.704 7.803 26.719 11.703 41.74 11.703 15.017 0 30.039-3.901 41.742-11.703l184.256-122.838v237.072c-.001 13.875-11.289 25.163-25.164 25.163z" fill="#ffffff" data-original="#000000" class="">
</path>
</svg>
</button>
</td>
@elseif(!empty($h->promocion_id))
<td class="hidden md:inline-table w-[1rem]">
<button
class="hidden md:flex m-auto gap-2 items-center bg-[#B221FD] text-white px-4 py-1 rounded-lg"
wire:click="enviarNotificacionPromo({{ $h->id }})">Notificar
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svgjs="http://svgjs.com/svgjs" class="w-4" x="0" y="0"
viewBox="0 0 511.996 511.996"
style="enable-background:new 0 0 512 512" xml:space="preserve"
class="">
<path
d="m511.996 127.512v-8.079c0-30.419-24.748-55.166-55.166-55.166h-401.664c-30.419 0-55.166 24.747-55.166 55.166v8.079.059 264.995c0 30.417 24.747 55.163 55.166 55.163h401.667c30.417 0 55.163-24.746 55.163-55.163v-264.995c0-.019 0-.039 0-.059zm-456.83-33.245h401.664c13.876 0 25.166 11.289 25.166 25.166v.007l-200.896 133.93c-13.372 8.915-36.83 8.914-50.2.001l-200.9-133.932v-.007c0-13.876 11.289-25.165 25.166-25.165zm401.667 323.462h-401.667c-13.877 0-25.166-11.288-25.166-25.163v-237.072l184.259 122.838c11.704 7.803 26.719 11.703 41.74 11.703 15.017 0 30.039-3.901 41.742-11.703l184.256-122.838v237.072c-.001 13.875-11.289 25.163-25.164 25.163z"
fill="#ffffff" data-original="#000000" class="">
<button class="hidden md:flex m-auto gap-2 items-center bg-[#B221FD] text-white px-4 py-1 rounded-lg" wire:click="enviarNotificacionPromo({{ $h->id }})">Notificar
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" class="w-4" x="0" y="0" viewBox="0 0 511.996 511.996" style="enable-background:new 0 0 512 512" xml:space="preserve" class="">
<path d="m511.996 127.512v-8.079c0-30.419-24.748-55.166-55.166-55.166h-401.664c-30.419 0-55.166 24.747-55.166 55.166v8.079.059 264.995c0 30.417 24.747 55.163 55.166 55.163h401.667c30.417 0 55.163-24.746 55.163-55.163v-264.995c0-.019 0-.039 0-.059zm-456.83-33.245h401.664c13.876 0 25.166 11.289 25.166 25.166v.007l-200.896 133.93c-13.372 8.915-36.83 8.914-50.2.001l-200.9-133.932v-.007c0-13.876 11.289-25.165 25.166-25.165zm401.667 323.462h-401.667c-13.877 0-25.166-11.288-25.166-25.163v-237.072l184.259 122.838c11.704 7.803 26.719 11.703 41.74 11.703 15.017 0 30.039-3.901 41.742-11.703l184.256-122.838v237.072c-.001 13.875-11.289 25.163-25.164 25.163z" fill="#ffffff" data-original="#000000" class="">
</path>
</svg>
</button>
@@ -842,9 +824,8 @@
</tbody>
</table>
<span class="text-center mx-auto ">
<button wire:click="cerrar" type="button"
class="mx-auto inline-flex justify-center w-full w-24 mx-auto rounded-md border border-transparent px-4 py-2 text-white bg-[#585858] hover:bg-[#3a3a3a] ease-in-out sm-text-sm sm-leading-5">Cerrar</button>
<span class="text-center mx-auto">
<button wire:click="cerrar" type="button" class="mx-auto inline-flex justify-center w-full w-24 mx-auto rounded-md border border-transparent px-4 py-2 text-white bg-[#585858] hover:bg-[#3a3a3a] ease-in-out sm-text-sm sm-leading-5">Cerrar</button>
</span>
</div>
@endif