]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Merge branch 'refs/heads/develop' into feature_fomichev_erp-458_analytic_operation_1c... origin/feature_fomichev_erp-458_analytic_operation_1c_exchnge
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 2 Sep 2025 13:35:04 +0000 (16:35 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 2 Sep 2025 13:35:04 +0000 (16:35 +0300)
# Conflicts:
# erp24/api2/controllers/DataController.php

1  2 
erp24/api2/controllers/DataController.php
erp24/commands/CronController.php

index bb857fadc617eb22404543a2838685f8e54f6ff2,e46a1c99c672d5f40336616f6a9db2d624c8c7ac..91604049a056b4f1bacb428b050af220e9ae0c7a
@@@ -2552,102 -2553,74 +2555,170 @@@ class DataController extends BaseContro
                  }
  
              }
 +
 +            if (!empty($result['analysts_business_operations'])) {
 +                $existingOperations = AnalystsBusinessOperations::find()
 +                    ->indexBy('id')
 +                    ->asArray()
 +                    ->all();
 +                $existingTypes = AnalystsBusinessOperationsTypes::find()
 +                    ->indexBy('code')
 +                    ->asArray()
 +                    ->all();
 +                foreach ($result["analysts_business_operations"] as $operation) {
 +                    if (!in_array($operation['id'], array_keys($existingOperations))) {
 +                        $newOperation = new AnalystsBusinessOperations();
 +                        $newOperation->id = $operation['id'];
 +                        $newOperation->name = $operation['name'];
 +                        $newOperation->type = (int)$operation['type'];
 +                        $newOperation->active = 1;
 +                        if (!in_array((int)$operation['type'], array_column($existingTypes, 'code'))) {
 +                            $newType = new AnalystsBusinessOperationsTypes();
 +                            $newType->code = (int)$operation['type'];
 +                            $newType->name = null;
 +                            $newType->alias = null;
 +                            $newType->created_at = date('Y-m-d H:i:s');
 +                            $newType->created_by = 1409;
 +                            if ($newType->save()) {
 +                                $newOperation->type_id = $newType->id;
 +                            } else {
 +                                $newOperation->type_id = null;
 +                               Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
 +                                LogService::apiErrorLog(
 +                                    json_encode(
 +                                        ["error_id" => 44.1, "error" => $newType->getErrors()],
 +                                        JSON_UNESCAPED_UNICODE
 +                                    )
 +                                );
 +                            }
 +                        } else {
 +                            $newOperation->type_id = $existingTypes[$operation['type']]['id'];
 +                        }
 +                        $newOperation->created_at = date('Y-m-d H:i:s');
 +                        if (!$newOperation->save()) {
 +                            LogService::apiErrorLog(
 +                                json_encode(
 +                                    ["error_id" => 44.2, "error" => $newOperation->getErrors()],
 +                                    JSON_UNESCAPED_UNICODE
 +                                )
 +                            );
 +                        }
 +
 +                    } else {
 +                        if ($existingOperations[$operation['id']]['type'] !== (int)$operation['type']) {
 +                            $oldOperation = AnalystsBusinessOperations::findOne($operation['id']);
 +                            if (!in_array((int)$operation['type'], array_column($existingTypes, 'code'))) {
 +                                $newType = new AnalystsBusinessOperationsTypes();
 +                                $newType->code = (int)$operation['type'];
 +                                $newType->name = null;
 +                                $newType->alias = null;
 +                                $newType->created_at = date('Y-m-d H:i:s');
 +                                $newType->created_by = 1409;
 +                                if ($newType->save()) {
 +                                    $oldOperation->type = (int)$operation['type'];
 +                                    $oldOperation->type_id = $newType->id;
 +                                    if (!$oldOperation->save()) {
 +                                        LogService::apiErrorLog(
 +                                            json_encode(
 +                                                ["error_id" => 44.3, "error" => $oldOperation->getErrors()],
 +                                                JSON_UNESCAPED_UNICODE
 +                                            )
 +                                        );
 +                                    }
 +                                } else {
 +                                    Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ );
 +                                    LogService::apiErrorLog(
 +                                        json_encode(
 +                                            ["error_id" => 44.4, "error" => $oldOperation->getErrors()],
 +                                            JSON_UNESCAPED_UNICODE
 +                                        )
 +                                    );
 +                                }
 +                            } else {
 +                                $oldOperation->type = (int)$operation['type'];
 +                                $oldOperation->type_id = AnalystsBusinessOperationsTypes::find()->where(['code' => (int)$operation['type']])->one()->id;
 +                                if (!$oldOperation->save()) {
 +                                    LogService::apiErrorLog(
 +                                        json_encode(
 +                                            ["error_id" => 44.5, "error" => $oldOperation->getErrors()],
 +                                            JSON_UNESCAPED_UNICODE
 +                                        )
 +                                    );
 +                                }
 +                            }
 +                        }
 +                    }
 +
 +                }
 +            }
+             if (!empty($result['cancelled_orders'])) {
+                 foreach ($result['cancelled_orders'] as $arr) {
+                     $marketplaceOrders = null;
+                     $marketplaceOrdersGuidArr = [];
+                     $marketplaceOrders = MarketplaceOrders::find()->where(['guid' => $arr])->one();
+                     $marketplaceOrdersGuidArr[] = $marketplaceOrders->guid;
+                     if (!empty($marketplaceOrders)) {
+                         /** @var MarketplaceOrders $marketplaceOrders */
+                         if (!empty($arr["errors"]) || !empty($arr["error"]) || !empty($arr["errors_items"])) {
+                             $errorText = '';
+                             if (!empty($arr["errors"])) {
+                                 foreach ($arr["errors"] as $errorRow) {
+                                     if (!empty($errorRow['error'])) {
+                                         $errorText .= $errorRow['error'];
+                                         $errorText .= ' ,' . $errorRow['error_description'];
+                                         if (!empty($errorRow['error_json'])) {
+                                             foreach ($errorRow['error_json'] as $errorJsonRow) {
+                                                 $errorText .= ' , поле: ' . $errorJsonRow['field'];
+                                                 $errorText .= ' , ошибка: ' . $errorJsonRow['error'];
+                                             }
+                                         }
+                                     }
+                                 }
+                             }
+                             if (!empty($arr["error"])) {
+                                 //"error": "Ошибка преобразования ИД документа",
+                                 //"error_description": "ИД документа 01202307-2705-1039-09bc-100015809667 уже записан в системе",
+                                 $errorText .= $arr["error"];
+                                 $errorText .= ' ,' . $arr['error_description'];
+                             }
+                             $marketplaceOrders->status_1c = MarketplaceOrders::STATUSES_1C_ERROR_1C;
+                             $marketplaceOrders->error_text = $errorText;
+                             $marketplaceOrders->save();
+                             if ($marketplaceOrders->getErrors()) {
+                                 LogService::apiErrorLog(
+                                     json_encode(
+                                         ["error_id" => 41, "error" => $marketplaceOrders->getErrors()],
+                                         JSON_UNESCAPED_UNICODE
+                                     )
+                                 );
+                             }
+                         } else {
+                            $marketplaceOrder->cancelled_order_sent = MarketplaceOrders::STATUSES_1C_CANCELLED_ORDER_SENT_IN_1C;
+                             $marketplaceOrders->save();
+                             if ($marketplaceOrders->getErrors()) {
+                                 LogService::apiErrorLog(
+                                     json_encode(
+                                         ["error_id" => 41, "error" => $marketplaceOrders->getErrors()],
+                                         JSON_UNESCAPED_UNICODE
+                                     )
+                                 );
+                             }
+                         }
+                     }
+                 }
+             }
              $mess['line'][] = __LINE__;
          } catch (Exception $e) {
              LogService::apiDataLogs(1, json_encode($mess, JSON_UNESCAPED_UNICODE), $requestIdText);
Simple merge