1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
b24integrationstattable.php
См. документацию.
1<?php
2namespace Bitrix\Sale\Exchange\Integration\Entity;
3
4use Bitrix\Main;
5use Bitrix\Main\Application;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\ORM\Data\AddResult;
8use Bitrix\Sale\Exchange\Integration\EntityType;
9
26class B24integrationStatTable extends Main\Entity\DataManager
27{
28 public static function getTableName(): string
29 {
30 return 'b_sale_b24integration_stat';
31 }
32
36 public static function getMap(): array
37 {
38 return [
39 new Main\Entity\IntegerField('ID', ['primary' => true, 'autocomplete' => true]),
40 new Main\Entity\EnumField('ENTITY_TYPE_ID', [
41 'required' => true,
42 'values' => [
44 ]]),
45 new Main\Entity\IntegerField('ENTITY_ID', ['required' => true]),
46 new Main\Entity\DatetimeField('DATE_UPDATE'),
47 new Main\Entity\DatetimeField('TIMESTAMP_X', ['default_value' => new Main\Type\DateTime()]),
48 new Main\Entity\IntegerField('PROVIDER_ID', ['required' => true]),
49 new Main\Entity\StringField("CURRENCY", ['required' => true]),
50 new Main\Entity\EnumField("STATUS", [
51 'required' => true,
52 'values' => [
56 ]]),
57 new Main\Entity\StringField("XML_ID", ['required' => true]),
58 new Main\Entity\FloatField("AMOUNT", ['required' => true]),
59 ];
60 }
61
62 protected static function upsertPrepareParams(array $data): array
63 {
64 $entityTypeID = (int)($data['ENTITY_TYPE_ID'] ?? EntityType::UNDEFINED);
65 $entityID = (int)($data['ENTITY_ID'] ?? 0);
66 $providerID = (int)($data['PROVIDER_ID'] ?? 0);
67 $dateUpdate = $data['DATE_UPDATE'] ?? null;
68 $currency = $data['CURRENCY'] ?? null;
69 $status = $data['STATUS'] ?? null;
70 $xmlId = $data['XML_ID'] ?? null;
71 $amount = (float)($data['AMOUNT'] ?? 0.0);
72
73 return [
74 'ENTITY_TYPE_ID' => $entityTypeID,
75 'ENTITY_ID' => $entityID,
76 'DATE_UPDATE' => $dateUpdate,
77 'TIMESTAMP_X' => new Main\DB\SqlExpression(
78 Main\Application::getConnection()->getSqlHelper()->getCurrentDateTimeFunction()
79 ),
80 'PROVIDER_ID' => $providerID,
81 'CURRENCY' => $currency,
82 'STATUS' => $status,
83 'XML_ID' => $xmlId,
84 'AMOUNT' => $amount,
85 ];
86 }
87
95 public static function upsert(array $data): AddResult
96 {
97 $result = new AddResult();
99
100 static::checkFields($result, null, $data);
101 if (!$result->isSuccess())
102 {
103 return $result;
104 }
105
106 $updateFields = $insertFields = static::upsertPrepareParams($data);
107
108 $queries = $connection->getSqlHelper()->prepareMerge(
109 static::getTableName(),
110 [
111 'ENTITY_TYPE_ID',
112 'ENTITY_ID'
113 ],
114 $insertFields,
115 $updateFields
116 );
117
118 foreach($queries as $query)
119 {
120 $connection->queryExecute($query);
121 }
122
123 $result->setId(
124 $connection->getInsertedId()
125 );
126
127 return $result;
128 }
129
138 public static function modify(array $items): AddResult
139 {
141 $helper = $connection->getSqlHelper();
142
143 $r = static::checkModifyFields($items);
144 if (!$r->isSuccess())
145 {
146 return $r;
147 }
148
149 $names = [
150 'ENTITY_TYPE_ID',
151 'ENTITY_ID',
152 'DATE_UPDATE',
153 'TIMESTAMP_X',
154 'PROVIDER_ID',
155 'CURRENCY',
156 'STATUS',
157 'XML_ID',
158 'AMOUNT',
159 ];
160
161 $values = [];
162 foreach ($items as $item)
163 {
164 $values[] = static::upsertPrepareParams($item);
165 }
166
167 $query = $helper->prepareMergeValues(
168 static::getTableName(),
169 [
170 'ENTITY_ID',
171 'ENTITY_TYPE_ID',
172 'PROVIDER_ID',
173 ],
174 $values,
175 $names
176 );
177
178 $connection->queryExecute($query);
179
180 return $r;
181 }
182
189 protected static function checkModifyFields(array $list): AddResult
190 {
191 $result = new AddResult();
192 $error = [];
193
194 foreach ($list as $k=>$fields)
195 {
196 $r = new AddResult();
197
198 static::checkFields($r, null, $fields);
199 if (!$r->isSuccess())
200 {
201 $error[] = '['.$k.'] '.implode(', ', $r->getErrorMessages()).'.';
202 }
203 }
204
205 if (!empty($error))
206 {
207 $result->addError(new Main\Error(implode(', ', $error)));
208 }
209
210 return $result;
211 }
212}
$connection
Определения actionsdefinitions.php:38
static getConnection($name="")
Определения application.php:638
Определения error.php:15
$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
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$status
Определения session.php:10
Определения collection.php:2
if(!function_exists("bx_hmac")) $amount
Определения payment.php:30
$currency
Определения template.php:266
$items
Определения template.php:224
$error
Определения subscription_card_product.php:20
$k
Определения template_pdf.php:567
$fields
Определения yandex_run.php:501