$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"])) {
}
}
}
+
+ $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);