From af33a20c818f91adc46fb2c62ad7ea06c0def6cf Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Sun, 7 Apr 2024 05:53:56 +0700 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D1=82=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parser/system/public/markets.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mirzaev/spetsresurs/google_sheets/parser/system/public/markets.php b/mirzaev/spetsresurs/google_sheets/parser/system/public/markets.php index 3f45658..15757c1 100755 --- a/mirzaev/spetsresurs/google_sheets/parser/system/public/markets.php +++ b/mirzaev/spetsresurs/google_sheets/parser/system/public/markets.php @@ -32,10 +32,11 @@ $arangodb = new connection(require __DIR__ . '/../settings/arangodb.php'); function generateLabel(string $name): string { return match ($name) { - 'id', 'ID', 'ТТ' => 'id', - 'type', 'ТИП', 'Тип', 'тип' => 'type', - 'name', 'ДИРЕКТОР', 'Директор', 'директор' => 'name', + 'id', 'ID', 'ТТ', '№ТТ' => 'id', + 'type', 'ТИП', 'Тип', 'тип', 'ФОРМАТ' => 'type', + 'name', 'ДИРЕКТОР', 'Директор', 'директор', 'ДИРЕКТОР ТТ' => 'name', 'address', 'АДРЕС', 'Адрес', 'адрес' => 'address', + 'city', 'город', 'Город', 'Направление' => 'city', default => $name }; } @@ -47,6 +48,7 @@ function degenerateLabel(string $name): string 'ТИП', 'type' => 'ТИП', 'ДИРЕКТОР', 'name' => 'ДИРЕКТОР', 'АДРЕС', 'address' => 'АДРЕС', + 'city' => 'ГОРОД', default => $name }; } @@ -72,7 +74,7 @@ function init(array $row, bool $reverse = false): array } -function sync(Row &$row, string $city = 'Красноярск'): void +function sync(Row &$row): void { global $arangodb; @@ -82,8 +84,8 @@ function sync(Row &$row, string $city = 'Красноярск'): void // Инициализация ФИО $name = explode(' ', $_row['name']); - if (collection::init($arangodb->session, 'markets')) - if (!empty($_row['id']) && $market = collection::search($arangodb->session, sprintf("FOR d IN markets FILTER d.id == '%s' RETURN d", $_row['id']))) { + if (collection::init($arangodb->session, 'market')) + if (!empty($_row['id']) && $market = collection::search($arangodb->session, sprintf("FOR d IN market FILTER d.id == '%s' RETURN d", $_row['id']))) { // Найдена запись магазина (строки) в базе данных и включен режим перезаписи (приоритет - google sheets) if (false && $market->transfer_to_sheets) { @@ -119,12 +121,12 @@ function sync(Row &$row, string $city = 'Красноярск'): void /* // Обновление инстанции документа в базе данных document::update($arangodb->session, $market); */ - } else if ( + } else if ( $market = collection::search( $arangodb->session, sprintf( - "FOR d IN markets FILTER d._id == '%s' RETURN d", - document::write($arangodb->session, 'markets', [ + "FOR d IN market FILTER d._id == '%s' RETURN d", + document::write($arangodb->session, 'market', [ 'id' => $_row['id'] ?? '', 'type' => $_row['type'] ?? '', 'name' => [ @@ -133,7 +135,7 @@ function sync(Row &$row, string $city = 'Красноярск'): void 'last' => $name[2] ?? '' ], 'address' => $_row['address'] ?? '', - 'city' => $city, + 'city' => $_row['city'] ?? '', 'active' => true ]) ) @@ -181,13 +183,13 @@ $client->setAuthConfig($settings); $api = new Sheets($client); foreach ($sheets as $sheet) { - $rows = (new Flow())->read(new GoogleSheetExtractor($api, $document, new Columns($sheet, 'A', 'D'), true, 1000, 'row')); + $rows = (new Flow())->read(new GoogleSheetExtractor($api, $document, new Columns($sheet, 'B', 'F'), true, 1000, 'row')); $i = 1; foreach ($rows->fetch(5000) as $row) { - ++$i; + if (++$i === 2) continue; $buffer = $row; - sync($row, $sheet); + sync($row); if ($buffer !== $row) { /* $api->spreadsheets_values->update( $document,