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/wbs24.ozonapinew/lib/Api/Fbs/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/wbs24.ozonapinew/lib/Api/Fbs/StatusAct.php
<?php
namespace Wbs24\Ozonapinew\Api\Fbs;

use Bitrix\Main\SystemException;
use Wbs24\Ozonapinew\Api;

class StatusAct extends Api
{
    public function __construct($objects = [])
    {
        parent::__construct($objects);

        $this->GetAct = $objects['GetAct'] ?? null;
        $this->DigitalStatusAct = $objects['DigitalStatusAct'] ?? null;
        $this->DigitalGetAct = $objects['DigitalGetAct'] ?? null;
    }

    public function apiLaunch($data)
    {
        $requestUrl = $this->getRequestUrl('/v2/posting/fbs/act/check-status');
        $requestBody = $this->getRequestBody($data);
        $request = $this->createRequest($requestUrl, $requestBody);

        return $request['result'] ?: 'error';
    }

    protected function getRequestBody($data)
    {
        $requestBody = [
            'id' => $data['act_create_id'],
        ];

        return $requestBody;
    }

    public function processAction($data)
    {
        $result = 'error';
        $linkToDocument = '';
        $externalId = $data['external_id'] ?? '';

        if ($externalId && $data['result'] != 'error') {
            $result = 'success';
            $actType = $data['result']['act_type'] ?? '';

            if ($actType == 'ozon_digital') {
                // электронный акт
                $linkToDocument = $this->getDigitalAct($data);
            } else {
                // бумажный акт
                $status = $data['result']['status'] ?? '';
                $linkToDocument = $this->getAct($status, $data);
            }

            if ($linkToDocument) {
                $this->OrdersState->setAct(
                    $externalId,
                    $linkToDocument,
                );
                $this->setActForIncludedOrders($data, $linkToDocument);
            }
        }

        return [
            'result' => $result,
            'link_to_document' => $linkToDocument,
        ];
    }

    protected function getDigitalAct($data)
    {
        $linkToDocument = '';
        $actId = $data['act_create_id'] ?? '';

        if (
            $actId
            && is_object($this->DigitalStatusAct)
            && is_object($this->DigitalGetAct)
        ) {
            $statusResult = $this->DigitalStatusAct->apiLaunch($data);
            $status = $statusResult['status'] ?? '';
            if (
                $status == 'FORMED'
                || $status == 'CONFIRMED'
                || $status == 'CONFIRMED_WITH_MISMATCH'
            ) {
                $actResult = $this->DigitalGetAct->apiLaunch($data);
                $pdf = ($actResult != 'error') ? $actResult : '';
                if ($pdf) {
                    $linkToDocument = $this->createPdfAndGetLink($actId, $pdf);
                }
            }
        }

        return $linkToDocument;
    }

    protected function getAct($status, $data)
    {
        $linkToDocument = '';
        $actId = $data['act_create_id'] ?? '';

        if ($actId && $status == 'ready') {
            try {
                if (!is_object($this->GetAct)) {
                    throw new SystemException("GetAct object don`t available");
                }

                $result = $this->GetAct->apiLaunch($data);
                $pdf = ($result != 'error') ? $result : '';
                if ($pdf) {
                    $linkToDocument = $this->createPdfAndGetLink($actId, $pdf);
                }
            } catch (SystemException $exception) {
                $this->exceptionHandler($exception);
            }
        }

        return $linkToDocument;
    }

    protected function createPdfAndGetLink($actId, $pdf)
    {
        $path = "/upload/wbs24.ozonapinew/acts/";
        $fileName = "ozon_act_".$actId.".pdf";
        $pathWithRoot = $_SERVER['DOCUMENT_ROOT'].$path;
        $linkToDocument = '';

        if (!file_exists($pathWithRoot)) mkdir($pathWithRoot, 0755, true);
        $handle = @fopen($pathWithRoot.$fileName, "w");
        if ($handle) {
            $linkToDocument = $path.$fileName;
            fwrite($handle, $pdf);
            fclose($handle);
        }

        return $linkToDocument;
    }

    protected function setActForIncludedOrders($data, $linkToDocument)
    {
        if (!$linkToDocument) return;

        $includedExternalIds = $data['result']['added_to_act'] ?? [];

        foreach ($includedExternalIds as $externalId) {
            if ($externalId == $data['external_id']) continue;

            $this->OrdersState->setCreatedActId(
                $externalId,
                $data['act_create_id'],
                'true',
            );

            $this->OrdersState->setStatusAct(
                $externalId,
                'ready',
            );

            $this->OrdersState->setAct(
                $externalId,
                $linkToDocument,
            );
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit