From 3205254194e03e7bf0f2f63397ebd24f76e67412 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Fri, 22 Aug 2025 11:58:21 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?utf8?q?=20=D1=82=D0=B5=D1=80=D0=BC=D0=B8=D0=BD=D0=B0=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 62 ++++++++++++----------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index b0c99e5d..d69cccc7 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -1023,29 +1023,42 @@ class DataController extends BaseController } if (!empty($result['stores'])) { + $products1cStores = Products1c::find() + ->andWhere(['tip' => 'city_store']) + ->indexBy('id') + ->asArray() + ->column(); + $products1cTerminals = Products1c::find() + ->andWhere(['tip' => 'terminals']) + ->indexBy('id') + ->asArray() + ->column(); + $existTerminals = Terminals::find() + ->indexBy('id') + ->asArray() + ->column(); + $products1cKkms = Products1c::find() + ->andWhere(['tip' => 'kkms']) + ->indexBy('id') + ->asArray() + ->column(); foreach ($result['stores'] as $gi => $arr) { - $products1c = new Products1c; - $products1c->id = $arr["id"]; - $products1c->tip = 'city_store'; - $products1c->name = $arr["name"]; - $products1c->code = $arr["code"]; - $products1c->save(); - if ($products1c->getErrors()) { - LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $products1c->getErrors()], JSON_UNESCAPED_UNICODE)); + if (!in_array($arr["id"], $products1cStores)) { + $products1c = new Products1c; + $products1c->id = $arr["id"]; + $products1c->tip = 'city_store'; + $products1c->name = $arr["name"]; + $products1c->code = $arr["code"]; + $products1c->save(); + if ($products1c->getErrors()) { + LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $products1c->getErrors()], JSON_UNESCAPED_UNICODE)); + } } if ($arr["terminals"]) { $k = 0; - $products1cTerminals = Products1c::find() - ->andWhere(['tip' => 'terminals']) - ->indexBy('id') - ->asArray() - ->column(); - $existTerminals = Terminals::find()->indexBy('id')->asArray()->column(); foreach ($arr["terminals"] as $gi2 => $arr2) { - if (in_array($arr2['id'], $products1cTerminals)) { - continue; - } else { + if (!in_array($arr2['id'], $products1cTerminals)) { $products1c2 = new Products1c; $products1c2->id = $arr2['id']; $products1c2->tip = 'terminals'; @@ -1058,9 +1071,7 @@ class DataController extends BaseController } } - if (in_array($arr2['id'], $existTerminals)) { - continue; - } else { + if (!in_array($arr2['id'], $existTerminals)) { $terminal = new Terminals; $terminal->id = $arr2["id"]; $terminal->name = $arr2["name"]; @@ -1072,21 +1083,14 @@ class DataController extends BaseController if ($terminal->getErrors()) { LogService::apiErrorLog(json_encode(["error_id" => 4, "error" => $terminal->getErrors()], JSON_UNESCAPED_UNICODE)); } - $k++; } + $k++; } } if ($arr['kkms']) { - $products1cKkms = Products1c::find() - ->andWhere(['tip' => 'kkms']) - ->indexBy('id') - ->asArray() - ->column(); foreach ($arr["kkms"] as $gi2 => $arr2) { - if (in_array($arr2['id'], $products1cKkms)) { - continue; - } else { + if (!in_array($arr2['id'], $products1cKkms)) { $products1c3 = new Products1c; $products1c3->id = $arr2["id"]; $products1c3->tip = 'kkms'; -- 2.39.5