U
U
UncleDenn2017-07-31 17:37:06
Laravel
UncleDenn, 2017-07-31 17:37:06

How to display prices from the parser?

Hello everyone, I have this question:
the code of the parser of things:

public function loadMyInventory() {
        if(Auth::guest()) return ['success' => false];
    $prices = json_decode(File::get('prices.txt'), true);
    
    if (Session::get('applocale') == 'ru') {
        	$response = json_decode(file_get_contents('https://steamcommunity.com/inventory/'.$this->user->steamid64.'/730/2?l=russian&count=5000'), true);
    } else {
      $response = json_decode(file_get_contents('https://steamcommunity.com/inventory/'.$this->user->steamid64.'/730/2?l=english&count=5000'), true);
    }
    if(time() < (Session::get('InvUPD') + 5)) {
      return [
        'success' => false,
        'msg' => 'Произошла ошибка. Повторите через '.(Session::get('InvUPD') - time() + 5).' сек.',
        'status' => 'error'
      ];
    }
        //return $response;
        $inventory = [];
        
        foreach($response['assets'] as $item) {
            $find = 0;
            foreach($response['descriptions'] as $descriptions) {
                if($find == 0) {
                    if(($descriptions['classid'] == $item['classid']) && ($descriptions['instanceid'] == $item['instanceid'])) {
                        $find++;
                        # Если мы нашли цену на итем, то идем дальше.
                        if(isset($prices['data']['prices'][0]['market_hash_name'])) {
                            # Поиск данных
                            $price = $prices['data']['prices'][0]['price']*$this->config->curs;
                            $class = false;
                            $text = false;
                            
                            if($price <= $this->config->min_dep_sum) {
                                $price = 0;
                                if (Session::get('applocale') == 'ru') {
                                    $text = 'Дешевое';
                                } else {
                                    $text = 'Cheap';
                                }
                                $class = 'minPrice';
                            }
                            
                            if(($descriptions['tradable'] == 0) || ($descriptions['marketable'] == 0)) {
                                $price = 0;
                                $class = 'minPrice';
                                if (Session::get('applocale') == 'ru') {
                                    $text = 'Нельзя передавать';
                                } else {
                                    $text = 'Not tradable';
                                }
                            }
                            # Добавление в массив
                            $inventory[] = [
                                'name' => $descriptions['market_name'],
                                'price' => floor($price),
                                'color' => $this->getRarity($descriptions['tags']),
                                'tradable' => $descriptions['tradable'],
                                'class' => $class,
                                'text' => $text,
                                'classid' => $item['classid'],
                                'assetid' => $item['assetid'],
                                'instanceid' => $item['instanceid']
                            ];   
                        }
                    }
                }
            }
        }
        Session::put('InvUPD', (time() + 5));
        return [
            'success' => true,
            'items' => $inventory
        ];
    }

how to display the price(price) in the following structure:
{
"status" : "success",
"prices" : [
{
"appid" : "730",
"market_hash_name" : "AK-47 | Aquamarine Revenge (Battle-Scarred)" ,
"price" : "13.27",
"pricing_mode" : "market",
"skewness" : "-0.19",
"created_at" : 1501407594,
"icon_url" : " https://steamcommunity-a.akamaihd.net/economy /imag... ",
"name_color" : "D2D2D2",
"quality_color" : "EB4B4B"
},

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2017-07-31
@dimonchik2013

https://stackoverflow.com/questions/6836592/serial...

I
Ivan, 2017-08-01
@asmodeusta

Use json_encode on the resulting array.

function renderArr($your_array) {
    echo json_encode($your_array);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question