From: Vladimir Fomichev Date: Wed, 3 Sep 2025 10:27:59 +0000 (+0300) Subject: Не менять статус отмененных заказов в ERp из 1C если статус из 1С отличен от отмены X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=28b86b5cd193f7283a6988fa527d413829483333;p=erp24_rep%2Fyii-erp24%2F.git Не менять статус отмененных заказов в ERp из 1C если статус из 1С отличен от отмены --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 28a225a6..237f122c 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -3070,7 +3070,7 @@ class DataController extends BaseController $result = null; if (!$mpOrder['status']) { $result['message'] = 'Статус не передан'; - $result['status'] = null; + $result['status'] = 'error'; return $result; } // статусы маркетплейса @@ -3084,7 +3084,7 @@ class DataController extends BaseController $status = $mpOrder['status']; $marketplaceOrder = MarketplaceOrders::find() ->where(['guid' => $mpOrder['id']]) - ->andWhere(['<>', 'status_id', $cancelledStatusId]) + // ->andWhere(['<>', 'status_id', $cancelledStatusId]) ->one(); if ($marketplaceOrder) { @@ -3093,6 +3093,23 @@ class DataController extends BaseController if ($marketplaceOrder->fake == 1) { $debug = true; } + $marketplaceId = $marketplaceOrder->marketplace_id; + $cancelledStatusesCode = MarketplaceOrder1cStatuses::find() + ->select(['status_id']) + ->where(['marketplace_id' => $marketplaceId]) + ->andWhere(['order_status_id' => $cancelledStatusId]) + ->scalar(); + + $statusId1C = MarketplaceOrder1cStatuses::find() + ->where(['marketplace_id' => $marketplaceId]) + ->andWhere(['status_id' => $status]) + ->one(); + + if ($marketplaceOrder->status_id === $cancelledStatusId && $status !== $cancelledStatusesCode) { + $result['message'] = 'Заказ отменен ' . $mpOrder['id'];; + $result['status'] = 'cancelled_order'; + return $result; + } $statuses1cWithCancelledId = ArrayHelper::getColumn(MarketplaceOrder1cStatuses::find() ->select(['status_id']) @@ -3109,12 +3126,7 @@ class DataController extends BaseController $statuses = ArrayHelper::map($statuses, 'code', 'id'); $statusCodes = array_unique(array_keys($statuses)); - $marketplaceId = $marketplaceOrder->marketplace_id; - $statusId1C = MarketplaceOrder1cStatuses::find() - ->where(['marketplace_id' => $marketplaceId]) - ->andWhere(['status_id' => $status]) - ->one(); if (empty($statusId1C)) { $mess["result"] = 'error'; $mess["message_order"] = "Статус не найден"; @@ -3162,6 +3174,8 @@ class DataController extends BaseController $marketplaceOrder->status_processing_1c = $statusId1C->id; $marketplaceOrder->seller_id = $mpOrder['seller_id'] ?? null; $marketplaceOrder->number_1c = $mpOrder['number'] ?? null; + + if ($marketplaceOrder->save()) { // Обновляем историю статусов MarketplaceService::createOrUpdateStatusHistory($marketplaceOrder->id, $status->id, $substatus->id, [