From f91b30d1edc5438b1e3f49d8505014d6c345261d Mon Sep 17 00:00:00 2001 From: fomichev Date: Fri, 7 Feb 2025 13:39:55 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?utf8?q?=D0=B8=20=D0=B4=D1=83=D0=B1=D0=BB=D0=B8=D0=BA=D0=B0=D1=82=D0=BE?= =?utf8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/StoreCityListController.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/erp24/controllers/StoreCityListController.php b/erp24/controllers/StoreCityListController.php index eb9860b9..256ae56d 100644 --- a/erp24/controllers/StoreCityListController.php +++ b/erp24/controllers/StoreCityListController.php @@ -97,13 +97,25 @@ class StoreCityListController extends Controller } foreach ($data as $row) { - $model = new StoreCityList(); - $model->name = $row['name'] ?? $row['A']; - $model->parent_id = $row['parent_id'] ?? $row['B']; - $model->type = $row['type'] ?? $row['C']; - - if (!$model->save()) { - Yii::error("Ошибка при сохранении: " . json_encode($model->errors)); + $name = $row['name'] ?? $row['A']; + $parent_id = $row['parent_id'] ?? $row['B']; + $type = $row['type'] ?? $row['C']; + + $existingRecord = StoreCityList::find() + ->where(['name' => $name, 'parent_id' => $parent_id, 'type' => $type]) + ->exists(); + + if (!$existingRecord) { + $model = new StoreCityList(); + $model->name = $name; + $model->parent_id = $parent_id; + $model->type = $type; + + if (!$model->save()) { + Yii::error("Ошибка при сохранении: " . json_encode($model->errors)); + } + } else { + Yii::info("Пропущена запись: $name (parent_id: $parent_id, type: $type), так как она уже существует."); } } } -- 2.39.5