]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Проверка терминалов
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 22 Aug 2025 08:58:21 +0000 (11:58 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 22 Aug 2025 08:58:21 +0000 (11:58 +0300)
erp24/api2/controllers/DataController.php

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