Skip to content

Commit

Permalink
Merge branch 'develop' into api-updating-entity-removes-images-uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis authored Oct 10, 2023
2 parents 7df8051 + bde7493 commit 7ecea6d
Show file tree
Hide file tree
Showing 90 changed files with 271 additions and 1,772 deletions.
7 changes: 6 additions & 1 deletion app/Http/Controllers/Settings/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\SubscriptionCancellation;
use Carbon\Carbon;
use App\Services\SubscriptionService;
use App\Services\SubscriptionUpgradeService;
use App\User;
use Exception;
use Illuminate\Http\Request;
Expand All @@ -19,14 +20,16 @@
class SubscriptionController extends Controller
{
protected SubscriptionService $subscription;
protected SubscriptionUpgradeService $subscriptionUpgrade;

/**
* SubscriptionController constructor.
*/
public function __construct(SubscriptionService $service)
public function __construct(SubscriptionService $service, SubscriptionUpgradeService $subscriptionUpgradeService)
{
$this->middleware(['auth', 'identity', 'subscriptions']);
$this->subscription = $service;
$this->subscriptionUpgrade = $subscriptionUpgradeService;
}

/**
Expand Down Expand Up @@ -94,6 +97,7 @@ public function change(Request $request)
if ($user->hasPayPal()) {
$limited = true;
}
$upgrade = $this->subscriptionUpgrade->user($user)->upgradePrice($period, $tier);

return view('settings.subscription.change', compact(
'tier',
Expand All @@ -103,6 +107,7 @@ public function change(Request $request)
'intent',
'cancel',
'user',
'upgrade',
'isDowngrading',
'hasPromo',
'limited',
Expand Down
2 changes: 1 addition & 1 deletion app/Services/PayPalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function process(string $pledge): mixed
$oldPrice = "110.00";
}
// @phpstan-ignore-next-line
$price = floatval($price) - ($oldPrice + ((floatval($price) / 365) * $this->user->subscriptions()->first()->created_at->diffInDays(Carbon::now())));
$price = floatval($price) - ($oldPrice + ((floatval($price) / 365) * $this->user->subscriptions()->first()->updated_at->diffInDays(Carbon::now())));
// @phpstan-ignore-next-line
$price = str(ceil($price)) . '.00';
}
Expand Down
84 changes: 84 additions & 0 deletions app/Services/SubscriptionUpgradeService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Services;

use App\Traits\UserAware;
use Carbon\Carbon;

class SubscriptionUpgradeService
{
use UserAware;

public function upgradePrice(string $period, string $tier): string
{
$plans = [
config('subscription.owlbear.eur.yearly'),
config('subscription.owlbear.usd.yearly'),
config('subscription.wyvern.eur.yearly'),
config('subscription.wyvern.usd.yearly'),
config('subscription.elemental.eur.yearly'),
config('subscription.elemental.usd.yearly'),
];

$oldPrice = '';
$currency = "US$ ";
$monthly = true;
if ($this->user->billedInEur()) {
$currency = "";
}

$price = "55.00";
if ($tier === 'Wyvern') {
$price = "110.00";
if ($period == 'monthly') {
$price = "10.00";
}
} elseif ($tier === 'Elemental') {
$price = "275.00";
if ($period == 'monthly') {
$price = "25.00";
}
}

if (!$this->user->isSubscriber()) {
return $price;
}
// @phpstan-ignore-next-line
if (in_array($this->user->subscriptions->first()->stripe_price, $plans) || $this->user->hasPayPal()) {
$monthly = false;
}
if ($this->user->isElemental()) {
if ($monthly) {
$oldPrice = "25.00";
} else {
return '';
}
} elseif ($this->user->isOwlbear()) {
if ($monthly) {
$oldPrice = "5.00";
} else {
$oldPrice = "55.00";
}

} elseif ($this->user->isWyvern()) {
if ($monthly) {
$oldPrice = "10.00";
} else {
$oldPrice = "110.00";
}
}
if ($period == 'yearly') {
// @phpstan-ignore-next-line
$price = floatval($price) - ($oldPrice + ((floatval($price) / 365) * $this->user->subscriptions()->first()->updated_at->diffInDays(Carbon::now())));
} elseif ($monthly && $period == 'monthly') {
// @phpstan-ignore-next-line
$price = floatval($price) - ($oldPrice + ((floatval($price) / 31) * $this->user->subscriptions()->first()->updated_at->diffInDays(Carbon::now())));
}

// @phpstan-ignore-next-line
$price = $currency . str(ceil($price)) . '.00';


return $price;
}
}
1 change: 0 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ public function isFrauding(): bool
} elseif ($this->campaigns()->count() === 1) {
$campaign = $this->campaigns()->first();
// Only the 4 starting entities
// @//phpstan-ignore-next-line
if ($campaign->entities()->withInvisible()->count() === 4) {
return true;
}
Expand Down
23 changes: 18 additions & 5 deletions database/migrations/2017_10_27_090105_create_campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function up()
$table->string('export_path')->nullable();
$table->date('export_date')->nullable();

$table->string('visibility', 7)->default('private');
$table->unsignedTinyInteger('visibility_id')->default(\App\Models\Campaign::VISIBILITY_PRIVATE);
$table->boolean('is_featured')->default(false);
$table->boolean('entity_visibility')->default(false);
$table->unsignedInteger('visible_entity_count')->default(0);
Expand All @@ -45,20 +45,33 @@ public function up()

$table->unsignedTinyInteger('boost_count')->nullable();

$table->unsignedInteger('created_by')->nullable();
$table->unsignedInteger('updated_by')->nullable();

$table->dateTime('featured_until')->nullable();
$table->text('featured_reason')->nullable();

$table->unsignedInteger('follower')->default(0);

$table->boolean('is_hidden')->default(0);

$table->timestamps();

$table->index(['visibility', 'is_featured', 'visible_entity_count']);
$table->index(['visibility_id', 'is_featured', 'visible_entity_count', 'featured_until', 'is_hidden'], 'campaigns_idx');
$table->index('follower');

$table->foreign('created_by')->references('id')->on('users')->nullOnDelete();
$table->foreign('updated_by')->references('id')->on('users')->nullOnDelete();
});

Schema::create('campaign_user', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->integer('campaign_id')->unsigned();
$table->string('role', 6);
$table->timestamps();

$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('campaign_id')->references('id')->on('campaigns')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
$table->foreign('campaign_id')->references('id')->on('campaigns')->cascadeOnDelete();
});
}

Expand Down
4 changes: 3 additions & 1 deletion database/migrations/2017_10_27_091125_create_characters.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public function up()

$table->timestamps();

// Privacy
$table->boolean('is_private')->default(false);
$table->boolean('is_personality_pinned')->default(false);
$table->boolean('is_appearance_pinned')->default(false);

$table->index(['is_private']);

$table->boolean('is_personality_visible')->default(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateVisibilitiesTable extends Migration
class CreateRealVisibilitiesTable extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,6 +13,9 @@ class CreateVisibilitiesTable extends Migration
*/
public function up()
{
if(Schema::hasTable('visibilities')) {
return;
}
Schema::create('visibilities', function (Blueprint $table) {
$table->id();
$table->string('code', 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEntitiesTable extends Migration
class CreateRealEntitiesTable extends Migration
{
/**
* Run the migrations.
Expand All @@ -13,10 +13,12 @@ class CreateEntitiesTable extends Migration
*/
public function up()
{
if (Schema::hasTable('entities')) {
return;
}
Schema::create('entities', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('type_id')->nullable();
$table->string('type', 20)->notNull();
$table->string('name')->notNull();
$table->boolean('is_private')->default(0);
$table->integer('entity_id')->unsigned()->notNull();
Expand All @@ -31,11 +33,25 @@ public function up()
$table->unsignedSmallInteger('focus_x')->nullable();
$table->unsignedSmallInteger('focus_y')->nullable();

$table->unsignedInteger('created_by')->nullable();
$table->unsignedInteger('updated_by')->nullable();
$table->unsignedInteger('deleted_by')->nullable();


$table->timestamps();

// Foreign
$table->foreign('campaign_id')->references('id')->on('campaigns')->onDelete('cascade');
$table->foreign('campaign_id')
->references('id')->on('campaigns')
->cascadeOnDelete();

$table->foreign('created_by')
->references('id')->on('users')
->nullOnDelete();

$table->foreign('updated_by')
->references('id')->on('users')
->nullOnDelete();

$table->index(['type', 'name', 'is_private', 'is_template']);
$table->index('updated_at');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function up()
$table->string('image', 255)->nullable();
$table->date('date')->nullable();
$table->unsignedInteger('campaign_id')->notNull();
$table->unsignedInteger('character_id')->nullable();
$table->unsignedInteger('author_id')->nullable();
$table->unsignedInteger('location_id')->nullable();

$table->unsignedInteger('_lft')->default(0);
Expand All @@ -41,7 +41,7 @@ public function up()

// Foreign
$table->foreign('campaign_id')->references('id')->on('campaigns')->cascadeOnDelete();
$table->foreign('character_id')->references('id')->on('characters')->nullOnDelete();
$table->foreign('author_id')->references('id')->on('entities')->nullOnDelete();
$table->foreign('location_id')->references('id')->on('locations')->nullOnDelete();
$table->foreign('journal_id')->references('id')->on('journals')->nullOnDelete();

Expand Down
14 changes: 7 additions & 7 deletions database/migrations/2017_10_30_160311_create_item_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ class CreateItemTable extends Migration
*/
public function up()
{
Schema::dropIfExists('items');
Schema::create('items', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->notNull();
$table->string('slug');
$table->string('type')->nullable();
$table->string('image', 255)->nullable();
$table->date('date')->nullable();
$table->integer('campaign_id')->unsigned()->notNull();
$table->integer('character_id')->unsigned()->nullable();
$table->integer('location_id')->unsigned()->nullable();
$table->unsignedInteger('campaign_id')->notNull();
$table->unsignedInteger('item_id')->nullable();
$table->unsignedInteger('character_id')->nullable();
$table->unsignedInteger('location_id')->nullable();

// Overview
$table->longText('entry')->nullable();

$table->string('price')->nullable();
$table->string('size')->nullable();


// Privacy
$table->boolean('is_private')->default(false);

$table->timestamps();


// Foreign
$table->foreign('campaign_id')->references('id')->on('campaigns')->onDelete('cascade');
$table->foreign('campaign_id')->references('id')->on('campaigns')->cascadeOnDelete();
$table->foreign('location_id')->references('id')->on('locations')->nullOnDelete();
$table->foreign('character_id')->references('id')->on('characters')->nullOnDelete();
$table->foreign('item_id')->references('id')->on('items')->nullOnDelete();

// Index
$table->index(['name', 'slug', 'type', 'is_private']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function up()
$table->boolean('has_last_login_sharing')->default(0);

$table->string('theme', 20)->nullable();
$table->text('profile')->nullable();

$table->datetime('banned_until')->nullable();

$table->index(['provider', 'provider_id']);

Expand Down
8 changes: 7 additions & 1 deletion database/migrations/2017_11_03_181958_create_notes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function up()
$table->string('image', 255)->nullable();

$table->integer('campaign_id')->unsigned()->notNull();
$table->unsignedInteger('note_id')->nullable();
$table->unsignedInteger('_lft')->default(0);
$table->unsignedInteger('_rgt')->default(0);


// Overview
$table->longText('entry')->nullable();
Expand All @@ -32,10 +36,12 @@ public function up()
$table->index(['is_private']);

// Foreign
$table->foreign('campaign_id')->references('id')->on('campaigns')->onDelete('cascade');
$table->foreign('campaign_id')->references('id')->on('campaigns')->cascadeOnDelete();
$table->foreign('note_id')->references('id')->on('notes')->nullOnDelete();

// Index
$table->index(['name', 'slug', 'type']);
$table->index(['_lft', '_rgt', 'note_id']);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public function up()
$table->boolean('menu_links')->default(true);
$table->boolean('maps')->default(true);
$table->boolean('inventories')->default(true);
$table->boolean('entity_attributes')->default(true);
$table->timestamps();

// Foreign
$table->foreign('campaign_id')->references('id')->on('campaigns')->onDelete('cascade');
$table->foreign('campaign_id')->references('id')->on('campaigns')->cascadeOnDelete();
});
}

Expand Down
Loading

0 comments on commit 7ecea6d

Please sign in to comment.