Daily currency reward.
This commit is contained in:
parent
45f6074c9c
commit
608b071ee8
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
Graphictoria 2022
|
||||||
|
Number helper.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
class NumberHelper
|
||||||
|
{
|
||||||
|
public static function Abbreviate($number)
|
||||||
|
{
|
||||||
|
$divisors = array(
|
||||||
|
pow(1000, 0) => '', // 1000^0 == 1
|
||||||
|
pow(1000, 1) => 'K+', // Thousand
|
||||||
|
pow(1000, 2) => 'M+', // Million
|
||||||
|
pow(1000, 3) => 'B+', // Billion
|
||||||
|
pow(1000, 4) => 'T+', // Trillion
|
||||||
|
pow(1000, 5) => 'Qa+', // Quadrillion
|
||||||
|
pow(1000, 6) => 'Qi+', // Quintillion
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($divisors as $divisor => $shorthand) {
|
||||||
|
if (abs($number) < ($divisor * 1000))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return number_format($number / $divisor, 0) . $shorthand;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -36,6 +36,8 @@ class Kernel extends HttpKernel
|
||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
|
||||||
|
\App\Http\Middleware\DailyReward::class
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class DailyReward
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||||
|
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, Closure $next)
|
||||||
|
{
|
||||||
|
if (Auth::check() && Carbon::now()->gte(Auth::user()->next_reward)) {
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
$user->tokens += 15;
|
||||||
|
$user->next_reward = Carbon::now()->addHours(24);
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -40,5 +40,6 @@ class User extends Authenticatable
|
||||||
*/
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'email_verified_at' => 'datetime',
|
'email_verified_at' => 'datetime',
|
||||||
|
'next_reward' => 'datetime',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'timezone' => 'UTC',
|
'timezone' => 'America/New_York',
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,14 @@ return new class extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('username')->unique();
|
$table->string('username')->unique();
|
||||||
$table->string('email')->unique();
|
$table->string('email')->unique();
|
||||||
$table->timestamp('email_verified_at')->nullable();
|
$table->dateTime('email_verified_at')->nullable();
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
$table->rememberToken();
|
$table->rememberToken();
|
||||||
|
$table->unsignedBigInteger('banId')->nullable();
|
||||||
|
|
||||||
|
$table->unsignedBigInteger('tokens')->default(0);
|
||||||
|
$table->dateTime('next_reward')->useCurrent();
|
||||||
|
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,8 @@
|
||||||
<div id="graphictoria-nav-searchbar" class="graphictoria-search"></div>
|
<div id="graphictoria-nav-searchbar" class="graphictoria-search"></div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<p class="my-auto me-2 text-muted" style="color:#e59800!important;font-weight:bold">
|
<p class="my-auto me-2 text-muted" style="color:#e59800!important;font-weight:bold">
|
||||||
<span data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tokens are Graphictoria's currency.">
|
<span data-bs-toggle="tooltip" data-bs-placement="bottom" title="You have {{ number_format(Auth::user()->tokens) }} tokens. Your next reward is in {{ Auth::user()->next_reward->diffForHumans(['syntax' => Carbon\CarbonInterface::DIFF_ABSOLUTE]) }}.">
|
||||||
<img src="{{ asset('images/symbols/token.svg') }}" height="20" width="20" class="img-fluid me-1" style="margin-top:-1px" />
|
<img src="{{ asset('images/symbols/token.svg') }}" height="20" width="20" class="img-fluid me-1" style="margin-top:-1px" />{{ \App\Helpers\NumberHelper::Abbreviate(Auth::user()->tokens) }}
|
||||||
123
|
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue