]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Поле ошибки в CreateChecks.php
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 23 Dec 2025 15:37:10 +0000 (18:37 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 23 Dec 2025 15:37:10 +0000 (18:37 +0300)
erp24/migrations/m251223_145226_add_error_text_field_to_create_checks_table.php [new file with mode: 0644]
erp24/records/CreateChecks.php
erp24/services/UploadService.php

diff --git a/erp24/migrations/m251223_145226_add_error_text_field_to_create_checks_table.php b/erp24/migrations/m251223_145226_add_error_text_field_to_create_checks_table.php
new file mode 100644 (file)
index 0000000..7f30e99
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+use yii\db\Migration;
+
+class m251223_145226_add_error_text_field_to_create_checks_table extends Migration
+{
+    const TABLE_NAME = 'erp24.create_checks';
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+        if ($table === null) {
+            return;
+        }
+
+        if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('error_text')) {
+            $this->addColumn(
+                self::TABLE_NAME,
+                'error_text',
+                $this->text()->null()->comment('Текст ошибки при создании чека в 1С')
+            );
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('error_text')) {
+            $this->dropColumn(self::TABLE_NAME, 'error_text');
+        }
+    }
+}
index 1781596520d44ccbb6643bec6e752961a43d6ee8..d77b0833e9eccf4394b153a8fe8dad6e201269f8 100644 (file)
@@ -31,6 +31,7 @@ use yii_app\api3\core\validators\PhoneValidator;
  * @property string|null $marketplace_order_id
  * @property int|null $is_marketplace признак продажи через маркетплейс
  * @property string|null $marketplace_name название маркетплейса
+ * @property string|null $error_text Текст ошибки при создании чека в 1С
  */
 class CreateChecks extends \yii\db\ActiveRecord
 {
@@ -53,7 +54,7 @@ class CreateChecks extends \yii\db\ActiveRecord
         return [
             [[/*'kkm_id', */'store_id', /*'order_id', */'check_id', 'guid', /*'name', 'sales_check',*/ 'items', /*'payments',*/ 'held', 'date'/*, 'comments'*/], 'required'],
             [['order_id', 'held', 'status', 'is_marketplace'], 'integer'],
-            [['type', 'items', 'payments', 'phone'], 'string'],
+            [['type', 'items', 'payments', 'phone', 'error_text'], 'string'],
             [['date', 'delivery_date', 'date_up', 'phone'], 'safe'],
             [['kkm_id', 'seller_id', 'store_id', 'check_id', 'guid', 'sales_check', 'order_guid', 'marketplace_order_id', 'marketplace_name'], 'string', 'max' => 36],
             [['name', 'comments'], 'string', 'max' => 255],
@@ -91,6 +92,7 @@ class CreateChecks extends \yii\db\ActiveRecord
             'marketplace_order_id' => 'Marketplace Order ID',
             'is_marketplace' => 'Is Marketplace',
             'marketplace_name' => 'Marketplace Name',
+            'error_text' => 'Error Text',
         ];
     }
 
index b69aeaf5ec72c8b2db196789b28d827ae277bc4f..23f4df58ecea2231aa62e7d16f807a14625d370b 100644 (file)
@@ -1470,7 +1470,7 @@ class UploadService {
 
             if (!empty($result['created_checks'])) {
                 foreach ($result["created_checks"] as $idp => $arr2) {
-                    if (!empty($arr2["error"])) { // Если есть ошибки
+                    if (!empty($arr2["error"]) || !empty($arr2["errors"])) { // Если есть ошибки
                         // // обновляем GUID на новый
 //                        try {
 //                            $createChecks = CreateChecks::find()->select(['order_id'])->where(['check_id' => $arr2["id"]])->one();
@@ -1492,13 +1492,31 @@ class UploadService {
 //                        } catch (Exception $e) {
 //                            file_put_contents(self::OUT_DIR . '/log_created_check_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e->getMessage(), FILE_APPEND);
 //                        }
+                        // Формируем текст ошибки
+                        $errorText = null;
+                        if (!empty($arr2["errors"]) && is_array($arr2["errors"])) {
+                            $errorDescriptions = [];
+                            foreach ($arr2["errors"] as $err) {
+                                if (!empty($err["error_description"])) {
+                                    $errorDescriptions[] = $err["error_description"];
+                                }
+                            }
+                            $errorText = implode('; ', $errorDescriptions);
+                        }
+                        // Fallback на $arr2["error"] если error_description пустой
+                        if (empty($errorText) && !empty($arr2["error"])) {
+                            $errorText = is_array($arr2["error"])
+                                ? json_encode($arr2["error"], JSON_UNESCAPED_UNICODE)
+                                : $arr2["error"];
+                        }
                         CreateChecks::updateAll([
                             'status' => CreateChecks::STATUS_CHECK_ERROR_1C,
                             'guid' => $arr2["id"],
                             'date_up' => date('Y-m-d H:i:s'),
+                            'error_text' => $errorText,
                         ], ['check_id' => $arr2["id"]]);
                         LogService::apiErrorLog(json_encode(["error_id" => 31, "error" => 'ОШИБКА В 1С - СОЗДАНИЕ ЧЕКА ЗАКАЗА  id=' . $arr2["id"]], JSON_UNESCAPED_UNICODE));
-                        $txt = date("d.m.Y H:i:s", time()) . " $idp СОЗДАНИЕ ЧЕКА ОШИБКА id=" . $arr2["id"] . " " . $arr2["error"];
+                        $txt = date("d.m.Y H:i:s", time()) . " $idp СОЗДАНИЕ ЧЕКА ОШИБКА id=" . $arr2["id"] . " " . $errorText;
                         file_put_contents(self::OUT_DIR . '/log_created_check_error.txt', PHP_EOL . $txt, FILE_APPEND);
                     } else { // Если ошибок нет
                         if (/* $arr2["held"] == true and */ !empty($arr2["name"]) and !empty($arr2["id"])) { // Если заполнен name b id