'boolean', ]; /** * 获取该商品的所有购买记录 */ public function purchases(): HasMany { return $this->hasMany(UserPurchase::class); } /** * 是否为自动钓鱼卡 */ public function isAutoFishingCard(): bool { return $this->type === 'auto_fishing'; } /** * 是否为特效类商品(instant 或 duration,slug 以 once_ 或 week_ 开头) */ public function isEffect(): bool { return str_starts_with($this->slug, 'once_') || str_starts_with($this->slug, 'week_'); } /** * 是否为周卡(duration 类型) */ public function isWeekCard(): bool { return $this->type === 'duration'; } /** * 是否为单次卡(instant 类型) */ public function isInstant(): bool { return $this->type === 'instant'; } /** * 获取特效 key(去掉 once_ / week_ 前缀,返回 fireworks/rain/lightning/snow) */ public function effectKey(): ?string { if (str_starts_with($this->slug, 'once_')) { return substr($this->slug, 5); } if (str_starts_with($this->slug, 'week_')) { return substr($this->slug, 5); } return null; } /** * 获取所有上架商品(按排序) */ public static function active(): Collection { return static::where('is_active', true)->orderBy('sort_order')->get(); } }