From b5be98cd4b3056ec52b1aa01fd9f0cf7990b5707 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Thu, 20 Mar 2025 17:40:03 +0300 Subject: [PATCH] =?utf8?q?[ERP-331]=20=D1=81=D1=87=D0=B8=D1=82=D1=8B=D0=B2?= =?utf8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20errors=20=D0=B8=D0=B7=20json=20=D0=BE?= =?utf8?q?=D1=82=D0=B2=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 86 ++++++++++++++++++- ...arketplace_orders_add_field_error_text.php | 42 +++++++++ erp24/records/MarketplaceOrders.php | 7 +- 3 files changed, 133 insertions(+), 2 deletions(-) create mode 100755 erp24/migrations/m250320_142705_alter_table_marketplace_orders_add_field_error_text.php diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 406efc1b..2e1238b1 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -2230,7 +2230,91 @@ class DataController extends BaseController if (!empty($result['created_orders'])) { foreach ($result['created_orders'] as $arr) { - MarketplaceOrders::updateAll(['status_1c' => MarketplaceOrders::STATUSES_1C_CREATED_IN_1C], ['guid' => $arr['id']]); + if (!empty($arr["id"])) { + $marketplaceOrders = MarketplaceOrders::find()->where(['guid' => $arr["id"]])->one(); + } + if (!empty($marketplaceOrders)) { + /** @var MarketplaceOrders $marketplaceOrders */ + if (!empty($arr["errors"]) || !empty($arr["errors_items"])) { + $errorText = ''; + if (!empty($arr["errors"])) { + //"errors": [ + //{ + //"error": "Ошибка преобразования ИД документа", + //"error_description": "ИД документа 01202307-2705-1039-09bc-100015809667 уже записан в системе", + //"error_json": [ + //{ + //"field": "id", + //"error": "Документ с данным ИД уже записан в системе" + //} + // + + 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($errorRow["errors_items"])) { + foreach ($errorRow["errors_items"] as $errorDopRow) { + //"errors_items": [ + //{ + //"error_dop": "Ошибка проверки количества номенклатуры", + //"field": "quantity", + //"product_id": "bdd17587-09d8-11e5-bd74-1c6f659fb563", + //"error": "У данной позиции запрещён ввод дробного значения!" + //}, + // + // + $productName = $errorDopRow['product_id']; + + if (array_key_exists($errorDopRow['product_id'], $productsNames)) { + $productName = $productsNames[$errorDopRow['product_id']]; + } + + $errorText .= ' ' . $errorDopRow['error_dop']; + $errorText .= ' , поле: ' . $errorDopRow['field']; + $errorText .= ' , товар: ' . $productName; + $errorText .= ' , ошибка: ' . $errorDopRow['error']; + } + } + } + } + + $marketplaceOrders->status_1c = WriteOffsErp::STATUS_ERROR_1С; + $marketplaceOrders->error_text = $errorText; + $marketplaceOrders->save(); + if ($marketplaceOrders->getErrors()) { + LogService::apiErrorLog( + json_encode( + ["error_id" => 41, "error" => $marketplaceOrders->getErrors()], + JSON_UNESCAPED_UNICODE + ) + ); + } + } else { + if (isset($arr["held"]) && $arr["held"]) { + $marketplaceOrders->number_1c = $arr["number"] ?? ''; + $marketplaceOrders->status_1c = WriteOffsErp::STATUS_CREATED_1С; + $marketplaceOrders->save(); + if ($marketplaceOrders->getErrors()) { + LogService::apiErrorLog( + json_encode( + ["error_id" => 42, "error" => $marketplaceOrders->getErrors()], + JSON_UNESCAPED_UNICODE + ) + ); + } + } + } + } } } } catch (Exception $e) { diff --git a/erp24/migrations/m250320_142705_alter_table_marketplace_orders_add_field_error_text.php b/erp24/migrations/m250320_142705_alter_table_marketplace_orders_add_field_error_text.php new file mode 100755 index 00000000..e36559a5 --- /dev/null +++ b/erp24/migrations/m250320_142705_alter_table_marketplace_orders_add_field_error_text.php @@ -0,0 +1,42 @@ +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()); + } + + if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('number_1c')) { + $this->addColumn(self::TABLE_NAME, 'number_1c', $this->string(100)->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'); + } + if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('number_1c')) { + $this->dropColumn(self::TABLE_NAME, 'number_1c'); + } + } +} diff --git a/erp24/records/MarketplaceOrders.php b/erp24/records/MarketplaceOrders.php index ac770012..5b61e32c 100644 --- a/erp24/records/MarketplaceOrders.php +++ b/erp24/records/MarketplaceOrders.php @@ -30,6 +30,8 @@ use Yii; * @property int|null $status_1c Статус заказа в 1С * @property int|null $marketplace_name Наименование маркетплейса 'ФлауВау' 'ЯндексМаркет' * @property int|null $marketplace_id ID маркетплейса: 1 - Flowwow, 2 - YandexMarket + * @property string $error_text + * @property string|null $number_1c Название документа в 1с */ class MarketplaceOrders extends \yii\db\ActiveRecord { @@ -63,9 +65,10 @@ class MarketplaceOrders extends \yii\db\ActiveRecord [[ 'fake'], 'default', 'value' => 0], [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'marketplace_id'], 'integer'], [['creation_date', 'updated_at', 'returned_at'], 'safe'], - [['return_data', 'raw_data', 'marketplace_name'], 'string'], + [['return_data', 'raw_data', 'marketplace_name', 'error_text'], 'string'], [['total', 'delivery_total', 'buyer_total_before_discount'], 'number'], [['marketplace_order_id'], 'string', 'max' => 64], + [['number_1c'], 'string', 'max' => 100], [['warehouse_guid', 'guid'], 'string', 'max' => 36], [['tax_system', 'payment_type', 'payment_method'], 'string', 'max' => 32], [['marketplace_order_id'], 'unique'], @@ -101,6 +104,8 @@ class MarketplaceOrders extends \yii\db\ActiveRecord 'status_1c' => 'Статус заказа в 1С', 'marketplace_name' => 'Наименование маркетплейса', 'marketplace_id' => 'ID маркетплейса: 1 - Flowwow, 2 - YandexMarket', + 'error_text' => 'Ошибка', + 'number_1c' => 'Номер документа в 1с', ]; } -- 2.39.5