Advertisement
Guest User

Untitled

a guest
Jun 25th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.1.0.0
  8. * @ Author : DeZender
  9. * @ Release on : 15.05.2020
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class WebOrder
  15. {
  16. public $provider;
  17. public $tsService;
  18. public $positions;
  19. public $buffer = [];
  20. public $mode;
  21. public $aviable = false;
  22. public $options = [];
  23. protected $positionApi;
  24. protected $interface;
  25.  
  26. public function __construct($provider, $positions, $mode)
  27. {
  28. global $_interface;
  29. $this->interface = $_interface;
  30. $this->positionApi = System\Application\App::app()->api->position;
  31. $this->provider = $provider;
  32. $this->positions = $positions;
  33. $this->mode = $mode;
  34. $this->debug = false;
  35. $this->tsService = &WarTradesoftService::getInstance();
  36. $this->loadOptions();
  37. $debug = isset($_REQUEST['__DEBUG_MODE']) && ($_REQUEST['__DEBUG_MODE'] === 'GGNORE');
  38. $systemCheck = isset($_REQUEST['systemCheck']) && ($_REQUEST['systemCheck'] == 1);
  39. if ($debug || $systemCheck) {
  40. $this->debug = true;
  41. }
  42. }
  43.  
  44. public function loadOptions()
  45. {
  46. $default = [
  47. 'wsQuantityControl' => 'divide',
  48. 'wsDivideState' => 4,
  49. 'wsProvderComment' => 0,
  50. 'wsLogLevel' => 1,
  51. 'wsExcludeState' => [],
  52. 'wsChangeClientState' => 1,
  53. 'wsTimeLimit' => 50,
  54. 'woCancelState' => '',
  55. 'woUpdatePosState' => '',
  56. 'woCompareAction' => 'dontChange',
  57. 'woDivergenceRateMin' => 0,
  58. 'woDivergenceRateMax' => 0,
  59. 'woCommentTemplate' => '',
  60. 'woReferenceTemplate' => '{pst_client_ref}',
  61. 'woDivideRule' => '',
  62. 'woOrderNumberTemplate' => '',
  63. 'woOrderCommentTemplate' => '',
  64. 'woAutoStates' => [],
  65. 'woTimeLimit' => 50,
  66. 'woDivergenceTermMin' => '',
  67. 'woDivergenceTermMax' => '',
  68. 'woSortResultsColumn' => 'price'
  69. ];
  70.  
  71. foreach ($default as $id => $opt) {
  72. $value = $this->tsService->getOption($id, $opt);
  73. if ((is_array($value) && empty($value)) || (!is_array($value) && (strlen($value) == 0))) {
  74. $this->tsService->setOption($id, $opt);
  75. $value = $opt;
  76. }
  77.  
  78. $this->options[$id] = $value;
  79. }
  80. }
  81.  
  82. public function getOption($id)
  83. {
  84. if ((is_array($id) && empty($id)) || (strlen($id) == 0)) {
  85. return '';
  86. }
  87.  
  88. return $this->options[$id];
  89. }
  90.  
  91. public function addLog($id, $level, $area, $msg)
  92. {
  93. if ($level <= $this->getOption('wsLogLevel')) {
  94. $this->tsService->addLog(['provider' => $this->provider, 'area' => $area, 'level' => $level, 'id' => $id, 'desc' => $msg]);
  95. }
  96.  
  97. $this->webAnswer($msg);
  98. }
  99.  
  100. public function substitute($str, $data)
  101. {
  102. preg_match_all('/{([^}]*)}/i', $str, $replaces);
  103.  
  104. if (!empty($replaces[1])) {
  105. foreach ($replaces[1] as $name) {
  106. if ($name == 'ord_code') {
  107. $data['ord_code'] = $this->interface->getDocumentNumber($data['ord_dcm_id']);
  108. }
  109.  
  110. if (array_key_exists($name, $data)) {
  111. $str = str_replace('{' . $name . '}', (string) $data[$name], $str);
  112. }
  113. }
  114. }
  115.  
  116. return trim($str);
  117. }
  118.  
  119. public function changeState($pstId, $refId, $stateId)
  120. {
  121. if (empty($stateId)) {
  122. return false;
  123. }
  124.  
  125. $level = $this->getOption('wsChangeClientState');
  126. $this->interface->adapter->change_db(DB_AUTO_RESOURCE);
  127. $res = $this->positionApi->DBchangeState($pstId, $stateId, $level, 0, true);
  128.  
  129. if (empty($res)) {
  130. return true;
  131. }
  132. else {
  133. $this->addLog($pstId, 1, 'web_order', 'Ref ' . $refId . '. ' . tr('Не удалось сменить состояние', 'web_order') . '.');
  134. return false;
  135. }
  136. }
  137.  
  138. public function webError($msg)
  139. {
  140. $this->aviable = false;
  141.  
  142. if ($this->mode == 'buffer') {
  143. $this->webAnswer('<div class=\'error\'>' . $msg . '</div>');
  144. }
  145. else {
  146. $this->webAnswer($msg);
  147. }
  148. }
  149.  
  150. public function echoData($msg)
  151. {
  152. echo $msg;
  153. }
  154.  
  155. public function webAnswer($msg)
  156. {
  157. switch ($this->mode) {
  158. case 'buffer':
  159. $this->buffer[] = '<div>' . $msg . '</div>';
  160. break;
  161. case 'json':
  162. $data = json_encode($msg);
  163.  
  164. if (!$this->debug) {
  165. ob_clean();
  166. ob_end_clean();
  167. }
  168.  
  169. return $data;
  170. case 'array':
  171. $this->buffer = $msg;
  172. break;
  173. case 'flush':
  174. $this->echoData('<div>' . $msg . '</div>');
  175. break;
  176. }
  177. }
  178.  
  179. public function getResults()
  180. {
  181. return $this->buffer;
  182. }
  183.  
  184. public function setState($itemId, $state, $params = [])
  185. {
  186. $val = $val2 = $header = '';
  187.  
  188. if (!empty($params)) {
  189. foreach ($params as $field => $value) {
  190. $header .= ', `' . $field . '`';
  191. $val2 .= ', ' . $field . ' = \'' . $value . '\'';
  192. $val .= ', \'' . $value . '\'';
  193. }
  194. }
  195.  
  196. $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;
  197. $this->interface->adapter->query($query);
  198.  
  199. if (isset($this->responce)) {
  200. $this->setResponce($itemId, 'status', $state);
  201. }
  202. }
  203.  
  204. public function isSytemRequest()
  205. {
  206. return $this->interface->cmsApi->isUserRoot();
  207. }
  208.  
  209. public function cleanBrand($str)
  210. {
  211. $str = html_entity_decode($str);
  212. $str = $this->interface->__parseBrand($str);
  213. ...................................................................................
  214. ..........................................
  215. ....................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement