diff --git a/app/Models/EinundzwanzigPleb.php b/app/Models/EinundzwanzigPleb.php index dff4120..d475a6b 100644 --- a/app/Models/EinundzwanzigPleb.php +++ b/app/Models/EinundzwanzigPleb.php @@ -22,4 +22,9 @@ class EinundzwanzigPleb extends Model return $this->hasOne(Profile::class, 'pubkey', 'pubkey'); } + public function paymentEvents() + { + return $this->hasMany(PaymentEvent::class); + } + } diff --git a/app/Models/PaymentEvent.php b/app/Models/PaymentEvent.php new file mode 100644 index 0000000..700fd71 --- /dev/null +++ b/app/Models/PaymentEvent.php @@ -0,0 +1,10 @@ +id(); + $table->unsignedBigInteger('einundzwanzig_pleb_id'); + $table->foreign('einundzwanzig_pleb_id')->references('id')->on('einundzwanzig_plebs')->cascadeOnDelete(); + $table->unsignedInteger('year'); + $table->unsignedInteger('amount'); + $table->string('event_id', 255 * 2)->nullable(); + $table->timestamps(); + }); + + Schema::table('einundzwanzig_plebs', function (Blueprint $table) { + $table->dropColumn('payment_event'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('payment_events'); + } +}; diff --git a/resources/views/pages/association/profile.blade.php b/resources/views/pages/association/profile.blade.php index 3ee830a..9aa248e 100644 --- a/resources/views/pages/association/profile.blade.php +++ b/resources/views/pages/association/profile.blade.php @@ -52,11 +52,16 @@ updated([ on([ 'nostrLoggedIn' => function ($pubkey) { $this->currentPubkey = $pubkey; - $this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first(); + $this->currentPleb = \App\Models\EinundzwanzigPleb::query() + ->with([ + 'paymentEvents' => fn($query) + => $query->where('year', date('Y')), + ]) + ->where('pubkey', $pubkey)->first(); if ($this->currentPleb->association_status === \App\Enums\AssociationStatus::ACTIVE) { $this->amountToPay = 21; } - if (!$this->currentPleb->payment_event) { + if ($this->currentPleb->paymentEvents->count() < 1) { $this->createPaymentEvent(); } $this->loadEvents(); @@ -90,16 +95,17 @@ $searchPaymentEvent = function () { $response = $request->send(); if (count($response[config('services.relay')]) > 0) { - $this->payments = collect($response[config('services.relay')])->map(fn($event) - => [ - 'id' => $event->event->id, - 'kind' => $event->event->kind, - 'content' => $event->event->content, - 'pubkey' => $event->event->pubkey, - 'tags' => $event->event->tags, - 'created_at' => $event->event->created_at, - ]) - ->filter(fn($payment) => collect($payment['tags'])->firstWhere('0', 'p')[1] === $this->currentPubkey) + $this->payments = collect($response[config('services.relay')]) + ->map(fn($event) + => [ + 'id' => $event->event->id, + 'kind' => $event->event->kind, + 'content' => $event->event->content, + 'pubkey' => $event->event->pubkey, + 'tags' => $event->event->tags, + 'created_at' => $event->event->created_at, + ]) + ->filter(fn($payment) => collect($payment['tags'])->firstWhere('0', 'e')[1] === $this->currentPleb->paymentEvents->first()->event_id) ->values() ->toArray(); @@ -173,8 +179,10 @@ $createPaymentEvent = function () { $relay->setMessage($eventMessage); $result = $relay->send(); - $this->currentPleb->update([ - 'payment_event' => $result->eventId, + $this->currentPleb->paymentEvents()->create([ + 'year' => date('Y'), + 'event_id' => $result->eventId, + 'amount' => $this->amountToPay, ]); }; @@ -233,7 +241,7 @@ $loadEvents = function () {
+ class="flex flex-nowrap overflow-x-scroll no-scrollbar md:block md:overflow-auto px-3 py-6 border-b md:border-b-0 md:border-r border-gray-200 dark:border-gray-700/60 min-w-60 md:space-y-3">
@@ -245,7 +253,7 @@ $loadEvents = function () { href="#0"> Status + class="text-sm font-medium text-orange-500 dark:text-orange-400">Status {{--
  • @@ -304,20 +312,20 @@ $loadEvents = function () {

    + class="tw-48 sm:w-full truncate text-sm text-gray-500 dark:text-gray-400" + x-text="$store.nostr.user.nip05">
  • @if($currentPubkey)
    + class="inline-flex min-w-80 px-4 py-2 rounded-lg text-sm bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700/60 text-gray-600 dark:text-gray-100">
    + d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zM7 11.4L3.6 8 5 6.6l2 2 4-4L12.4 6 7 11.4z">
    Profil in der Datenbank vorhanden. Bewerbung kann erfolgen.
    @@ -335,9 +343,9 @@ $loadEvents = function () {
    + corner="Beschreibe deine Motivation, passives Mitglied zu werden." + label="Warum möchtest du passives Mitglied werden?" + wire:model="form.reason"/>
    @@ -358,10 +366,10 @@ $loadEvents = function () {
    + corner="Woher kennen wir dich? Was möchtest du einbringen?" + description="Wir bitten dich mindestens von 3 aktiven Mitgliedern auf Nostr gefolgt zu werden." + label="Warum möchtest du aktives Mitglied werden?" + wire:model="form.reason"/>
    @@ -377,13 +385,13 @@ $loadEvents = function () {
    @if($currentPubkey && $currentPleb->application_for)
    + class="inline-flex flex-col w-full max-w-lg px-4 py-2 rounded-lg text-sm bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700/60 text-gray-600 dark:text-gray-400">
    + d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 12c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1zm1-3H7V4h2v5z">
    @@ -400,13 +408,13 @@ $loadEvents = function () {
    @if($currentPleb && $currentPleb->association_status->value > 1)
    + class="inline-flex flex-col w-full max-w-lg px-4 py-2 rounded-lg text-sm bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700/60 text-gray-600 dark:text-gray-400">
    + d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 12c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1zm1-3H7V4h2v5z">
    @@ -423,17 +431,17 @@ $loadEvents = function () {
    @if($currentPleb && $currentPleb->association_status->value > 1)
    + class="inline-flex flex-col w-full px-4 py-2 rounded-lg text-sm bg-white dark:bg-gray-800 shadow-sm border border-gray-200 dark:border-gray-700/60 text-gray-600 dark:text-gray-400">
    + d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 12c-.6 0-1-.4-1-1s.4-1 1-1 1 .4 1 1-.4 1-1 1zm1-3H7V4h2v5z">
    + class="font-medium text-gray-800 dark:text-gray-100 mb-1 space-y-2">

    Nostr Event für die Zahlung des Mitgliedsbeitrags: {{ $currentPleb->payment_event }}

    @@ -443,8 +451,8 @@ $loadEvents = function () { @if(!$invoice && !$currentYearIsPaid)
    @else @if($currentYearIsPaid)