From af678565a5ffacb816ba171a11300c417360ba05 Mon Sep 17 00:00:00 2001 From: fomichev Date: Tue, 15 Jul 2025 15:51:37 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?utf8?q?=D1=8F=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 63 +++++++++++------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 1e1d9098..c7292db4 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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); -- 2.39.5