From ebaffc03772ac3a1176c1d21d09bb1d88378c7f6 Mon Sep 17 00:00:00 2001 From: fomichev Date: Fri, 5 Jun 2026 10:48:09 +0300 Subject: [PATCH] =?utf8?q?refactor:=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D1=82=D1=8C=20Yii::$app->get(StoreService)=20=D0=BD=D0=B0=20new?= =?utf8?q?=20StoreService()=20=D0=B2=20StorePlanService?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Убрана лишняя регистрация StoreService в container.singletons (web.php), так как сервис теперь создаётся напрямую, как принято в остальном проекте. Дублирующий запрос к CityStore заменён вызовом StoreService::getActiveStoreIds(). Co-Authored-By: Claude Sonnet 4.6 --- erp24/config/web.php | 6 ------ erp24/services/StorePlanService.php | 29 ++++++++++++++++------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/erp24/config/web.php b/erp24/config/web.php index 6e389cf7..303d94c2 100644 --- a/erp24/config/web.php +++ b/erp24/config/web.php @@ -1,7 +1,6 @@ response->redirect(['site/login']); }, ], - 'container' => [ - 'singletons' => [ - StoreService::class => StoreService::class, - ], - ], 'params' => $params, 'timeZone' => 'Europe/Moscow', ]; diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index af18f492..09c7bc6e 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -14,6 +14,7 @@ use yii_app\records\BouquetCompositionProducts; use yii_app\records\BouquetForecast; use yii_app\records\CityStore; use yii_app\records\CityStoreParams; +use yii_app\services\StoreService; use yii_app\records\MatrixBouquetForecast; use yii_app\records\Motivation; use yii_app\records\PricesDynamic; @@ -27,6 +28,8 @@ use yii_app\records\StorePlan; use yii_app\records\StoreType; use yii_app\records\WriteOffsErp; + + class StorePlanService { const PERIOD_COUNT = 3; @@ -1110,17 +1113,15 @@ class StorePlanService } + /** + * Service Locator используется намеренно: метод статический, constructor injection невозможен. + * TODO: рефакторить в instance-метод при следующем касании класса. + */ public static function getBouquetSpiecesMonthGoal($month, $year) { - $stores = ArrayHelper::map( - CityStore::find() - ->select(['id']) - ->where(['visible' => CityStore::IS_VISIBLE]) - ->asArray() - ->all(), - 'id', - 'id' - ); + $storeService = new StoreService(); + $activeIds = $storeService->getActiveStoreIds(); + $stores = $activeIds ? array_combine($activeIds, $activeIds) : []; $storesParams = ArrayHelper::map( CityStoreParams::find() ->select(['store_id', 'address_region']) @@ -1218,12 +1219,14 @@ class StorePlanService } + /** + * Service Locator используется намеренно: метод статический, constructor injection невозможен. + * TODO: рефакторить в instance-метод при следующем касании класса. + */ public static function getBouquetSpiecesMonthGoalFromForecast($month, $year, $storeId = null, $matrixGroups = []) { - $stores = $storeId ? [$storeId] : ArrayHelper::getColumn( - CityStore::find()->select(['id'])->where(['visible' => CityStore::IS_VISIBLE])->asArray()->all(), - 'id' - ); + $storeService = new StoreService(); + $stores = $storeId ? [$storeId] : $storeService->getActiveStoreIds(); if (empty($matrixGroups)) { return ['detail' => [], 'final' => [], 'debug' => []]; -- 2.39.5