| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace App\Module\GameItems\Logics;
- use App\Module\GameItems\Models\ItemInstance as ItemInstanceModel;
- /**
- * 物品实例逻辑类
- */
- class ItemInstance
- {
- /**
- * 检查物品实例是否已过期
- *
- * @param ItemInstanceModel $instance 物品实例模型
- * @return bool
- */
- public function isExpired(ItemInstanceModel $instance): bool
- {
- // 注入Item逻辑类
- $itemLogic = new Item();
-
- if (empty($instance->expire_at)) {
- return $itemLogic->isExpired($instance->item);
- }
- return $instance->expire_at->isPast() || $itemLogic->isExpired($instance->item);
- }
- /**
- * 检查物品是否已绑定
- *
- * @param ItemInstanceModel $instance 物品实例模型
- * @return bool
- */
- public function isBound(ItemInstanceModel $instance): bool
- {
- return $instance->is_bound;
- }
- /**
- * 检查绑定是否已过期
- *
- * @param ItemInstanceModel $instance 物品实例模型
- * @return bool
- */
- public function isBindExpired(ItemInstanceModel $instance): bool
- {
- if (empty($instance->bind_exp_time)) {
- return false;
- }
- return $instance->bind_exp_time->isPast();
- }
- }
|