From: Vladimir Fomichev Date: Tue, 23 Dec 2025 15:37:10 +0000 (+0300) Subject: Поле ошибки в CreateChecks.php X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=4c5006445120b4d72b3e925a3c3f3d7ad4a6a603;p=erp24_rep%2Fyii-erp24%2F.git Поле ошибки в CreateChecks.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 index 00000000..7f30e994 --- /dev/null +++ b/erp24/migrations/m251223_145226_add_error_text_field_to_create_checks_table.php @@ -0,0 +1,37 @@ +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'); + } + } +} diff --git a/erp24/records/CreateChecks.php b/erp24/records/CreateChecks.php index 17815965..d77b0833 100644 --- a/erp24/records/CreateChecks.php +++ b/erp24/records/CreateChecks.php @@ -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', ]; } diff --git a/erp24/services/UploadService.php b/erp24/services/UploadService.php index b69aeaf5..23f4df58 100644 --- a/erp24/services/UploadService.php +++ b/erp24/services/UploadService.php @@ -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