You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\CurrencyTypes;
|
||||
use App\Models\User;
|
||||
use App\Services\RconService;
|
||||
|
||||
class SendCurrency
|
||||
{
|
||||
public function __construct(protected RconService $rcon) {}
|
||||
|
||||
public function execute(User $user, string $type, ?int $amount): bool
|
||||
{
|
||||
if (! $amount || $amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->rcon->isConnected) {
|
||||
match ($type) {
|
||||
'credits' => $this->rcon->giveCredits($user, $amount),
|
||||
'duckets' => $this->rcon->giveDuckets($user, $amount),
|
||||
'diamonds' => $this->rcon->giveDiamonds($user, $amount),
|
||||
'points' => $this->rcon->giveGotw($user, $amount),
|
||||
default => false,
|
||||
};
|
||||
} else {
|
||||
match ($type) {
|
||||
'credits' => $user->update(['credits' => $user->credits + $amount]),
|
||||
'duckets' => $user->currencies()->where('type', CurrencyTypes::Duckets)->increment('amount', $amount),
|
||||
'diamonds' => $user->currencies()->where('type', CurrencyTypes::Diamonds)->increment('amount', $amount),
|
||||
'points' => $user->currencies()->where('type', CurrencyTypes::Points)->increment('amount', $amount),
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user