Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @ This file is created by http://DeZender.Net
- * @ deZender (PHP7 Decoder for ionCube Encoder)
- *
- * @ Version : 4.1.0.0
- * @ Author : DeZender
- * @ Release on : 15.05.2020
- * @ Official site : http://DeZender.Net
- *
- */
- class WebOrder
- {
- public $provider;
- public $tsService;
- public $positions;
- public $buffer = [];
- public $mode;
- public $aviable = false;
- public $options = [];
- protected $positionApi;
- protected $interface;
- public function __construct($provider, $positions, $mode)
- {
- global $_interface;
- $this->interface = $_interface;
- $this->positionApi = System\Application\App::app()->api->position;
- $this->provider = $provider;
- $this->positions = $positions;
- $this->mode = $mode;
- $this->debug = false;
- $this->tsService = &WarTradesoftService::getInstance();
- $this->loadOptions();
- $debug = isset($_REQUEST['__DEBUG_MODE']) && ($_REQUEST['__DEBUG_MODE'] === 'GGNORE');
- $systemCheck = isset($_REQUEST['systemCheck']) && ($_REQUEST['systemCheck'] == 1);
- if ($debug || $systemCheck) {
- $this->debug = true;
- }
- }
- public function loadOptions()
- {
- $default = [
- 'wsQuantityControl' => 'divide',
- 'wsDivideState' => 4,
- 'wsProvderComment' => 0,
- 'wsLogLevel' => 1,
- 'wsExcludeState' => [],
- 'wsChangeClientState' => 1,
- 'wsTimeLimit' => 50,
- 'woCancelState' => '',
- 'woUpdatePosState' => '',
- 'woCompareAction' => 'dontChange',
- 'woDivergenceRateMin' => 0,
- 'woDivergenceRateMax' => 0,
- 'woCommentTemplate' => '',
- 'woReferenceTemplate' => '{pst_client_ref}',
- 'woDivideRule' => '',
- 'woOrderNumberTemplate' => '',
- 'woOrderCommentTemplate' => '',
- 'woAutoStates' => [],
- 'woTimeLimit' => 50,
- 'woDivergenceTermMin' => '',
- 'woDivergenceTermMax' => '',
- 'woSortResultsColumn' => 'price'
- ];
- foreach ($default as $id => $opt) {
- $value = $this->tsService->getOption($id, $opt);
- if ((is_array($value) && empty($value)) || (!is_array($value) && (strlen($value) == 0))) {
- $this->tsService->setOption($id, $opt);
- $value = $opt;
- }
- $this->options[$id] = $value;
- }
- }
- public function getOption($id)
- {
- if ((is_array($id) && empty($id)) || (strlen($id) == 0)) {
- return '';
- }
- return $this->options[$id];
- }
- public function addLog($id, $level, $area, $msg)
- {
- if ($level <= $this->getOption('wsLogLevel')) {
- $this->tsService->addLog(['provider' => $this->provider, 'area' => $area, 'level' => $level, 'id' => $id, 'desc' => $msg]);
- }
- $this->webAnswer($msg);
- }
- public function substitute($str, $data)
- {
- preg_match_all('/{([^}]*)}/i', $str, $replaces);
- if (!empty($replaces[1])) {
- foreach ($replaces[1] as $name) {
- if ($name == 'ord_code') {
- $data['ord_code'] = $this->interface->getDocumentNumber($data['ord_dcm_id']);
- }
- if (array_key_exists($name, $data)) {
- $str = str_replace('{' . $name . '}', (string) $data[$name], $str);
- }
- }
- }
- return trim($str);
- }
- public function changeState($pstId, $refId, $stateId)
- {
- if (empty($stateId)) {
- return false;
- }
- $level = $this->getOption('wsChangeClientState');
- $this->interface->adapter->change_db(DB_AUTO_RESOURCE);
- $res = $this->positionApi->DBchangeState($pstId, $stateId, $level, 0, true);
- if (empty($res)) {
- return true;
- }
- else {
- $this->addLog($pstId, 1, 'web_order', 'Ref ' . $refId . '. ' . tr('Не удалось сменить состояние', 'web_order') . '.');
- return false;
- }
- }
- public function webError($msg)
- {
- $this->aviable = false;
- if ($this->mode == 'buffer') {
- $this->webAnswer('<div class=\'error\'>' . $msg . '</div>');
- }
- else {
- $this->webAnswer($msg);
- }
- }
- public function echoData($msg)
- {
- echo $msg;
- }
- public function webAnswer($msg)
- {
- switch ($this->mode) {
- case 'buffer':
- $this->buffer[] = '<div>' . $msg . '</div>';
- break;
- case 'json':
- $data = json_encode($msg);
- if (!$this->debug) {
- ob_clean();
- ob_end_clean();
- }
- return $data;
- case 'array':
- $this->buffer = $msg;
- break;
- case 'flush':
- $this->echoData('<div>' . $msg . '</div>');
- break;
- }
- }
- public function getResults()
- {
- return $this->buffer;
- }
- public function setState($itemId, $state, $params = [])
- {
- $val = $val2 = $header = '';
- if (!empty($params)) {
- foreach ($params as $field => $value) {
- $header .= ', `' . $field . '`';
- $val2 .= ', ' . $field . ' = \'' . $value . '\'';
- $val .= ', \'' . $value . '\'';
- }
- }
- $query = 'INSERT INTO ' . DB_AUTO_RESOURCE . '.position_web (`pst_id`, `pst_status`, `pst_www_id`' . $header . ')' . "\n\t\t\t\t\t\t" . 'VALUES (\'' . $itemId . '\', \'' . $state . '\', \'' . $this->provider . '\'' . $val . ')' . "\n\t\t\t\t\t" . 'ON DUPLICATE KEY UPDATE pst_status = \'' . $state . '\'' . $val2;
- $this->interface->adapter->query($query);
- if (isset($this->responce)) {
- $this->setResponce($itemId, 'status', $state);
- }
- }
- public function isSytemRequest()
- {
- return $this->interface->cmsApi->isUserRoot();
- }
- public function cleanBrand($str)
- {
- $str = html_entity_decode($str);
- $str = $this->interface->__parseBrand($str);
- ...................................................................................
- ..........................................
- ....................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement