$singleDto]; // 使用0作为默认键 } /** * 从缓存数据创建单个DTO对象 * * 这是一个辅助方法,保留原有的逻辑,但不覆盖父类的fromCache方法 * * @param mixed $cachedData 缓存数据 * @return HouseChangeTempDto|null 包含DTO对象或null */ public static function fromCacheSingle($cachedData): ?HouseChangeTempDto { if (empty($cachedData)) { return null; } if ($cachedData instanceof self) { return $cachedData; } if (!is_array($cachedData)) { return null; } $dto = new self(); $dto->oldLevel = $cachedData['old_level'] ?? 0; $dto->newLevel = $cachedData['new_level'] ?? 0; $dto->isUpgrade = $cachedData['is_upgrade'] ?? true; $dto->outputBonus = $cachedData['output_bonus'] ?? 0.0; $dto->specialLandLimit = $cachedData['special_land_limit'] ?? 0; $dto->updatedAt = $cachedData['updated_at'] ?? time(); return $dto; } /** * 转换为数组 * * @return array */ public function toArray(): array { return [ 'old_level' => $this->oldLevel, 'new_level' => $this->newLevel, 'is_upgrade' => $this->isUpgrade, 'output_bonus' => $this->outputBonus, 'special_land_limit' => $this->specialLandLimit, 'updated_at' => $this->updatedAt, ]; } }