1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
delivery_2_pay_system.php
См. документацию.
1<?
2
3use \Bitrix\Sale\Internals\DeliveryPaySystemTable;
4use \Bitrix\Sale\Delivery;
5
7{
8 public static $arFirstDS = array();
9 public static $arFirstPS = array();
10
11 protected static function convertDeliveryIds($oldDeliveryIds = array(), $oldProfiles = array())
12 {
13 if(!is_array($oldDeliveryIds))
14 $oldDeliveryIds = trim(strval($oldDeliveryIds)) != "" ? array($oldDeliveryIds) : array();
15
16 if(!is_array($oldProfiles))
17 $oldProfiles = trim(strval($oldProfiles)) != "" ? array($oldProfiles) : array();
18
19 if(empty($oldDeliveryIds) && empty($oldProfiles))
20 return array();
21
22 $qParams = array(
23 "LOGIC" => "AND",
24 );
25
26 if(!empty($oldDeliveryIds))
27 {
28 $params = array (
29 "LOGIC" => "OR",
30 "%CODE" => array()
31 );
32
33 foreach($oldDeliveryIds as $id)
34 {
35 $params["%CODE"][] = $id.":";
36 $params["%CODE"][] = $id;
37 }
38
39 $qParams[] = $params;
40 }
41
42 if(!empty($oldProfiles))
43 {
44 $params = array (
45 "LOGIC" => "OR",
46 "%CODE" => array()
47 );
48
49 foreach($oldProfiles as $id)
50 $params["%CODE"][] = ":".$id;
51
52 $qParams[] = $params;
53 }
54
55 $res = Delivery\Services\Table::getList(array(
56 'filter' => $qParams,
57 'select' => array("ID")
58 ));
59
60 $result = array();
61
62 while($delivery = $res->fetch())
63 $result[] = $delivery["ID"];
64
65 return $result;
66 }
67
68 public static function GetList($arFilter = array(), $arGroupBy = false, $arSelectFields = array())
69 {
70 $params = array();
71
72 if(is_array($arFilter) && !empty($arFilter))
73 {
74 if(isset($arFilter["DELIVERY_ID"]) || $arFilter["DELIVERY_PROFILE_ID"])
75 {
77 isset($arFilter["DELIVERY_ID"]) ? $arFilter["DELIVERY_ID"] : array(),
78 isset($arFilter["DELIVERY_PROFILE_ID"]) ? $arFilter["DELIVERY_PROFILE_ID"] : array()
79 );
80
81 if(!empty($ids))
82 $arFilter["=DELIVERY_ID"] = $ids;
83
84 unset($arFilter["DELIVERY_ID"]);
85 unset($arFilter["DELIVERY_PROFILE_ID"]);
86 }
87
88 if(isset($arFilter["PAYSYSTEM_ID"]))
89 {
90 $arFilter["=PAYSYSTEM_ID"] = $arFilter["PAYSYSTEM_ID"];
91 unset($arFilter["PAYSYSTEM_ID"]);
92 }
93
94 $params['filter'] = $arFilter;
95 }
96
97 //todo:
98 if(is_array($arGroupBy) && !empty($arGroupBy))
99 $params['group'] = array_intersect($arGroupBy, array("DELIVERY_ID", "PAYSYSTEM_ID"));
100
101 $params["select"] = array(
102 "DELIVERY_ID",
103 "PAYSYSTEM_ID",
104 "LINK_DIRECTION"
105 );
106
107 $deliveryChildrenList = self::getDeliveryChildrenList();
108
109 $records = array();
110 $res = DeliveryPaySystemTable::getList($params);
111
112 $restricted = array(
113 'D' => array(),
114 'P' => array()
115 );
116
117 while($record = $res->fetch())
118 {
119 if($record['LINK_DIRECTION'] == 'D')
120 {
121 if(!in_array($record["DELIVERY_ID"], $restricted['D']))
122 $restricted['D'][] = $record["DELIVERY_ID"];
123 }
124 elseif($record['LINK_DIRECTION'] == 'P')
125 {
126 if(!in_array($record["DELIVERY_ID"], $restricted['P']))
127 $restricted['P'][] = $record["PAYSYSTEM_ID"];
128 }
129
130 $deliveryId = $record["DELIVERY_ID"];
131 $linkDirection = $record["LINK_DIRECTION"];
132 unset($record["LINK_DIRECTION"]);
133 $deliveryCode = \CSaleDelivery::getCodeById($record["DELIVERY_ID"]);
134 $delivery = CSaleDeliveryHelper::getDeliverySIDAndProfile($deliveryCode);
135 $record["DELIVERY_ID"] = $delivery["SID"];
136 $record["DELIVERY_PROFILE_ID"] = isset($delivery["PROFILE"]) ? $delivery["PROFILE"] : null;
137 $records[] = $record;
138
139 if(!empty($deliveryChildrenList[$deliveryId]))
140 {
141 foreach($deliveryChildrenList[$deliveryId] as $childrenId)
142 {
143 if($linkDirection == 'D' && !in_array($childrenId, $restricted['D']))
144 $restricted['D'][] = $childrenId;
145
146 $deliveryCode = \CSaleDelivery::getCodeById($childrenId);
147 $delivery = CSaleDeliveryHelper::getDeliverySIDAndProfile($deliveryCode);
148 $record["DELIVERY_ID"] = $delivery["SID"];
149 $record["DELIVERY_PROFILE_ID"] = isset($delivery["PROFILE"]) ? $delivery["PROFILE"] : null;
150 $records[] = $record;
151 }
152 }
153 }
154
155 foreach(self::getFullDeliveryList() as $dlvId)
156 {
157 if(in_array($dlvId, $restricted['D']))
158 continue;
159
160 $deliveryCode = \CSaleDelivery::getCodeById($dlvId);
161 $delivery = CSaleDeliveryHelper::getDeliverySIDAndProfile($deliveryCode);
162
163 $record = array(
164 "DELIVERY_ID" => $delivery["SID"],
165 "DELIVERY_PROFILE_ID" => isset($delivery["PROFILE"]) ? $delivery["PROFILE"] : null
166 );
167
168 foreach(self::getFullPaySystemList() as $psId)
169 {
170 if(in_array($psId, $restricted['P']))
171 continue;
172
173 if(self::isRecordExists($record["DELIVERY_ID"], $record["DELIVERY_PROFILE_ID"], $psId, $records))
174 continue;
175
176 $record["PAYSYSTEM_ID"] = $psId;
177 $records[] = $record;
178 }
179 }
180
181 $result = new \CDBResult;
182 $result->InitFromArray($records);
183 return $result;
184 }
185
186 protected static function isRecordExists($dlvId, $profile, $paySystemId, $records)
187 {
188 return in_array(
189 array(
190 "DELIVERY_ID" => $dlvId,
191 "DELIVERY_PROFILE_ID" => $profile,
192 "PAYSYSTEM_ID" => $paySystemId
193 ),
194 $records
195 );
196 }
197
198 protected static function getFullDeliveryList()
199 {
200 static $result = null;
201
202 if($result === null)
203 {
204 $result = array();
205
206 foreach(Delivery\Services\Manager::getActiveList() as $dlvId => $dlvParams)
207 $result[] = $dlvId;
208 }
209
210 return $result;
211 }
212
213 protected static function getDeliveryChildrenList()
214 {
215 static $result = null;
216
217 if($result === null)
218 {
219 $result = array();
220
221 foreach(Delivery\Services\Manager::getActiveList() as $dlvId => $dlvParams)
222 {
223 $parentId = intval($dlvParams["PARENT_ID"]);
224
225 if(!isset($result[$parentId]))
226 $result[$parentId] = array();
227
228 $result[$parentId][] = $dlvId;
229 }
230 }
231
232 return $result;
233 }
234
235 protected static function getFullPaySystemList()
236 {
237 static $result = null;
238
239 if($result === null)
240 {
241 $result = array();
243 'filter' => array('ACTIVE' => 'Y')
244 ));
245
246 while($ps = $dbRes->fetch())
247 $result[] = $ps['ID'];
248 }
249
250 return $result;
251 }
252 public static function isPaySystemApplicable($paySystemId, $deliveryId)
253 {
254 if($deliveryId == '')
255 return true;
256
257 $result = false;
258 $arDelivery = CSaleDeliveryHelper::getDeliverySIDAndProfile($deliveryId);
259 $psInList = $dInList = $together = false;
260 $dbPSRec = self::GetList();
261
262 while($arPSRec = $dbPSRec->Fetch())
263 {
264 $psInRecord = $dInRecord = false;
265
266 if($arPSRec["PAYSYSTEM_ID"] == $paySystemId)
267 $psInList = $psInRecord = true;
268
269 if($arPSRec["DELIVERY_ID"] == $arDelivery["SID"]
270 &&
271 (
272 is_null($arPSRec["DELIVERY_PROFILE_ID"])
273 ||
274 $arPSRec["DELIVERY_PROFILE_ID"] == $arDelivery["PROFILE"]
275 )
276 )
277 {
278 $dInList = $dInRecord = true;
279 }
280
281 if($dInRecord && $psInRecord)
282 {
283 $together = true;
284 break;
285 }
286 }
287
288 if($together)
289 $result = true;
290 elseif (!$psInList || !$dInList)
291 $result = true;
292
293 return $result;
294 }
295
296
297 public static function UpdateDelivery($ID, $arFields)
298 {
299 if(!is_array($arFields) || $ID == '')
300 return false;
301
302 $arFilterFields["DELIVERY_ID"] = $ID;
303
304 if(isset($arFields["DELIVERY_PROFILE_ID"]))
305 $arFilterFields["DELIVERY_PROFILE_ID"] = $arFields["DELIVERY_PROFILE_ID"];
306
308
309 if(!is_array($arFields["PAYSYSTEM_ID"]))
310 $arFields["PAYSYSTEM_ID"] = array("PAYSYSTEM_ID" => $arFields["PAYSYSTEM_ID"]);
311
312 foreach ($arFields["PAYSYSTEM_ID"] as $psId)
313 {
314 $arFilterFields["PAYSYSTEM_ID"] = $psId;
316 }
317
318 return true;
319 }
320
329 public static function UpdatePaySystem($ID, $arFields)
330 {
331 $ID = trim($ID);
332 $arUpdateFields = array("PAYSYSTEM_ID" => $ID);
333
334 if ($ID == '' || !is_array($arFields) || empty($arFields))
335 return false;
336
337 if ($arFields[0] == "")
338 unset($arFields[0]);
339
340 self::Delete($arUpdateFields);
341
342 $arRecords = array();
343
344 foreach ($arFields as $deliveryId)
345 {
346
347 $delivery = CSaleDeliveryHelper::getDeliverySIDAndProfile($deliveryId);
348
349 if(!isset($delivery["SID"]))
350 continue;
351
352 $arUpdateFields["DELIVERY_ID"] = $delivery["SID"];
353
354 if(isset($delivery["PROFILE"]))
355 $arUpdateFields["DELIVERY_PROFILE_ID"] = $delivery["PROFILE"];
356 else
357 $arUpdateFields["DELIVERY_PROFILE_ID"] = null;
358
359 self::Add($arUpdateFields);
360 $arRecords[] = $arUpdateFields;
361 }
362
363 return true;
364 }
365
366 public static function Delete($arFilter)
367 {
369
370 $delParams = "";
371
372 if(isset($arFilter["PAYSYSTEM_ID"]) && intval($arFilter["PAYSYSTEM_ID"]) > 0)
373 $delParams .= "PAYSYSTEM_ID=".intval($arFilter["PAYSYSTEM_ID"]);
374
375 $code = "";
376
377 if(isset($arFilter["DELIVERY_ID"]) && $arFilter["DELIVERY_ID"] <> '')
378 {
379 $code .= $arFilter["DELIVERY_ID"];
380
381 if(isset($arFilter["DELIVERY_PROFILE_ID"]) && $arFilter["DELIVERY_PROFILE_ID"] <> '')
382 $code .= ":".$arFilter["DELIVERY_PROFILE_ID"];
383 }
384
385 $deliveryId = 0;
386
387 if($code <> '')
388 $deliveryId = \CSaleDelivery::getIdByCode($code);
389
390 if(intval($deliveryId) > 0)
391 $delParams .= "DELIVERY_ID=".intval($deliveryId);
392
393 if($delParams <> '')
394 $con->queryExecute("DELETE FROM ".DeliveryPaySystemTable::getTableName()." WHERE ".$delParams);
395
396 return new CDBResult();
397 }
398
399 public static function Add($arFields)
400 {
401 if(!isset($arFields["DELIVERY_ID"])
402 ||
403 trim($arFields["DELIVERY_ID"]) == ''
404 ||
405 !isset($arFields["PAYSYSTEM_ID"])
406 ||
407 intval($arFields["PAYSYSTEM_ID"]) <=0
408 )
409 {
410 return false;
411 }
412
413 if(isset($arFields["DELIVERY_PROFILE_ID"]) && $arFields["DELIVERY_PROFILE_ID"] <> '')
414 {
415 $arFields["DELIVERY_ID"] .= ":".$arFields["DELIVERY_PROFILE_ID"];
416 unset($arFields["DELIVERY_PROFILE_ID"]);
417 }
418
419 $arFields["DELIVERY_ID"] = \CSaleDelivery::getIdByCode($arFields["DELIVERY_ID"]);
420 $res = DeliveryPaySystemTable::add($arFields);
421 return new CDBResult($res);
422 }
423
424 public static function convertEmptyAllAgent()
425 {
426 return "";
427 }
428}
429?>
$con
Определения admin_tab.php:7
static getConnection($name="")
Определения application.php:638
static getActiveList($calculatingOnly=false, $restrictedIds=null)
Определения manager.php:147
static getList(array $params=array())
Определения manager.php:84
static getCodeById($id)
Определения delivery.php:1655
static getIdByCode($code)
Определения delivery.php:1641
static convertEmptyAllAgent()
Определения delivery_2_pay_system.php:424
static convertDeliveryIds($oldDeliveryIds=array(), $oldProfiles=array())
Определения delivery_2_pay_system.php:11
static isPaySystemApplicable($paySystemId, $deliveryId)
Определения delivery_2_pay_system.php:252
static Add($arFields)
Определения delivery_2_pay_system.php:399
static GetList($arFilter=array(), $arGroupBy=false, $arSelectFields=array())
Определения delivery_2_pay_system.php:68
static Delete($arFilter)
Определения delivery_2_pay_system.php:366
static getDeliveryChildrenList()
Определения delivery_2_pay_system.php:213
static getFullPaySystemList()
Определения delivery_2_pay_system.php:235
static UpdatePaySystem($ID, $arFields)
Определения delivery_2_pay_system.php:329
static getFullDeliveryList()
Определения delivery_2_pay_system.php:198
static UpdateDelivery($ID, $arFields)
Определения delivery_2_pay_system.php:297
static isRecordExists($dlvId, $profile, $paySystemId, $records)
Определения delivery_2_pay_system.php:186
static getDeliverySIDAndProfile($deliveryId)
Определения delivery_helper.php:123
$arFields
Определения dblapprove.php:5
</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
if($ajaxMode) $ID
Определения get_user.php:27
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$arFilter
Определения user_search.php:106
$arFilterFields
Определения user_search.php:40
$dbRes
Определения yandex_detail.php:168