1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
adapter.php
См. документацию.
1<?php
2
5
11{
12 public static function preparePreregistrationReqData($arOrder, $profileId, $arConfig)
13 {
14 $result = array();
15 $result["sender"] = array(
16 "inn" => $arConfig["INN"]["VALUE"],
17 "city" => static::getFilialAndCity($arConfig["CITY_DELIVERY"]["VALUE"]),
18 "title" => $arConfig["NAME"]["VALUE"],
19 "phone" => $arConfig["PHONE"]["VALUE"],
20 );
21
22 $inn = "";
23 $city = "";
24 $title = "";
25 $phone = "";
26 $address = "";
27
28 if(isset($extraParams["location"]))
29 $city = $extraParams["location"];
30
31 $dbOrderProps = \CSaleOrderPropsValue::GetOrderProps($arOrder["ID"]);
32
33 while ($arOrderProps = $dbOrderProps->Fetch())
34 {
35 if($arOrderProps["CODE"] == "COMPANY" || $arOrderProps["CODE"] == "FIO")
36 $title = $arOrderProps["VALUE"];
37
38 if($arOrderProps["CODE"] == "INN")
39 $inn = $arOrderProps["VALUE"];
40
41 if($arOrderProps["CODE"] == "PHONE")
42 $phone = $arOrderProps["VALUE"];
43
44 if($arOrderProps["CODE"] == "LOCATION")
45 {
46 $location = $arOrderProps["VALUE"];
47 $locDelivery = Adapter::mapLocation($location); // todo: if more than one
48 $city = static::getFilialAndCity(key($locDelivery));
49 }
50
51 if($arOrderProps["CODE"] == "ADDRESS")
52 $address = $arOrderProps["VALUE"];
53 }
54
55 $arPacks = \CSaleDeliveryHelper::getBoxesFromConfig($profileId, $arConfig);
56
58 $arOrder["ITEMS"],
59 $arPacks,
60 0);
61
62 $result["cargos"] = array(
63 array(
64 "common" => array(
65 "positionsCount" => count($arPackagesParams),
66 "decription" => GetMessage("SALE_DH_PECOM_DESCRIPTION_GOODS"),
67 "orderNumber" => $arOrder["ACCOUNT_NUMBER"],
68 "paymentForm" => $arConfig["PAYMENT_FORM"]["VALUE"],
69 "accompanyingDocuments" => false
70 ),
71 "receiver" => array(
72 "inn" => $inn,
73 "city" => $city,
74 "title" => $title,
75 "phone" => $phone,
76 "addressStock" => $address
77 ),
78 "services" => array(
79
80 "transporting" =>array(
81 "payer" => array(
82 "type" => 1
83 )
84 ),
85
86 "hardPacking" => array(
87 "enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_RIGID_PACKING'),
88 "payer" => array(
89 "type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_RIGID_PAYER')
90 )
91 ),
92
94 "palletTransporting" => array(
95 "enabled" => !\CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_RIGID_PACKING') && \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_PALLETE'),
96 "payer" => array(
97 "type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_PALLETE_PAYER')
98 )
99 ),
100
101 "insurance" => array(
102 "enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_INSURANCE'),
103 "payer" => array(
104 "type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_INSURANCE_PAYER')
105 ),
106 "cost" => intval($arOrder["PRICE"])
107 ),
108
109 "sealing" => array(
110 "enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_PLOMBIR_ENABLE'),
111 "payer" => array(
112 "type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_PLOMBIR_PAYER')
113 )
114 ),
115
116 "strapping" => array(
117 "enabled" => false
118 ),
119
120 "documentsReturning" => array(
121 "enabled" => false
122 ),
123
124 "delivery" => array(
125 "enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_DELIVERY_ENABLED'),
126 "payer" => array(
127 "type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_DELIVERY_PAYER')
128 )
129 )
130 )
131 )
132 );
133
134 return $result;
135 }
136
137 protected static function getUpperCityId($locationId)
138 {
139 if($locationId == '')
140 return 0;
141
142 $res = LocationTable::getList(array(
143 'filter' => array(
144 array(
145 'LOGIC' => 'OR',
146 '=CODE' => $locationId,
147 '=ID' => $locationId
148 ),
149 '=PARENTS.TYPE.CODE' => 'CITY',
150 ),
151 'select' => array(
152 'ID', 'CODE',
153 'PID' => 'PARENTS.ID',
154 )
155 ));
156
157 if($loc = $res->fetch())
158 return $loc['PID'];
159
160 return 0;
161 }
162
163 protected static function mapLocation2($internalLocationId)
164 {
165 if(intval($internalLocationId) <=0)
166 return array();
167
168 static $result = array();
169
170 if(!isset($result[$internalLocationId]))
171 {
172 $result[$internalLocationId] = array();
173
174 $internalLocation = \CSaleHelper::getLocationByIdHitCached($internalLocationId);
175 $externalId = Location::getExternalId($internalLocationId);
176
177 //Let's try to find upper city
178 if($externalId == '')
179 {
180 $cityId = self::getUpperCityId($internalLocationId);
181 $externalId = Location::getExternalId($cityId);
182 }
183
184 if($externalId <> '')
185 {
186 $result[$internalLocationId] = array(
187 $externalId => !empty($internalLocation["CITY_NAME_LANG"]) ? $internalLocation["CITY_NAME_LANG"] : ""
188 );
189 }
190 }
191
192 return $result[$internalLocationId];
193 }
194
201 public static function mapLocation($locationId, $cleanCache = false)
202 {
204 return self::mapLocation2($locationId);
205
206 $cityName = static::getCityNameFromLocationId($locationId);
207
208 if(!$cityName)
209 return array();
210
211 $ttl = 2592000;
212 $cacheId = "SaleDeliveryPecomMapLocations".$locationId;
213 $data = array();
214
215 $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
216
217 if($cleanCache)
218 {
219 $cacheManager->clean($cacheId);
220 }
221
222 if($cacheManager->read($ttl, $cacheId))
223 {
224 $data = $cacheManager->get($cacheId);
225 }
226
227 if(empty($data))
228 {
229 $pecCities = static::getAllPecomCities();
230 $data = array();
231
232 foreach($pecCities as $key => $cities)
233 {
234 foreach($cities as $smallCityKey => $smallCityName)
235 {
236 $pos = mb_strpos($smallCityName, $cityName);
237 if($pos !== false
238 && (
239 mb_strlen($cityName) == mb_strlen($smallCityName)
240 || (
241 mb_substr($smallCityName, $pos + mb_strlen($cityName), 1) == " "
242 && (
243 $pos == 0
244 || mb_substr($smallCityName, $pos - 1, 1) == " "
245 )
246 )
247 )
248 )
249 {
250 $data[$smallCityKey] = $smallCityName;
251 }
252 }
253 }
254
255 $cacheManager->set($cacheId, $data);
256 }
257
258 return $data;
259 }
260
261 public static function getAllPecomCities($cleanCache = false)
262 {
263 global $APPLICATION;
264 $ttl = 2592000;
265 $data = array();
266 $cacheId = "SaleDeliveryPecomCities";
267
268 $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
269
270 if($cleanCache)
271 {
272 $cacheManager->clean($cacheId);
273 }
274
275 if($cacheManager->read($ttl, $cacheId))
276 {
277 $data = $cacheManager->get($cacheId);
278 }
279
280 if(empty($data))
281 {
282 $http = new \Bitrix\Main\Web\HttpClient(array(
283 "version" => "1.1",
284 "socketTimeout" => 30,
285 "streamTimeout" => 30,
286 "redirect" => true,
287 "redirectMax" => 5,
288 "disableSslVerification" => true
289 ));
290
291 $jsnData = $http->get("https://www.pecom.ru/ru/calc/towns.php");
292 $errors = $http->getError();
293
294 if (!$jsnData && !empty($errors))
295 {
296 $strError = "";
297
298 foreach($errors as $errorCode => $errMes)
299 $strError .= $errorCode.": ".$errMes;
300
302 "SEVERITY" => "ERROR",
303 "AUDIT_TYPE_ID" => "SALE_DELIVERY",
304 "MODULE_ID" => "sale",
305 "ITEM_ID" => "PECOM_GET_TOWNS",
306 "DESCRIPTION" => $strError,
307 ));
308 }
309
310 $data = json_decode($jsnData, true);
311
312 if(!is_array($data))
313 $data = array();
314
315 $cacheManager->set($cacheId, $data);
316 }
317
318 return $data;
319 }
320
321 public static function getCityNameFromLocationId($locationId)
322 {
323 $loc = \CSaleLocation::GetById($locationId);
324 return isset($loc["CITY_NAME_LANG"]) ? $loc["CITY_NAME_LANG"] : false;
325 }
326
327 public static function getFilialAndCity($cityId)
328 {
329 $result = false;
330 $ttl = 2592000;
331 $cacheId = "SaleDeliveryPecomFilialAndCity".$cityId;
332 $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache();
333
334 if($cityId <> '')
335 {
336 if($cacheManager->read($ttl, $cacheId))
337 {
338 $result = $cacheManager->get($cacheId);
339 }
340 else
341 {
342 $locations = static::getAllPecomCities();
343 foreach($locations as $filial => $cities)
344 {
345 foreach($cities as $cId => $city)
346 {
347 if($cityId == $cId)
348 {
349 $result = $filial;
350
351 if($filial != $city)
352 {
353 $arCity = explode(" ", $city);
354 $result .= " ".$arCity[0];
355 }
356
357 break;
358 }
359 }
360 }
361
362 $cacheManager->set($cacheId, $result);
363 }
364 }
365
366 return $result;
367 }
368
369 public static function prepareSubscribeReqData($arCargoCodes, $email = "", $phone = "")
370 {
371 $arData = array();
372
373 if(is_array($arCargoCodes) && !empty($arCargoCodes) && ($email <> '' || $phone <> ''))
374 {
375 $arData["cargoCodes"] = $arCargoCodes;
376
377 if($email <> '')
378 $arData["email"] = $email;
379
380 if($phone <> '')
381 $arData["phone"] = $phone;
382 }
383
384 return $arData;
385 }
386}
global $APPLICATION
Определения include.php:80
static getInstance()
Определения application.php:98
static getExternalId($locationId)
Определения externallocationmap.php:73
static prepareSubscribeReqData($arCargoCodes, $email="", $phone="")
Определения adapter.php:369
static preparePreregistrationReqData($arOrder, $profileId, $arConfig)
Определения adapter.php:12
static getCityNameFromLocationId($locationId)
Определения adapter.php:321
static mapLocation($locationId, $cleanCache=false)
Определения adapter.php:201
static getUpperCityId($locationId)
Определения adapter.php:137
static getAllPecomCities($cleanCache=false)
Определения adapter.php:261
static mapLocation2($internalLocationId)
Определения adapter.php:163
static getFilialAndCity($cityId)
Определения adapter.php:327
static GetOrderProps($ORDER_ID)
Определения order_props_values.php:149
static getConfValue(&$arConfig, $key)
Определения delivery_pecom.php:480
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
static getLocationByIdHitCached($id)
Определения helper.php:462
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$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
$email
Определения payment.php:49
if(empty($signedUserToken)) $key
Определения quickway.php:257
</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
$title
Определения pdf.php:123
$location
Определения options.php:2729