'datetime', 'triggered_at' => 'datetime', 'expires_at' => 'datetime', 'enabled' => 'boolean', 'total_amount' => 'integer', 'max_claimants' => 'integer', 'min_amount' => 'integer', 'max_amount' => 'integer', 'fixed_amount' => 'integer', 'expire_minutes' => 'integer', 'claimed_count' => 'integer', 'claimed_amount' => 'integer', ]; } /** * 本次活动的所有领取记录。 */ public function claims(): HasMany { return $this->hasMany(HolidayClaim::class, 'event_id'); } /** * 判断活动是否在领取有效期内。 */ public function isClaimable(): bool { return $this->status === 'active' && $this->expires_at && $this->expires_at->isFuture(); } /** * 判断是否还有剩余领取名额。 */ public function hasQuota(): bool { if ($this->max_claimants === 0) { return true; // 不限人数 } return $this->claimed_count < $this->max_claimants; } /** * 查询待触发的活动(定时任务调用)。 */ public static function pendingToTrigger(): \Illuminate\Database\Eloquent\Collection { return static::query() ->where('status', 'pending') ->where('enabled', true) ->where('send_at', '<=', now()) ->get(); } }