Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
stepper.php
1
<?php
2
3
4
namespace
Bitrix\Sale\Exchange\Integration\Controller
;
5
6
7
use
Bitrix\Main\Engine\Controller
;
8
use
Bitrix\Main\Error
;
9
use
Bitrix\Main\Localization\Loc
;
10
use
Bitrix\Sale\OrderTable
;
11
use
Bitrix\Sale\Result
;
12
13
Loc::loadMessages
(__FILE__);
14
15
class
Stepper
extends
Controller
16
{
17
const
BATCH_LENGTH
= 50;
18
19
public
function
activityBatchAction
(array $list, $total=0, $start=0)
20
{
21
$batch = array_slice($list, 0, static::BATCH_LENGTH,
true
);
22
$slice = array_slice($list, static::BATCH_LENGTH,
null
,
true
);
23
24
$start += count($batch);
25
26
$b = $this->
getUnprocessedItems
($batch);
27
$batch = $b->getData();
28
29
foreach
(array_keys($batch) as $orderId)
30
{
31
OrderTable::update($orderId, [
'IS_SYNC_B24'
=>
'Y'
]);
32
}
33
34
$result[
'progress'
] = round((100*$start)/$total);
35
36
$result[
'process'
] = [
37
'items'
=> $batch,
38
'list'
=> $slice,
39
'total'
=> $total,
40
'start'
=> $start
41
];
42
43
if
($start == $total)
44
{
45
$result[
'finish'
] =
true
;
46
}
47
48
if
(count($b->getErrorMessages())>0)
49
{
50
$result[
'error'
] = implode(
"<br>"
, $b->getErrorMessages());
51
}
52
return
$result;
53
}
54
55
public
function
progressBarAction
($value)
56
{
57
require_once($_SERVER[
"DOCUMENT_ROOT"
] .
"/bitrix/modules/main/include/prolog_admin_before.php"
);
58
59
ob_start();
60
61
$message = new \CAdminMessage(
''
);
62
$message->ShowMessage(array(
63
"TYPE"
=>
"PROGRESS"
,
64
"DETAILS"
=>
'#PROGRESS_BAR#'
.
65
'<div class="adm-loc-ri-statusbar">'
.
Loc::getMessage
(
'SALE_ORDER_REQUEST_STATUS'
).
': <span class="bx-ui-loc-ri-loader"></span> <span class="bx-ui-loc-ri-status-text">'
.
Loc::getMessage
(
'SALE_ORDER_REQUEST_STATUS_PROCESS'
).
'</span></div>'
,
66
"HTML"
=>
true
,
67
"PROGRESS_TOTAL"
=> 100,
68
"PROGRESS_VALUE"
=> $value,
69
"PROGRESS_TEMPLATE"
=>
'<span class="bx-ui-loc-ri-percents">#PROGRESS_VALUE#</span>%'
70
));
71
$res = ob_get_clean();
72
return
$res;
73
}
74
75
public
function
messageOKAction
()
76
{
77
return
$this->
messageByTypeAction
(
Loc::getMessage
(
'SALE_ORDER_REQUEST_ORDER_IDS_OK'
),
'OK'
);
78
}
79
80
public
function
messageByTypeAction
($message, $type)
81
{
82
require_once($_SERVER[
"DOCUMENT_ROOT"
] .
"/bitrix/modules/main/include/prolog_admin_before.php"
);
83
84
if
($type ==
'ERROR'
)
85
{
86
$adminMessage = new \CAdminMessage(
87
array(
88
"DETAILS"
=> $message,
89
"TYPE"
=>
"ERROR"
,
90
"HTML"
=>
true
91
)
92
);
93
}
94
else
95
{
96
$adminMessage = new \CAdminMessage(
97
array(
98
"DETAILS"
=> $message,
99
"TYPE"
=>
"OK"
,
100
"HTML"
=>
true
101
)
102
);
103
}
104
105
return
$adminMessage->Show();
106
}
107
108
static
protected
function
getInActiveOrders($orderIds)
109
{
110
$registry = \Bitrix\Sale\Registry::getInstance(\
Bitrix
\
Sale
\
Registry::REGISTRY_TYPE_ORDER
);
111
113
$orderClass = $registry->getOrderClassName();
114
115
$r=[];
116
if
(count($orderIds)>0)
117
{
118
$list = $orderClass::getList([
119
'select'
=>[
'ID'
],
120
'filter'
=>[
'ID'
=>$orderIds,
'IS_SYNC_B24'
=>
'Y'
]
121
])->fetchAll();
122
123
if
(count($list)>0)
124
{
125
foreach
($list as $l)
126
{
127
$r[] = $l[
'ID'
];
128
}
129
}
130
}
131
132
return
$r;
133
}
134
135
protected
function
getUnprocessedItems
($items)
136
{
137
$result =
new
Result
();
138
$list = [];
139
$orderIds = array_keys($items);
140
141
$inActiveOrders = static::getInActiveOrders($orderIds);
142
143
foreach
($items as $index => $item)
144
{
145
$r = $this->
checkInActiveOrder
($index, $inActiveOrders);
146
if
($r->isSuccess())
147
{
148
$list[$index] = $item;
149
}
150
else
151
{
152
$result->addError(
new
Error
(
Loc::getMessage
(
'SALE_ORDER_APP_REST_SENDER_ORDER_ERROR'
).$index.
' '
.implode(
', '
, $r->getErrorMessages())));
153
}
154
}
155
156
$result->setData($list);
157
return
$result;
158
}
159
160
protected
function
checkInActiveOrder
($id, $list)
161
{
162
$r = new \Bitrix\Sale\Result();
163
164
if
(count($list)>0)
165
{
166
if
(in_array($id, $list))
167
{
168
$r->addError(
new
Error
(
Loc::getMessage
(
'SALE_ORDER_APP_REST_SENDER_Y'
)));
169
}
170
}
171
172
return
$r;
173
}
174
}
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Engine\Controller
Definition
controller.php:32
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Sale\Exchange\Integration\Controller\Stepper
Definition
stepper.php:16
Bitrix\Sale\Exchange\Integration\Controller\Stepper\progressBarAction
progressBarAction($value)
Definition
stepper.php:55
Bitrix\Sale\Exchange\Integration\Controller\Stepper\getUnprocessedItems
getUnprocessedItems($items)
Definition
stepper.php:135
Bitrix\Sale\Exchange\Integration\Controller\Stepper\BATCH_LENGTH
const BATCH_LENGTH
Definition
stepper.php:17
Bitrix\Sale\Exchange\Integration\Controller\Stepper\messageOKAction
messageOKAction()
Definition
stepper.php:75
Bitrix\Sale\Exchange\Integration\Controller\Stepper\checkInActiveOrder
checkInActiveOrder($id, $list)
Definition
stepper.php:160
Bitrix\Sale\Exchange\Integration\Controller\Stepper\activityBatchAction
activityBatchAction(array $list, $total=0, $start=0)
Definition
stepper.php:19
Bitrix\Sale\Exchange\Integration\Controller\Stepper\messageByTypeAction
messageByTypeAction($message, $type)
Definition
stepper.php:80
Bitrix\Sale\Internals\OrderTable
Definition
order.php:32
Bitrix\Sale\Registry\REGISTRY_TYPE_ORDER
const REGISTRY_TYPE_ORDER
Definition
registry.php:16
Bitrix\Sale\Result
Definition
result.php:9
Bitrix\Sale\Exchange\Integration\Controller
Definition
scenarios.php:4
Bitrix\Sender\Internals\QueryController
Definition
action.php:8
Bitrix
Sale
modules
sale
lib
exchange
integration
controller
stepper.php
Создано системой
1.10.0