From c5e24d7838577c5af5d3f01b5388bc1c2511d477 Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Sat, 5 Mar 2022 13:44:11 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B3=D0=B8=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B8=D1=81=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/controllers/ProfileController.php | 4 ++-- .../system/models/ImportEdgeSupply.php | 5 +++++ mirzaev/skillparts/system/models/Supply.php | 20 +++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mirzaev/skillparts/system/controllers/ProfileController.php b/mirzaev/skillparts/system/controllers/ProfileController.php index 42dd74a..a54923f 100644 --- a/mirzaev/skillparts/system/controllers/ProfileController.php +++ b/mirzaev/skillparts/system/controllers/ProfileController.php @@ -1052,11 +1052,11 @@ class ProfileController extends Controller foreach (Supply::searchByImport($import->readId(), limit: 9999) as $supply) { // Перебор найденных поставок - if (ImportEdgeSupply::searchBySupply($supply, limit: 1)?->delete() === 1) { + if (ImportEdgeSupply::searchBySupply($supply)?->delete()) { // Удалено ребро: ИНСТАНЦИЯ ПОСТАВКИ -> ПОСТАВКА // Удаление поставки - if ($supply->delete() === 1) ++$deleted; + if ($supply->delete()) ++$deleted; } } diff --git a/mirzaev/skillparts/system/models/ImportEdgeSupply.php b/mirzaev/skillparts/system/models/ImportEdgeSupply.php index 9cdb9e0..f9f50ca 100644 --- a/mirzaev/skillparts/system/models/ImportEdgeSupply.php +++ b/mirzaev/skillparts/system/models/ImportEdgeSupply.php @@ -52,4 +52,9 @@ class ImportEdgeSupply extends Edge ] ); } + + public static function searchBySupply(Supply $supply): static + { + return static::find()->where(['_to' => $supply->readId()])->one(); + } } diff --git a/mirzaev/skillparts/system/models/Supply.php b/mirzaev/skillparts/system/models/Supply.php index ede21d4..e6bf367 100644 --- a/mirzaev/skillparts/system/models/Supply.php +++ b/mirzaev/skillparts/system/models/Supply.php @@ -173,7 +173,17 @@ class Supply extends Product implements ProductInterface, OfferInterface */ public static function searchByImport(string|null $id = null, int|null $limit = 10): array { - return static::find()->where(['_from' => $id])->limit($limit)->all(); + // Инициализация буфера вывода + $supplies = []; + + foreach (ImportEdgeSupply::find()->where(['_from' => $id])->limit($limit)->all() as $edge) { + // Перебор найденных рёбер + + // Поиск поставки и запись в буфер вывода + $supplies[] = static::searchById($edge->_to); + } + + return $supplies; } /** @@ -456,13 +466,16 @@ class Supply extends Product implements ProductInterface, OfferInterface $amount = $row['Количество'] ?? $row['количество'] ?? $row['Amount'] ?? $row['amount'] ?? $row['amnt'] ?? 1; // Поиск аналогов - $analogs = explode(',', $row['Артикул'] ?? $row['артикул'] ?? $row['Article'] ?? $row['article'] ?? $row['catn'], 50); + $analogs = explode(',', (string) ($row['Аналоги'] ?? $row['аналоги'] ?? $row['Analogs'] ?? $row['analogs'] ?? $row['ОЕМ'] ?? $row['eom'] ?? ''), 50); // Инициализация функции создания поставки $create = function (string $_supply) use ($row, $analogs, &$created, &$updated, &$imported, $amount, $account): bool { // Очистка $_supply = trim($_supply); + // Проверка на то, что передано пустое поле "Аналоги" (подразумевается) + if (empty($_supply)) return false; + // Инициализация буфера документов $_row = []; @@ -473,7 +486,7 @@ class Supply extends Product implements ProductInterface, OfferInterface $_row['catn'] = $_supply; $_row['cost'] = (float) preg_replace('/[^\d\.]+/', '', preg_replace('/\,+/', ' ', $row['Стоимость'] ?? $row['стоимость'] ?? $row['Цена'] ?? $row['цена'] ?? $row['Cost'] ?? $row['cost'] ?? $row['Price'] ?? $row['price'])); $_row['prod'] = $row['Производитель'] ?? $row['производитель'] ?? $row['Production'] ?? $row['production'] ?? $row['prod']; - $_row['oemn'] = $analogs; + $_row['oemn'] = array_walk($analogs, 'trim'); // Инициализация буфера поставки $supply = new static($_row); @@ -616,7 +629,6 @@ class Supply extends Product implements ProductInterface, OfferInterface // if (isset($product->prod) && $product->prod === $supply->prod) { // // Производитель совпадает с тем, что указан в товаре - for ($i = 0; $i++ < $amount;) { // Перебор создаваемых рёбер (так работает обозначение количества товаров в наличии)