403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/lpost.delivery/lib/agents/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/lpost.delivery/lib/agents/receiver.php
<?

namespace Lpost\Delivery\Agents;

use \Bitrix\Main\Localization\Loc;
use Lpost\Delivery\Repository\RepositoryPickupStorage;
use Lpost\Delivery\Repository\RepositoryReceivePoints;
use \Lpost\Delivery\Settings;

Loc::loadMessages(__FILE__);

// start for agent self::request()

class Receiver
{
    use \Lpost\Delivery\Connector;

    const REGION_IDS = [
        1, 2, 3, 4, 5, 6, 7, 8, 9,
        10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 21, 22, 23, 24,
        25, 26, 27, 28, 29, 30, 31,
        32, 33, 34, 35, 36, 37, 38,
        39, 40, 41, 42, 43, 44, 45,
        46, 47, 48, 49, 50, 51, 52,
        53, 54, 55, 56, 57, 58, 59,
        60, 61, 62, 63, 64, 65, 66,
        67, 68, 69, 70, 71, 72, 73,
        74, 75, 76, 77, 78, 79, 80,
        81, 82, 83, 84, 85, 86, 87,
        88, 89, 92, 95, 101
    ];

    public $fileDir;
    public $fileName;
    public $fileFull;

    function __construct()
    {
        $this->fileDir = $_SERVER['DOCUMENT_ROOT'] . "/upload/" . \Lpost\Delivery\Settings::getInstance()->getModuleId();
        $this->fileName = "pickups.json";
        $this->fileFull = $this->fileDir . "/" . $this->fileName;
    }

    public static function agentGetPickUpPoints(): string
    {
        if(self::isFileReady())
        {
            (new RepositoryPickupStorage)->deleteAll();

            self::getAll();

            \Lpost\Delivery\Agents\Savers::sync();

            if((new RepositoryReceivePoints())->isEmpty()) {
                (new Receiver())->getReceivePoints();
            }
        }
        return "\Lpost\Delivery\Agents\Receiver::agentGetPickUpPoints();";
    }

    /**
     * @throws \Bitrix\Main\ObjectPropertyException
     * @throws \Bitrix\Main\SystemException
     * @throws \Bitrix\Main\ArgumentException
     */
    public static function getAll()
    {
        $offset = 0;
        $limit = 10;

        while (self::get($offset, $limit)) {
            $offset += $limit;
        }
    }

    /**
     * @param int $offset
     * @param int $limit
     * @return int
     * @throws \Bitrix\Main\ArgumentException
     * @throws \Bitrix\Main\ObjectPropertyException
     * @throws \Bitrix\Main\SystemException
     */
    public static function get(int $offset = 0, int $limit = 10): int
    {
        $receiver = new Receiver();
        $options = Settings::getInstance()->getOptions();

        if (empty($options['lpost_token'])) {
            return false;
        }

        if($regionIds = array_slice(self::REGION_IDS, $offset, $limit)) {
            $data = $receiver->getData(
                "GetPickupPoints",
                [
                    "token" => $receiver->getToken(),
                    "json"  => \Bitrix\Main\Web\Json::encode([
                        "ID_Regions" => $regionIds //[77]
                        //,"isCourier" => 1
                    ])
                ]
            );
            
            $receiver->saveToTable($data);
        }

        /**
         *  how much is left to save
         */
        return max((count(self::REGION_IDS) - $offset), 0);

    }


    public static function isFileReady(): bool
    {
        $dateUpdate = \Lpost\Delivery\Settings::getInstance()->getOption('lpost_pickup_update_date');
        if($dateUpdate <= strtotime('-1 day'))
        {
            return true;
        }

        return false;
    }

    public function saveToTable($data)
    {
        if (!empty($data['JSON_TXT'])) {

            $jsonData = \Bitrix\Main\Web\Json::decode($data['JSON_TXT']);

            foreach ($jsonData['PickupPoint'] as $key => $jsonItem) {
                \Lpost\Delivery\Entity\PickupStorageTable::add([
                    "id_pickup" => $jsonItem['ID_PickupPoint'],
                    "type" => ($jsonItem['IsCourier'] == 0) ? "pvz" : "zone",
                    "data" => $jsonItem
                ]);
            }

            \Lpost\Delivery\Settings::getInstance()->setOption(
                'lpost_pickup_update_date',
                time()
            );
        }
    }

    public function getReceivePoints()
    {
        $data = $this->getData(
            "GetReceivePoints",
            [
                "token" => $this->getToken()
            ]
        );
        if (!empty($data["JSON_TXT"])) {

            (new RepositoryReceivePoints())->deleteAll();

            $rp = \Bitrix\Main\Web\Json::decode($data["JSON_TXT"]);
            foreach ($rp["ReceivePoints"] as $nextpoint) {
                $params = [];
                if (!empty($nextpoint['Shedule'])) {
                    $params['shedule'] = $nextpoint['Shedule'];
                }
                if (!empty($nextpoint['Break'])) {
                    $params['break'] = $nextpoint['Break'];
                }
                $insArr = [
                    'id_sklad'  => $nextpoint['ID_Sklad'],
                    'id_region' => $nextpoint['ID_Region'],
                    'city_name' => $nextpoint['City'],
                    'address'   => $nextpoint['Address'],
                    'params'    => \Bitrix\Main\Web\Json::encode($params)
                ];
                \Lpost\Delivery\Entity\ReceivePointsTable::add($insArr);
            }
        }
    }

}

?>

Youez - 2016 - github.com/yon3zu
LinuXploit