Added casino interface, wallet login, sucessful npm build sucessfull container build

This commit is contained in:
2025-09-06 14:39:39 +02:00
parent 7e311fbe27
commit 3983cdd554
24 changed files with 1681 additions and 524 deletions

View File

@@ -0,0 +1,110 @@
<?php
namespace App\Helpers;
use Illuminate\Support\Facades\DB;
use App\Models\Wallet;
use App\Models\Transaction;
use App\Models\AuditLog;
class WalletHelper
{
/**
* Process a wallet transaction (e.g., deposit, bet) with atomic updates and audit logging.
*
* @param int $userId
* @param float $amount
* @param string $type (deposit, bet, win, withdrawal)
* @param string|null $description
* @param string|null $ipAddress
* @return Transaction
* @throws \Exception
*/
public static function processTransaction($userId, $amount, $type, $description = null, $ipAddress = null)
{
return DB::transaction(function () use ($userId, $amount, $type, $description, $ipAddress) {
// Lock wallet for atomic update
$wallet = Wallet::where('user_id', $userId)->lockForUpdate()->firstOrFail();
// Validate balance for bets/withdrawals
if (in_array($type, ['bet', 'withdrawal']) && $wallet->balance < $amount) {
throw new \Exception('Insufficient Skunk Coins');
}
// Update balance
$newBalance = in_array($type, ['bet', 'withdrawal']) ? $wallet->balance - $amount : $wallet->balance + $amount;
$wallet->update(['balance' => $newBalance]);
// Create transaction with SHA-256 hash
$hash = hash('sha256', $userId . $amount . $type . time());
$transaction = Transaction::create([
'wallet_id' => $wallet->id,
'amount' => $amount,
'type' => $type,
'description' => $description,
'hash' => $hash,
]);
// Log action in audit_logs
AuditLog::create([
'user_id' => $userId,
'action' => 'wallet_' . $type,
'details' => json_encode([
'wallet_id' => $wallet->id,
'amount' => $amount,
'new_balance' => $newBalance,
'transaction_id' => $transaction->id,
]),
'ip_address' => $ipAddress,
]);
return $transaction;
});
}
/**
* Redeem a promo code for Skunk Coins.
*
* @param int $userId
* @param string $code
* @param string|null $ipAddress
* @return Transaction
* @throws \Exception
*/
public static function redeemPromoCode($userId, $code, $ipAddress = null)
{
return DB::transaction(function () use ($userId, $code, $ipAddress) {
$promo = \App\Models\PromoCode::where('code', $code)
->where('is_active', true)
->where(function ($query) {
$query->where('uses_remaining', -1)->orWhere('uses_remaining', '>', 0);
})
->where(function ($query) {
$query->whereNull('expires_at')->orWhere('expires_at', '>', now());
})
->firstOrFail();
// Check if already redeemed
if (\App\Models\PromoCodeRedemption::where('user_id', $userId)->where('promo_code_id', $promo->id)->exists()) {
throw new \Exception('Promo code already redeemed');
}
// Process deposit
$transaction = self::processTransaction($userId, $promo->value, 'deposit', "Promo code: $code", $ipAddress);
// Record redemption
\App\Models\PromoCodeRedemption::create([
'promo_code_id' => $promo->id,
'user_id' => $userId,
'redeemed_at' => now(),
]);
// Decrement uses if limited
if ($promo->uses_remaining !== -1) {
$promo->decrement('uses_remaining');
}
return $transaction;
});
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace App\Http\Controllers;
use Inertia\Inertia;
use App\Models\Wallet;
use App\Models\Game;
use App\Helpers\WalletHelper;
use Illuminate\Http\Request;
class LobbyController extends Controller
{
public function index()
{
$user = auth()->user();
return Inertia::render('Lobby', [
'wallet' => Wallet::where('user_id', $user->id)->first() ?? ['balance' => 0],
'games' => Game::where('is_active', true)->get(),
'user' => [
'name' => $user->name,
'vip_level' => $user->vip_level,
'is_kyc_verified' => $user->is_kyc_verified,
],
]);
}
public function addCoins(Request $request)
{
$request->validate(['amount' => 'required|numeric|min:1']);
WalletHelper::processTransaction(auth()->id(), $request->amount, 'deposit', 'Manual coin addition', $request->ip());
return Inertia::render('Lobby', [
'wallet' => Wallet::where('user_id', auth()->id())->first(),
'games' => Game::where('is_active', true)->get(),
'user' => [
'name' => auth()->user()->name,
'vip_level' => auth()->user()->vip_level,
'is_kyc_verified' => auth()->user()->is_kyc_verified,
],
'success' => 'Added ' . $request->amount . ' Skunk Coins',
]);
}
public function redeemPromo(Request $request)
{
$request->validate(['code' => 'required|string']);
try {
WalletHelper::redeemPromoCode(auth()->id(), $request->code, $request->ip());
return Inertia::render('Lobby', [
'wallet' => Wallet::where('user_id', auth()->id())->first(),
'games' => Game::where('is_active', true)->get(),
'user' => [
'name' => auth()->user()->name,
'vip_level' => auth()->user()->vip_level,
'is_kyc_verified' => auth()->user()->is_kyc_verified,
],
'success' => 'Promo code redeemed successfully',
]);
} catch (\Exception $e) {
return Inertia::render('Lobby', [
'wallet' => Wallet::where('user_id', auth()->id())->first(),
'games' => Game::where('is_active', true)->get(),
'user' => [
'name' => auth()->user()->name,
'vip_level' => auth()->user()->vip_level,
'is_kyc_verified' => auth()->user()->is_kyc_verified,
],
'error' => $e->getMessage(),
]);
}
}
}

42
app/Models/AuditLog.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class AuditLog extends Model
{
use HasFactory, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'action',
'details',
'ip_address',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'details' => 'json',
];
/**
* Get the user that owns the audit log.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

33
app/Models/Game.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Game extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'slug',
'thumbnail_url',
'category',
'is_active',
];
/**
* Get the player stats for the game.
*/
public function playerStats(): HasMany
{
return $this->hasMany(PlayerStats::class);
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PlayerStats extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'game_id',
'total_winnings',
'total_bets',
'play_count',
'daily_play_amount',
'win_streak',
'last_played_at',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'last_played_at' => 'datetime',
];
/**
* Get the user that owns the stats.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Get the game for the stats (if per-game).
*/
public function game(): BelongsTo
{
return $this->belongsTo(Game::class);
}
/**
* Custom method to update stats after a game play (example).
*
* @param float $betAmount
* @param float $winAmount
*/
public function updateAfterPlay(float $betAmount, float $winAmount): void
{
$this->increment('play_count');
$this->total_bets += $betAmount;
$this->total_winnings += $winAmount;
$this->daily_play_amount += $betAmount; // Simplify; use cron for daily reset
$this->win_streak = $winAmount > 0 ? $this->win_streak + 1 : 0;
$this->last_played_at = now();
$this->save();
}
}

42
app/Models/PromoCode.php Normal file
View File

@@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PromoCode extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'code',
'value',
'uses_remaining',
'expires_at',
'is_active',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'expires_at' => 'datetime',
];
/**
* Get the redemptions for the promo code.
*/
public function redemptions(): HasMany
{
return $this->hasMany(PromoCodeRedemption::class);
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PromoCodeRedemption extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'promo_code_id',
'user_id',
'redeemed_at',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'redeemed_at' => 'datetime',
];
/**
* Get the promo code that owns the redemption.
*/
public function promoCode(): BelongsTo
{
return $this->belongsTo(PromoCode::class);
}
/**
* Get the user that owns the redemption.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Transaction extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'wallet_id',
'amount',
'type',
'description',
'hash',
];
/**
* Get the wallet that owns the transaction.
*/
public function wallet(): BelongsTo
{
return $this->belongsTo(Wallet::class);
}
}

49
app/Models/Wallet.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Wallet extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'balance',
];
/**
* Get the user that owns the wallet.
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Get the transactions for the wallet.
*/
public function transactions(): HasMany
{
return $this->hasMany(Transaction::class);
}
/**
* Custom method to get total winnings (derived from transactions).
*
* @return float
*/
public function getTotalWinningsAttribute(): float
{
return $this->transactions()->where('type', 'win')->sum('amount');
}
}

View File

@@ -17,6 +17,7 @@ use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use Spatie\Permission\Middlewares\RoleMiddleware;
class AdminPanelProvider extends PanelProvider
{
@@ -27,8 +28,10 @@ class AdminPanelProvider extends PanelProvider
->id('admin')
->path('admin')
->login()
->darkMode(true) // Enforce dark theme for casino admin vibe
->colors([
'primary' => Color::Amber,
'primary' => Color::hex('#4CAF50'), // Crypto-green for consistency with lobby
'secondary' => Color::hex('#0D1117'), // Dark background to match Stake.com aesthetic
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
@@ -39,6 +42,7 @@ class AdminPanelProvider extends PanelProvider
->widgets([
Widgets\AccountWidget::class,
Widgets\FilamentInfoWidget::class,
// Add custom widgets later for stats (e.g., user activity, Skunk Coins transactions)
])
->middleware([
EncryptCookies::class,
@@ -53,6 +57,10 @@ class AdminPanelProvider extends PanelProvider
])
->authMiddleware([
Authenticate::class,
]);
RoleMiddleware::class . ':admin', // Restrict to admin role via Spatie
])
->brandName('Skunk Lounge Admin')
->brandLogo(asset('images/logo.png')) // Placeholder for custom logo
->favicon(asset('images/favicon.ico')); // Placeholder for favicon
}
}
}