支持所有游戏按房间范围配置和运行
This commit is contained in:
@@ -25,6 +25,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
class HorseRace extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'room_id',
|
||||
'status',
|
||||
'bet_opens_at',
|
||||
'bet_closes_at',
|
||||
@@ -48,6 +49,7 @@ class HorseRace extends Model
|
||||
'race_starts_at' => 'datetime',
|
||||
'race_ends_at' => 'datetime',
|
||||
'settled_at' => 'datetime',
|
||||
'room_id' => 'integer',
|
||||
'horses' => 'array',
|
||||
'winner_horse_id' => 'integer',
|
||||
'total_bets' => 'integer',
|
||||
@@ -75,12 +77,15 @@ class HorseRace extends Model
|
||||
/**
|
||||
* 查询当前正在进行的场次(状态为 betting 且押注未截止)。
|
||||
*/
|
||||
public static function currentRace(): ?static
|
||||
public static function currentRace(?int $roomId = null): ?static
|
||||
{
|
||||
return static::query()
|
||||
->whereIn('status', ['betting', 'running'])
|
||||
->latest()
|
||||
->first();
|
||||
$query = static::query()->whereIn('status', ['betting', 'running']);
|
||||
|
||||
if ($roomId !== null) {
|
||||
$query->where('room_id', $roomId);
|
||||
}
|
||||
|
||||
return $query->latest()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user