]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Повторная отправка
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 15 Jul 2025 12:28:57 +0000 (15:28 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 15 Jul 2025 12:28:57 +0000 (15:28 +0300)
erp24/api2/controllers/DataController.php
erp24/migrations/m250715_115651_add_sent_1c_at_and_attempts_number_fields_to_marketplace_orders_table.php [new file with mode: 0644]
erp24/records/MarketplaceOrders.php
erp24/views/marketplace-orders/view.php

index b9c5e8f423afd07eb47c1e96818a1e63298ba983..1e1d909889c863c96f99d30c07b6c7cad41ce5ad 100644 (file)
@@ -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 (file)
index 0000000..46fd319
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+
+use yii\db\Migration;
+
+class m250715_115651_add_sent_1c_at_and_attempts_number_fields_to_marketplace_orders_table extends Migration
+{
+    const TABLE_NAME = 'erp24.marketplace_orders';
+    /**
+     * {@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('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;
+    }
+    */
+}
index 4bfd5b16d8927a5ac5dca9f969fa844bbd72bbdc..fe74907741f07e73cf7cf871618befd42609b9e5 100644 (file)
@@ -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С',
         ];
     }
 
index 6ddd6b8cde74d62345873400887a4d3579964c2a..06220c603fac4398fab936551d2bb556f1ebc040 100644 (file)
@@ -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',