\App\Module\GameItems\Casts\DisplayAttributesCast::class, 'numeric_attributes' => \App\Module\GameItems\Casts\NumericAttributesCast::class, 'tradable' => 'boolean', 'is_bound' => 'boolean', ]; /** * 获取物品实例对应的基础物品 * * @return BelongsTo */ public function item(): BelongsTo { return $this->belongsTo(Item::class, 'item_id'); } /** * 获取拥有该物品实例的用户 * * @return HasMany */ public function users(): HasMany { return $this->hasMany(ItemUser::class, 'instance_id'); } /** * 检查物品实例是否已过期 * * @return bool */ public function isExpired(): bool { if (empty($this->expire_at)) { return $this->item->isExpired(); } return $this->expire_at->isPast() || $this->item->isExpired(); } /** * 检查物品是否已绑定 * * @return bool */ public function isBound(): bool { return $this->is_bound; } /** * 检查绑定是否已过期 * * @return bool */ public function isBindExpired(): bool { if (empty($this->bind_exp_time)) { return false; } return $this->bind_exp_time->isPast(); } /** * 检查物品是否可交易 * * @return bool */ public function isTradable(): bool { if (!$this->tradable) { return false; } if ($this->is_bound && !$this->isBindExpired()) { return false; } return true; } }