UNIT3D-Community-Edition icon indicating copy to clipboard operation
UNIT3D-Community-Edition copied to clipboard

[Request] Invite purchase time limit

Open Audionut opened this issue 7 months ago • 1 comments

The ability to place a time limit between invite purchases.

ChatGTP reckons a migration to update the database.

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddLastInviteExchangeToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->date('last_invite_exchange')->nullable()->after('invites');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn('last_invite_exchange');
        });
    }
}

Then it can be defined with the existing invite limitation:

case $bonExchange->invite:
    // Check if the user has reached the maximum number of unused invites
    if ($user->invites >= config('other.max_unused_user_invites', 1)) {
        return back()->withErrors('You already have the maximum amount of unused invites allowed per user.');
    }

    // Check if the user has already exchanged an invite this calendar month
    $lastExchange = $user->last_invite_exchange;
    $currentDate = now();
    $startOfMonth = $currentDate->copy()->startOfMonth();

    if ($lastExchange && $lastExchange->gte($startOfMonth)) {
        return back()->withErrors('You can only exchange an invite once per calendar month.');
    }

    // Update the last invite exchange date
    $user->last_invite_exchange = $currentDate;
    $user->save();

    // Proceed with the invite exchange logic
    // ...
    break;

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Audionut avatar Jul 19 '24 01:07 Audionut