From: Vladimir Fomichev Date: Fri, 22 Aug 2025 13:05:27 +0000 (+0300) Subject: Рефакторинг X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d53e80de92b1e32c9560d3b32edd1ff6480e98fe;p=erp24_rep%2Fyii-erp24%2F.git Рефакторинг --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index d69cccc7..7fffe9ee 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -1023,27 +1023,23 @@ 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') + $products1cByTip = Products1c::find() + ->select(['id', 'tip']) + ->andWhere(['tip' => ['kkms', 'terminals', 'city_store']]) + ->groupBy(['tip', 'id']) ->asArray() - ->column(); + ->all(); + $products1cByTipMap = []; + foreach ($products1cByTip as $item) { + $products1cByTipMap[$item['tip']][] = $item['id']; + } $existTerminals = Terminals::find() ->indexBy('id') ->asArray() ->column(); - $products1cKkms = Products1c::find() - ->andWhere(['tip' => 'kkms']) - ->indexBy('id') - ->asArray() - ->column(); + foreach ($result['stores'] as $gi => $arr) { - if (!in_array($arr["id"], $products1cStores)) { + if (!in_array($arr["id"], $products1cByTipMap['city_store'])) { $products1c = new Products1c; $products1c->id = $arr["id"]; $products1c->tip = 'city_store'; @@ -1058,7 +1054,7 @@ class DataController extends BaseController if ($arr["terminals"]) { $k = 0; foreach ($arr["terminals"] as $gi2 => $arr2) { - if (!in_array($arr2['id'], $products1cTerminals)) { + if (!in_array($arr2['id'], $products1cByTipMap['terminals'])) { $products1c2 = new Products1c; $products1c2->id = $arr2['id']; $products1c2->tip = 'terminals'; @@ -1090,7 +1086,7 @@ class DataController extends BaseController if ($arr['kkms']) { foreach ($arr["kkms"] as $gi2 => $arr2) { - if (!in_array($arr2['id'], $products1cKkms)) { + if (!in_array($arr2['id'], $products1cByTipMap['kkms'])) { $products1c3 = new Products1c; $products1c3->id = $arr2["id"]; $products1c3->tip = 'kkms';