1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
statistic.php
См. документацию.
1
<?php
2
3
4
namespace
Bitrix\Sale\Exchange\Integration\Manager
;
5
6
use
Bitrix\Main\Type\DateTime
;
7
use
Bitrix\Sale\Exchange\Integration\App\IntegrationB24
;
8
use
Bitrix\Sale\Exchange\Integration\Connector\Manager
;
9
use
Bitrix\Sale\Exchange\Integration\Entity\StatusType
;
10
use
Bitrix\Sale\Exchange\Integration\EntityType
;
11
use
Bitrix\Sale\Exchange\Integration\Service\Command\Line\StatisticsProvider
;
12
use
Bitrix\Sale\Exchange\Integration\Service\Container\Collection
;
13
use
Bitrix\Sale\Exchange\Integration\Service\Container\Item
;
14
use
Bitrix\Sale\Exchange\Integration\Service\Scenarios\Statistics
;
15
use
Bitrix\Sale\Exchange\Integration\Service\Statistic\Entity\Order
;
16
use
Bitrix\Sale\Exchange\Logger\Exchange
;
17
use
Bitrix\Sale\Exchange\Logger\ProviderType
;
18
use
Bitrix\Sale\Exchange\ManagerExport
;
19
use
Bitrix\Sale\OrderTable
;
20
21
class
Statistic
22
{
23
const
STATISTIC_IMPORT_PACKAGE_LIMIT
= 1000;
24
const
LOGGER_DAYS_INTERVAL
= 1;
25
26
protected
$app
;
27
protected
$collection
;
28
protected
$exchange
;
29
30
public
function
__construct
()
31
{
32
$this->app =
new
IntegrationB24
();
33
$this->collection =
new
Collection
();
34
$this->exchange =
new
Exchange
(
ProviderType::B24_INTEGRATION_NAME
);
35
}
36
40
public
function
getCollection
():
Collection
41
{
42
return
$this->collection
;
43
}
44
45
public
function
isOn
()
46
{
47
return
(
new
Manager
())->isOn();
48
}
49
50
public
function
modify
()
51
{
52
if
($this->
isOn
())
53
{
54
$provider
= $this->
getProvider
();
55
if
(is_null(
$provider
))
56
{
57
return
false
;
58
}
59
60
$list = $this->
getListByParams
(
$provider
)
61
->getCollection()
62
->toArray();
63
64
if
(
count
($list)>0)
65
{
66
return
(
new
Statistics
())
67
->modify($list)
68
->isSuccess();
69
}
70
}
71
72
return
true
;
73
}
74
75
protected
function
getStatisticsStartDate
()
76
{
77
$startDate
= new \Bitrix\Main\Type\DateTime();
78
$startDate
->add(
'-1 month'
);
79
80
return
$startDate
;
81
}
82
83
protected
function
getProvider
()
84
{
85
$res
=
StatisticsProvider::getList
([
86
'xmlId'
=>$this->app
87
->getCode()
88
]);
89
90
return
(isset(
$res
[
'error'
]) ==
false
) ?
$res
:
null
;
91
}
92
93
protected
function
prepareParamsByProviderFields
(
$provider
)
94
{
95
$lastDateUpdate =
null
;
96
if
(isset(
$provider
[
'statisticProviders'
][0][
'settings'
]))
97
{
98
$lastDateUpdate =
$provider
[
'statisticProviders'
][0][
'settings'
][
'lastDateUpdate'
];
99
}
100
101
return
[
102
'ID'
=> (int)
$provider
[
'statisticProviders'
][0][
'id'
],
103
'LAST_DATE_UPDATE'
=> $lastDateUpdate
104
];
105
}
106
107
protected
function
getListByParams
(
$provider
)
108
{
109
$this->
deleteOldEffectedRows
();
110
111
$startDate
= $this->
getStatisticsStartDate
()
112
->toString();
113
114
\CTimeZone::Disable();
115
116
$providerFields = $this->
prepareParamsByProviderFields
(
$provider
);
117
118
if
(is_null($providerFields[
'LAST_DATE_UPDATE'
]))
119
{
120
$time
=
$startDate
;
121
}
122
else
123
{
124
$lastDateUpdate = strtotime($providerFields[
'LAST_DATE_UPDATE'
]);
125
$time
= DateTime::createFromTimestamp($lastDateUpdate)
126
->toString();
127
}
128
129
$filter
[
'>=DATE_UPDATE'
] =
$time
;
130
$filter
[
'=RUNNING'
] =
'N'
;
131
132
$logs = $this->exchange->getEffectedRows(
133
$time
,
134
EntityType::ORDER
,
135
ManagerExport::EXCHANGE_DIRECTION_EXPORT
);
136
137
$r = OrderTable::getList([
138
'order'
=>[
'DATE_UPDATE'
=>
'ASC'
],
139
'filter'
=>
$filter
,
140
'limit'
=> static::STATISTIC_IMPORT_PACKAGE_LIMIT
141
]);
142
143
while
(
$res
= $r->fetch())
144
{
145
if
($this->exchange->isEffected(
$res
, $logs))
146
{
147
continue
;
148
}
149
150
$res
[
'AMOUNT'
] =
$res
[
'PRICE'
];
151
$res
[
'STATUS'
] = $this->
resolveStatusId
(
$res
);
152
$res
[
'ENTITY_ID'
] =
$res
[
'ID'
];
153
$res
[
'PROVIDER_ID'
] = $providerFields[
'ID'
];
154
155
$this->collection->addItem(
156
Item::create
(
157
Order::createFromArray
(
$res
))
158
->setInternalIndex(
$res
[
'ID'
])
159
);
160
161
$this->
addEffectedRows
(
$res
);
162
}
163
164
\CTimeZone::Enable();
165
166
return
$this;
167
}
168
169
protected
function
resolveStatusId
(
$fields
)
170
{
171
if
(
$fields
[
'PAYED'
] ==
'Y'
||
$fields
[
'DEDUCTED'
] ==
'Y'
)
172
{
173
return
StatusType::SUCCESS_NAME;
174
}
175
elseif
(
$fields
[
'CANCELED'
] ==
'Y'
)
176
{
177
return
StatusType::FAULTY_NAME;
178
}
179
else
180
{
181
return
StatusType::PROCESS_NAME;
182
}
183
}
184
185
protected
function
deleteOldEffectedRows
()
186
{
187
$this->exchange->deleteOldRecords(
ManagerExport::EXCHANGE_DIRECTION_EXPORT
, static::LOGGER_DAYS_INTERVAL);
188
}
189
190
protected
function
addEffectedRows
(
array
$fields
)
191
{
192
$this->exchange->add([
193
'XML_ID'
=>
$fields
[
'XML_ID'
],
194
'ENTITY_ID'
=>
$fields
[
'ID'
],
195
'DIRECTION'
=>
ManagerExport::EXCHANGE_DIRECTION_EXPORT
,
196
'ENTITY_TYPE_ID'
=>
EntityType::ORDER
,
197
'ENTITY_DATE_UPDATE'
=>
$fields
[
'DATE_UPDATE'
]
198
]);
199
}
200
201
}
$startDate
$startDate
Определения
basket_discount_convert.php:125
$provider
if(!Loader::includeModule('messageservice')) $provider
Определения
callback_ednaruimhpx.php:21
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
Bitrix\Sale\Exchange\Integration\App\IntegrationB24
Определения
integrationb24.php:6
Bitrix\Sale\Exchange\Integration\CRM\EntityType
Определения
entitytype.php:5
Bitrix\Sale\Exchange\Integration\Entity\StatusType
Определения
statustype.php:10
Bitrix\Sale\Exchange\Integration\EntityType\ORDER
const ORDER
Определения
entitytype.php:12
Bitrix\Sale\Exchange\Integration\Manager\Statistic
Определения
statistic.php:22
Bitrix\Sale\Exchange\Integration\Manager\Statistic\modify
modify()
Определения
statistic.php:50
Bitrix\Sale\Exchange\Integration\Manager\Statistic\__construct
__construct()
Определения
statistic.php:30
Bitrix\Sale\Exchange\Integration\Manager\Statistic\addEffectedRows
addEffectedRows(array $fields)
Определения
statistic.php:190
Bitrix\Sale\Exchange\Integration\Manager\Statistic\$exchange
$exchange
Определения
statistic.php:28
Bitrix\Sale\Exchange\Integration\Manager\Statistic\isOn
isOn()
Определения
statistic.php:45
Bitrix\Sale\Exchange\Integration\Manager\Statistic\prepareParamsByProviderFields
prepareParamsByProviderFields($provider)
Определения
statistic.php:93
Bitrix\Sale\Exchange\Integration\Manager\Statistic\deleteOldEffectedRows
deleteOldEffectedRows()
Определения
statistic.php:185
Bitrix\Sale\Exchange\Integration\Manager\Statistic\getListByParams
getListByParams($provider)
Определения
statistic.php:107
Bitrix\Sale\Exchange\Integration\Manager\Statistic\STATISTIC_IMPORT_PACKAGE_LIMIT
const STATISTIC_IMPORT_PACKAGE_LIMIT
Определения
statistic.php:23
Bitrix\Sale\Exchange\Integration\Manager\Statistic\getStatisticsStartDate
getStatisticsStartDate()
Определения
statistic.php:75
Bitrix\Sale\Exchange\Integration\Manager\Statistic\$collection
$collection
Определения
statistic.php:27
Bitrix\Sale\Exchange\Integration\Manager\Statistic\getCollection
getCollection()
Определения
statistic.php:40
Bitrix\Sale\Exchange\Integration\Manager\Statistic\getProvider
getProvider()
Определения
statistic.php:83
Bitrix\Sale\Exchange\Integration\Manager\Statistic\$app
$app
Определения
statistic.php:26
Bitrix\Sale\Exchange\Integration\Manager\Statistic\LOGGER_DAYS_INTERVAL
const LOGGER_DAYS_INTERVAL
Определения
statistic.php:24
Bitrix\Sale\Exchange\Integration\Manager\Statistic\resolveStatusId
resolveStatusId($fields)
Определения
statistic.php:169
Bitrix\Sale\Exchange\Integration\Service\Command\Batch\Statistics
Определения
statistics.php:17
Bitrix\Sale\Exchange\Integration\Service\Command\Line\StatisticsProvider
Определения
statisticsprovider.php:11
Bitrix\Sale\Exchange\Integration\Service\Command\Line\StatisticsProvider\getList
static getList($filter)
Определения
statisticsprovider.php:39
Bitrix\Sale\Exchange\Integration\Service\Container\Collection
Определения
collection.php:7
Bitrix\Sale\Exchange\Integration\Service\Container\Item
Определения
item.php:9
Bitrix\Sale\Exchange\Integration\Service\Container\Item\create
static create(Entity $entity)
Определения
item.php:20
Bitrix\Sale\Exchange\Integration\Service\Statistic\Entity\Order
Определения
order.php:8
Bitrix\Sale\Exchange\Integration\Service\Statistic\Entity\Order\createFromArray
static createFromArray(array $fields)
Определения
order.php:97
Bitrix\Sale\Exchange\Logger\Exchange
Определения
exchange.php:11
Bitrix\Sale\Exchange\Logger\ProviderType
Определения
providertype.php:5
Bitrix\Sale\Exchange\Logger\ProviderType\B24_INTEGRATION_NAME
const B24_INTEGRATION_NAME
Определения
providertype.php:7
Bitrix\Sale\Exchange\ManagerBase\EXCHANGE_DIRECTION_EXPORT
const EXCHANGE_DIRECTION_EXPORT
Определения
managerbase.php:16
Bitrix\Sale\Exchange\ManagerExport
Определения
managerexport.php:10
Bitrix\Sale\Internals\OrderTable
Определения
order.php:32
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$res
$res
Определения
filter_act.php:7
$filter
$filter
Определения
iblock_catalog_list.php:54
Bitrix\Sale\Exchange\Integration\Manager
Определения
statistic.php:4
$time
$time
Определения
payment.php:61
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
count
</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
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
sale
lib
exchange
integration
manager
statistic.php
Создано системой
1.14.0