]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Рефакторинг
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 22 Aug 2025 13:05:27 +0000 (16:05 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 22 Aug 2025 13:05:27 +0000 (16:05 +0300)
erp24/api2/controllers/DataController.php

index d69cccc754d673df211a4779d4a910eeac4367e5..7fffe9ee80ba552f4dc79106b90812b06b022c92 100644 (file)
@@ -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';