1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
calculator.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Delivery\Pecom;
4
10{
11 protected $arConfig = array();
12 protected $arOrder = array();
13 protected $profileId = "";
14 protected $packsCount = 0;
15
21 public function __construct($arOrder, $arConfig, $profileId = "")
22 {
23 $this->arOrder = $arOrder;
24 $this->arConfig = $arConfig;
25 $this->profileId = $profileId;
26 }
27
32 public function getCompabilityInfo()
33 {
34 $arResult = array();
35
37 $jsonInfo = $this->send($params);
38 $arInfo = json_decode($jsonInfo, true);
39
40 if(isset($arInfo["auto"]))
41 $arResult[] = "auto";
42
43 if(isset($arInfo["avia"]))
44 $arResult[] = "avia";
45
46 return $arResult;
47 }
48
53 public function getPriceInfo()
54 {
55 try
56 {
57 $strParams = $this->createCalcParams();
58 $jsonInfo = $this->send($strParams);
59 $result = $this->parseCalcResult($jsonInfo);
60
61
62 }
63 catch(\Exception $e)
64 {
65 $result = array(
66 'RESULT' => 'ERROR',
67 'TEXT' => $e->getMessage()
68 );
69 }
70
71 return $result;
72 }
73
74 protected function parseCalcResult($jsonInfo)
75 {
76 global $APPLICATION;
77 $arInfo = json_decode($jsonInfo,true);
78
79 if(is_array($arInfo) && !empty($arInfo))
80 {
81 if(isset($arInfo[$this->profileId][2]))
82 {
83 $price = 0;
84
85 $price += intval($arInfo[$this->profileId][2]);
86
87 if(isset($arInfo["take"][2]) && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED'))
88 $price += intval($arInfo["take"][2]);
89
90
91 if(isset($arInfo["deliver"][2]) && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED'))
92 $price += intval($arInfo["deliver"][2]);
93
94 foreach($arInfo as $key => $value)
95 if(mb_substr($key, 0, 3) == "ADD")
96 $price += intval($arInfo[$key][2]);
97
99 'RESULT' => 'OK',
100 'VALUE' => $price,
101 'PACKS_COUNT' => $this->packsCount
102 );
103
104 $period = "";
105
106 if($this->profileId == "auto" && !empty($arInfo["periods"]))
107 $period = $arInfo["periods"];
108 elseif($this->profileId == "avia" && !empty($arInfo["aperiods"]))
109 $period = $arInfo["aperiods"];
110
111 if($period <> '')
112 {
113 $pos = mb_strpos($period, ':');
114
115 if($pos !== false)
116 {
117 $CBXSanitizer = new \CBXSanitizer;
118 $CBXSanitizer->DelAllTags();
119 $arResult["TRANSIT"] = " (".GetMessage("SALE_DH_PECOM_PERIOD_DAYS").") ".$CBXSanitizer->SanitizeHtml(mb_substr($period, $pos + 1));
120 }
121 }
122 }
123 else
124 {
125 if(isset($arInfo["error"]))
126 {
127 $error = implode("<br>", $arInfo["error"]);
128 }
129 else
130 {
131 $error = GetMessage("SALE_DH_PECOM_ERROR");
132 }
133
135 'RESULT' => 'ERROR',
136 'TEXT' => $error
137 );
138 }
139 }
140 else
141 {
143 'RESULT' => 'ERROR',
144 'TEXT' => GetMessage("SALE_DH_PECOM_ERROR_NO_RESULTS")
145 );
146 }
147
148 return $arResult;
149 }
150
151 protected static function send($strParams)
152 {
153 $http = new \Bitrix\Main\Web\HttpClient(array(
154 "version" => "1.1",
155 "socketTimeout" => 30,
156 "streamTimeout" => 30,
157 "redirect" => true,
158 "redirectMax" => 5,
159 "disableSslVerification" => true
160 ));
161
162 $jsnData = $http->get("http://calc.pecom.ru/bitrix/components/pecom/calc/ajax.php?".$strParams);
163
164 $errors = $http->getError();
165
166 if (!$jsnData && !empty($errors))
167 {
168 $strError = "";
169
170 foreach($errors as $errorCode => $errMes)
171 $strError .= $errorCode.": ".$errMes;
172
174 "SEVERITY" => "ERROR",
175 "AUDIT_TYPE_ID" => "SALE_DELIVERY",
176 "MODULE_ID" => "sale",
177 "ITEM_ID" => "PECOM_CALCULATOR_SEND",
178 "DESCRIPTION" => $strError,
179 ));
180 }
181
182
183 return $jsnData;
184 }
185
186 protected function createCompParamsStr()
187 {
188 $arLocation = Adapter::mapLocation($this->arOrder["LOCATION_TO"]);
189
190 if(count($arLocation) > 0)
191 {
192 $params = 'places[0][]=1'.
193 '&places[0][]=1'.
194 '&places[0][]=1'.
195 '&places[0][]=1'.
196 '&places[0][]=1'.
197 '&places[0][]=1'.
198 '&places[0][]=0'.
199 '&take[town]='.$this->arConfig["CITY_DELIVERY"]["VALUE"].
200 '&take[tent]=0'.
201 '&take[gidro]=0'.
202 '&take[speed]=0'.
203 '&take[moscow]=0'.
204 '&deliver[town]='.strval(key($arLocation)).
205 '&deliver[tent]=0'.
206 '&delideliver[gidro]=0'.
207 '&deliver[speed]=0'.
208 '&deliver[moscow]=0'.
209 '&plombir=0'.
210 '&strah=0'.
211 '&ashan=0';
212 }
213 else
214 {
215 $params = "";
216 }
217
218 return $params;
219 }
220
221 protected function createCalcParams()
222 {
223 if(!isset($this->arOrder["WEIGHT"]))
224 throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_WEIGHT"));
225
226 $locationTo = "";
227 $arLocation = Adapter::mapLocation($this->arOrder["LOCATION_TO"]);
228
229 if(empty($arLocation))
230 throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_EMPTY_LOCATION"));
231
232 if(count($arLocation) > 1 && isset($this->arOrder["EXTRA_PARAMS"]["location"]))
233 {
234 $locationTo = $this->arOrder["EXTRA_PARAMS"]["location"];
235 }
236 elseif (count($arLocation) > 1 && !isset($this->arOrder["EXTRA_PARAMS"]["location"]))
237 {
238 throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_MANY_LOCATIONS"));
239 }
240
241 if(count($arLocation) == 1)
242 {
243 $locationTo = key($arLocation);
244 }
245
246 if(!isset($this->arOrder["ITEMS"]) || !is_array($this->arOrder["ITEMS"]) || empty($this->arOrder["ITEMS"]))
247 throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_EMPTY_ITEMS"));
248
249 $measureCoeff = 1000;
250 $itemsStr = "";
251 $loadingRange = true;
252 $rigidPacking = \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_OTHER_RIGID_PACKING');
253
254 $arPacks = \CSaleDeliveryHelper::getBoxesFromConfig($this->profileId, $this->arConfig);
255
256 $arPackagesParams = \CSaleDeliveryHelper::getRequiredPacks(
257 $this->arOrder["ITEMS"],
258 $arPacks,
259 0);
260
261 $this->packsCount = count($arPackagesParams);
262
263 for($i = $this->packsCount-1; $i >= 0; $i--)
264 {
265 $item = $arPackagesParams[$i];
266 $width = round(floatval($item["DIMENSIONS"]["WIDTH"])/$measureCoeff, 2);
267 $lenght = round(floatval($item["DIMENSIONS"]["LENGTH"])/$measureCoeff, 2);
268 $height = round(floatval($item["DIMENSIONS"]["HEIGHT"])/$measureCoeff, 2);
269 $volume = floatval($item["VOLUME"]/(pow($measureCoeff,3)));
270
274 || $item["WEIGHT"] > \CDeliveryPecom::$EXTRA_DEMENSIONS_WEIGHT
275 )
276 $loadingRange = false;
277
278 if($itemsStr <> '')
279 $itemsStr .='&';
280
281 $itemsStr .= 'places['.$i.'][]='.strval($width).
282 '&places['.$i.'][]='.strval($lenght).
283 '&places['.$i.'][]='.strval($height).
284 '&places['.$i.'][]='.strval($volume).
285 '&places['.$i.'][]='.strval($item["WEIGHT"]/1000).
286 '&places['.$i.'][]='.($loadingRange ? '1' : '0').
287 '&places['.$i.'][]='.($rigidPacking && \CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_RIGID_PAYER') == \CDeliveryPecom::$PAYER_BUYER ? '1' : '0');
288 }
289
290 if(\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_OTHER_PLOMBIR_ENABLE') && \CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_PLOMBIR_PAYER') == \CDeliveryPecom::$PAYER_BUYER)
291 $plombir = strval(intval(\CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_PLOMBIR_COUNT')));
292 else
293 $plombir = "0";
294
295 if(\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_OTHER_INSURANCE') && \CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_INSURANCE_PAYER') == \CDeliveryPecom::$PAYER_BUYER)
296 $insurance = strval($this->arOrder["PRICE"]);
297 else
298 $insurance = "0";
299
300 $result = $itemsStr.
301 '&take[town]='.$this->arConfig["CITY_DELIVERY"]["VALUE"].
302 '&take[tent]='.(\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_TENT_ENABLED') ? '1' : '0').
303 '&take[gidro]='.(\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_HYDRO_ENABLED') ? '1' : '0').
304 '&take[speed]=0'.
305 '&take[moscow]=0'.
306 '&deliver[town]='.$locationTo.
307 '&deliver[tent]='.(\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_TENT_ENABLED') ? '1' : '0').
308 '&delideliver[gidro]='.(\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_HYDRO_ENABLED') ? '1' : '0').
309 '&deliver[speed]=0'.
310 '&deliver[moscow]=0'.
311 '&plombir='.$plombir.
312 '&strah='.$insurance.
313 '&ashan=0';
314
315 return $result;
316 }
317}
global $APPLICATION
Определения include.php:80
$arResult
Определения generate_coupon.php:16
static mapLocation($locationId, $cleanCache=false)
Определения adapter.php:201
parseCalcResult($jsonInfo)
Определения calculator.php:74
static send($strParams)
Определения calculator.php:151
__construct($arOrder, $arConfig, $profileId="")
Определения calculator.php:21
static $EXTRA_DEMENSIONS_WEIGHT
Определения delivery_pecom.php:33
static $PAYER_BUYER
Определения delivery_pecom.php:37
static getConfValue(&$arConfig, $key)
Определения delivery_pecom.php:480
static $EXTRA_DIMENSIONS_SIZE
Определения delivery_pecom.php:34
static isConfCheckedVal(&$arConfig, $key)
Определения delivery_pecom.php:485
static Add($arFields)
Определения event_log.php:44
static getRequiredPacks(&$arItems, $arPacks, $maxWeight, $reservedSpace=0.15)
Определения delivery_helper.php:204
static getBoxesFromConfig($profile, &$arConfig)
Определения delivery_helper.php:447
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$errors
Определения iblock_catalog_edit.php:74
$strError
Определения options_user_settings.php:4
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$width
Определения html.php:68
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$arLocation['REGION_NAME']
Определения options.php:2800
$error
Определения subscription_card_product.php:20