支持所有游戏按房间范围配置和运行

This commit is contained in:
pllx
2026-04-29 14:37:28 +08:00
parent 3672140987
commit 1607f57e3c
37 changed files with 1033 additions and 255 deletions
+14 -5
View File
@@ -17,9 +17,13 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
/**
* 类功能:保存神秘箱子投放记录并提供当前箱子查询能力。
*/
class MysteryBox extends Model
{
protected $fillable = [
'room_id',
'box_type',
'passcode',
'reward_min',
@@ -35,6 +39,7 @@ class MysteryBox extends Model
protected function casts(): array
{
return [
'room_id' => 'integer',
'reward_min' => 'integer',
'reward_max' => 'integer',
'expires_at' => 'datetime',
@@ -64,13 +69,17 @@ class MysteryBox extends Model
/**
* 当前可领取(open 状态 + 未过期)的箱子。
*/
public static function currentOpenBox(): ?static
public static function currentOpenBox(?int $roomId = null): ?static
{
return static::query()
$query = static::query()
->where('status', 'open')
->where(fn ($q) => $q->whereNull('expires_at')->orWhere('expires_at', '>', now()))
->latest()
->first();
->where(fn ($q) => $q->whereNull('expires_at')->orWhere('expires_at', '>', now()));
if ($roomId !== null) {
$query->where('room_id', $roomId);
}
return $query->latest()->first();
}
// ─── 工具方法 ────────────────────────────────────────────────────