From: fomichev Date: Tue, 15 Jul 2025 12:28:57 +0000 (+0300) Subject: Повторная отправка X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=15953eab1d1ad073c71805a3357f9d8ad66ad2ec;p=erp24_rep%2Fyii-erp24%2F.git Повторная отправка --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index b9c5e8f4..1e1d9098 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -2317,6 +2317,39 @@ class DataController extends BaseController } if (!empty($marketplaceOrders)) { /** @var MarketplaceOrders $marketplaceOrders */ + + $now = time(); + $sentAt = strtotime($marketplaceOrders->sent_1c_at ?? '2025-07-01 00:00:00'); + $attempts = (int)$marketplaceOrders->attempts_number; + + if ( + empty($arr["held"]) + && empty($arr["errors"]) + && empty($arr["error"]) + && empty($arr["errors_items"]) + && ($now - $sentAt) > 300 + ) { + if ($attempts < 3) { + $marketplaceOrders->sent_1c_at = null; + $marketplaceOrders->attempts_number = $attempts + 1; + $marketplaceOrders->status_1c = MarketplaceOrders::STATUSES_1C_CREATED_IN_ERP; + + $marketplaceOrders->save(); + continue; + } else { + $marketplaceOrders->status_1c = MarketplaceOrders::STATUSES_1C_ERROR_1C; + $marketplaceOrders->error_text = 'Превышено число попыток отправки в 1С.'; + $marketplaceOrders->save(); + + LogService::apiErrorLog(json_encode([ + "error_id" => 43, + "error" => "Превышено число попыток отправки в 1С " . $marketplaceOrders->guid, + ], JSON_UNESCAPED_UNICODE)); + + continue; + } + } + if (!empty($arr["errors"]) || !empty($arr["error"]) || !empty($arr["errors_items"])) { $errorText = ''; if (!empty($arr["errors"])) { diff --git a/erp24/migrations/m250715_115651_add_sent_1c_at_and_attempts_number_fields_to_marketplace_orders_table.php b/erp24/migrations/m250715_115651_add_sent_1c_at_and_attempts_number_fields_to_marketplace_orders_table.php new file mode 100644 index 00000000..46fd3197 --- /dev/null +++ b/erp24/migrations/m250715_115651_add_sent_1c_at_and_attempts_number_fields_to_marketplace_orders_table.php @@ -0,0 +1,61 @@ +db->schema->getTableSchema(self::TABLE_NAME); + if ($table === null) { + return; + } + + if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('sent_1c_at')) { + $this->addColumn( + self::TABLE_NAME, + 'sent_1c_at', + $this->timestamp()->null()->comment('Время отправки заказа в 1С') + ); + } + if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('attempts_number')) { + $this->addColumn( + self::TABLE_NAME, + 'attempts_number', + $this->integer()->null()->comment('Количество попыток отправки заказа в 1С') + ); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('sent_1c_at')) { + $this->dropColumn(self::TABLE_NAME, 'sent_1c_at'); + } + if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('attempts_number')) { + $this->dropColumn(self::TABLE_NAME, 'attempts_number'); + } + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m250715_115651_add_sent_1c_at_and_attempts_number_fields_to_marketplace_orders_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/erp24/records/MarketplaceOrders.php b/erp24/records/MarketplaceOrders.php index 4bfd5b16..fe749077 100644 --- a/erp24/records/MarketplaceOrders.php +++ b/erp24/records/MarketplaceOrders.php @@ -44,6 +44,8 @@ use yii\db\Expression; * @property string|null $order_photo Ссылка на фото собранного заказа для МП * @property string|null $created_at Время создания заказа в ERP * @property string|null $manager_link Ссылка на панели менеджера заказов + * @property string|null $sent_1c_at Время отправки заказа в 1С + * @property int|null $attempts_number Количество попыток отправки заказа в 1С */ class MarketplaceOrders extends \yii\db\ActiveRecord { @@ -105,8 +107,8 @@ class MarketplaceOrders extends \yii\db\ActiveRecord [['marketplace_order_id', 'marketplace_id', 'marketplace_name', 'status_id', 'substatus_id', 'creation_date', 'updated_at', 'total', 'delivery_total', 'buyer_total_before_discount', 'tax_system', 'payment_type', 'payment_method'], 'required'], [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_processing_1c', 'order_link', 'delivery_to', 'order_photo'], 'default', 'value' => null], [[ 'fake'], 'default', 'value' => 0], - [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'marketplace_id', 'status_telegram', 'status_processing_1c', 'readyto_1c'], 'integer'], - [['creation_date', 'updated_at', 'returned_at'], 'safe'], + [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'marketplace_id', 'status_telegram', 'status_processing_1c', 'readyto_1c', 'attempts_number'], 'integer'], + [['creation_date', 'updated_at', 'returned_at', 'sent_1c_at'], 'safe'], [['return_data', 'raw_data', 'marketplace_name', 'telegram_error', 'order_link', 'delivery_to', 'order_photo', 'manager_link'], 'string'], [['total', 'delivery_total', 'buyer_total_before_discount'], 'number'], [['marketplace_order_id', 'seller_id'], 'string', 'max' => 64], @@ -159,6 +161,8 @@ class MarketplaceOrders extends \yii\db\ActiveRecord 'created_at' => 'Время создания заказа в ERP', 'manager_link' => 'Ссылка на панели менеджера заказов', 'check_guid' => 'GUID чека заказа МП', + 'sent_1c_at' => 'Время отправки заказа в 1С', + 'attempts_number' => 'Количество попыток отправки заказа в 1С', ]; } diff --git a/erp24/views/marketplace-orders/view.php b/erp24/views/marketplace-orders/view.php index 6ddd6b8c..06220c60 100644 --- a/erp24/views/marketplace-orders/view.php +++ b/erp24/views/marketplace-orders/view.php @@ -88,6 +88,8 @@ $this->params['breadcrumbs'][] = $this->title; return MarketplaceOrders::STATUSES_1C[$model->status_1c]; } ], + 'sent_1c_at', + 'attempts_number', 'seller_id', 'number_1c', 'check_guid',