1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
statistic.php
См. документацию.
1<?php
2
3
5
20
22{
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 {
86 'xmlId'=>$this->app
87 ->getCode()
88 ]);
89
90 return (isset($res['error']) == false) ? $res:null;
91 }
92
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
112 ->toString();
113
114 \CTimeZone::Disable();
115
116 $providerFields = $this->prepareParamsByProviderFields($provider);
117
118 if(is_null($providerFields['LAST_DATE_UPDATE']))
119 {
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,
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(
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'],
196 'ENTITY_TYPE_ID' => EntityType::ORDER,
197 'ENTITY_DATE_UPDATE' => $fields['DATE_UPDATE']
198 ]);
199 }
200
201}
$startDate
Определения basket_discount_convert.php:125
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
static create(Entity $entity)
Определения item.php:20
const EXCHANGE_DIRECTION_EXPORT
Определения managerbase.php:16
</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
$filter
Определения iblock_catalog_list.php:54
$time
Определения payment.php:61
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
</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
Определения yandex_run.php:501