]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
refactor: заменить Yii::$app->get(StoreService) на new StoreService() в StorePlanService
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 5 Jun 2026 07:48:09 +0000 (10:48 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 5 Jun 2026 07:48:09 +0000 (10:48 +0300)
Убрана лишняя регистрация StoreService в container.singletons (web.php),
так как сервис теперь создаётся напрямую, как принято в остальном проекте.
Дублирующий запрос к CityStore заменён вызовом StoreService::getActiveStoreIds().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
erp24/config/web.php
erp24/services/StorePlanService.php

index 6e389cf7c2b4a1b9287d9cf48fe8fbf2269ee979..303d94c24e7605ca0da2737424631f5f8909c29a 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 use yii\queue\amqp_interop\Queue;
-use yii_app\services\StoreService;
 
 $params = require __DIR__ . '/params.php';
 $db = require __DIR__ . '/db.php';
@@ -146,11 +145,6 @@ $config = [
             return Yii::$app->response->redirect(['site/login']);
         },
     ],
-    'container' => [
-        'singletons' => [
-            StoreService::class => StoreService::class,
-        ],
-    ],
     'params' => $params,
     'timeZone' => 'Europe/Moscow',
 ];
index af18f492bb1a088ee93da68593ea46ce861b19c9..09c7bc6ef4e2773019b55af6103e3209e776f235 100755 (executable)
@@ -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' => []];