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 @@
{{ $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) }}] 🏆💵 +
+No tienes notificaciones
+ @endforelse