]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Повторная отправка
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 15 Jul 2025 12:51:37 +0000 (15:51 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Tue, 15 Jul 2025 12:51:37 +0000 (15:51 +0300)
erp24/api2/controllers/DataController.php

index 1e1d909889c863c96f99d30c07b6c7cad41ce5ad..c7292db4b675ba4133e09844bdb67ea6847eb086 100644 (file)
@@ -2312,44 +2312,14 @@ class DataController extends BaseController
                 $productsNames = Products1c::getNamesByTip('products');
                 foreach ($result['created_orders'] as $arr) {
                     $marketplaceOrders = null;
+                    $marketplaceOrdersGuidArr = [];
                     if (!empty($arr["id"])) {
                         $marketplaceOrders = MarketplaceOrders::find()->where(['guid' => $arr["id"]])->one();
+                        $marketplaceOrdersGuidArr[] = $marketplaceOrders->guid;
                     }
                     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"])) {
@@ -2438,6 +2408,35 @@ class DataController extends BaseController
                         }
                     }
                 }
+
+                $now = time();
+                $sendedOrders = MarketplaceOrders::find()
+                    ->where(['status_1c' => MarketplaceOrders::STATUSES_1C_SENDED_TO_1C])
+                    ->andWhere(['not in', 'guid', $marketplaceOrdersGuidArr])
+                    ->all();
+                foreach ($sendedOrders as $order) {
+                    $sentAt = strtotime($order->sent_1c_at ?? '2025-07-01 00:00:00');
+                    $attempts = (int)$order->attempts_number;
+                    if (($now - $sentAt) > 300) {
+                        if ($attempts < 3) {
+                            $order->sent_1c_at = null;
+                            $order->attempts_number = $attempts + 1;
+                            $order->status_1c = MarketplaceOrders::STATUSES_1C_CREATED_IN_ERP;
+
+                            $order->save();
+                        } else {
+                            $order->status_1c = MarketplaceOrders::STATUSES_1C_ERROR_1C;
+                            $order->error_text = 'Превышено число попыток отправки в 1С.';
+                            $order->save();
+
+                            LogService::apiErrorLog(json_encode([
+                                "error_id" => 43,
+                                "error" => "Превышено число попыток отправки в 1С " . $order->guid,
+                            ], JSON_UNESCAPED_UNICODE));
+                        }
+                    }
+                }
+
             }
         } catch (Exception $e) {
             file_put_contents(self::OUT_DIR . '/log_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e->getMessage() . " " . $e->getLine(), FILE_APPEND);