Initialer Laravel Commit für BetiX
This commit is contained in:
52
app/Models/OperatorSession.php
Normal file
52
app/Models/OperatorSession.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OperatorSession extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'session_token',
|
||||
'operator_casino_id',
|
||||
'player_id',
|
||||
'game_slug',
|
||||
'currency',
|
||||
'start_balance',
|
||||
'current_balance',
|
||||
'server_seed',
|
||||
'server_seed_hash',
|
||||
'client_seed',
|
||||
'status',
|
||||
'expires_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_balance' => 'decimal:4',
|
||||
'current_balance' => 'decimal:4',
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function casino()
|
||||
{
|
||||
return $this->belongsTo(OperatorCasino::class, 'operator_casino_id');
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->expires_at->isPast() || $this->status !== 'active';
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark expired session if its expiry timestamp has passed.
|
||||
* Returns true if the status was just changed.
|
||||
*/
|
||||
public function expireIfNeeded(): bool
|
||||
{
|
||||
if ($this->status === 'active' && $this->expires_at->isPast()) {
|
||||
$this->update(['status' => 'expired']);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user