From: fomichev Date: Fri, 5 Jun 2026 07:48:09 +0000 (+0300) Subject: refactor: заменить Yii::$app->get(StoreService) на new StoreService() в StorePlanService X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ebaffc03772ac3a1176c1d21d09bb1d88378c7f6;p=erp24_rep%2Fyii-erp24%2F.git refactor: заменить Yii::$app->get(StoreService) на new StoreService() в StorePlanService Убрана лишняя регистрация StoreService в container.singletons (web.php), так как сервис теперь создаётся напрямую, как принято в остальном проекте. Дублирующий запрос к CityStore заменён вызовом StoreService::getActiveStoreIds(). Co-Authored-By: Claude Sonnet 4.6 --- 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' => []];