/** * @param $userId * @param $from * @param $to * @return array */ protected function fetchInventory($userId, $from, $to) { $inventory = $this->steamSchema->queryPlayerInventory(570, $userId)->where(function ($row) { return $row['tradable']; })->slice($from, $to)->get(); usort($inventory, [ItemStorage::getItemClass(570), 'sortByPrice']); return $inventory; }
/** * @param $appId * @param $steamID * @return array */ public function getRawPlayerInventory($appId, $steamID) { if (isset(self::$inventories[$steamID]) && !empty(self::$inventories[$steamID])) { return self::$inventories[$steamID]; } Debugbar::startMeasure('getRawInventory', 'Получаем инвентарь'); $appContext = ItemStorage::getItemContextID($appId); $url = $this->communityURL . 'profiles/' . $steamID . '/inventory/json/' . $appId . '/' . $appContext . '?l=russian'; $json = $this->getPage($url); Debugbar::stopMeasure('getRawInventory'); Debugbar::startMeasure('parseRawInventory', 'Декодируем инвентарь'); $result = json_decode($json, true); if (!$result['success']) { Debugbar::stopMeasure('parseRawInventory'); Debugbar::warning('Ошибка парсинга инвентаря!'); Debugbar::info($result); return []; } self::$inventories[$steamID] = $result; Debugbar::stopMeasure('parseRawInventory'); return $result; }
/** * @param $itemInfo * @return Item */ public function parseItem($itemInfo) { if (empty($itemInfo) || !is_array($itemInfo)) { throw new \InvalidArgumentException('ItemInfo should be filled array!'); } $key = md5(json_encode($itemInfo)); if (isset(self::$itemCache[$key]) && !empty(self::$itemCache[$key])) { return self::$itemCache[$key]; } \Debugbar::startMeasure('parseItem', 'Парсим предмет ' . $itemInfo['name']); /** @var Item $item */ $item = ItemStorage::createItem($itemInfo); if ($itemInfo['tradable'] !== '0') { try { /** @var $price ItemPrice */ $price = $this->priceHelper->getItemPrice($item); $item->setPrice($price); } catch (\Exception $e) { \Log::debug($e->getMessage()); } } \Debugbar::stopMeasure('parseItem'); return $item; }