]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Оптимизация запросов и циклов
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 19 May 2025 14:03:19 +0000 (17:03 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Mon, 19 May 2025 14:03:19 +0000 (17:03 +0300)
erp24/services/StorePlanService.php

index 5ce67ab9f195721fef6d460a69bb89fac99c37af..366491f79e4b5c37dd9ad5734264935c8136a5bf 100755 (executable)
@@ -829,24 +829,29 @@ class StorePlanService
 
         $matrixTypesIds = StorePlanService::getActiveMatrixTypes();
         $storesForecasts = [];
+        $priceDictionary = [];
+        $priceModel = BouquetCompositionPrice::find()
+            ->select(['bouquet_id', 'region_id', 'price'])
+           ->asArray()
+            ->all();
+        foreach ($priceModel as $price) {
+            $priceDictionary[$price['bouquet_id']][$price['region_id']]['price'] = $price['price'];
+        }
 
         if ($matrixTypesIds) {
             foreach ($matrixTypesIds as $matrixTypeId) {
                 $bouquetsArray = StorePlanService::getBouqetsByDate($month, $year, $matrixTypeId);
+                $bouquetsArray = StorePlanService::getBouqetsByDate(5, 2025, 2);
                 $forecasts = ArrayHelper::getColumn($bouquetsArray, 'bouquetForecast');
-                var_dump($bouquetsArray); die();
+                $ids = ArrayHelper::getColumn($bouquetsArray, 'id');
+
+                //var_dump($ids); die();
                 foreach ($forecasts as $forecastArray) {
                     if (is_array($forecastArray)) {
                         foreach ($forecastArray as $fc) {
                             $bouquetPrice = 0;
-                            if (isset($storesParams[$fc["type_sales_id"]])) {
-                                $priceModel = BouquetCompositionPrice::find()
-                                    ->where(['bouquet_id' => $fc['bouquet_id']])
-                                    ->andWhere(['region_id' => $storesParams[$fc["type_sales_id"]]])
-                                    ->one();
-                                if ($priceModel !== null) {
-                                    $bouquetPrice = $priceModel->price;
-                                }
+                            if (isset($storesParams[$fc["type_sales_id"]]) &&$priceDictionary[$fc['bouquet_id']][$storesParams[$fc["type_sales_id"]]] !== null) {
+                               $bouquetPrice = $priceDictionary[$fc['bouquet_id']][$storesParams[$fc["type_sales_id"]]]['price'];
                             }
                             $storesForecasts[] = array_merge($fc, [
                                 'matrixTypeId' => $matrixTypeId,
@@ -860,7 +865,7 @@ class StorePlanService
 
         $resultData = [];
         $detailData = [];
-        //var_dump($storesParams);die();
+        //var_dump($storesForecasts);die();
         foreach ($storesForecasts as $storeForecast) {
             $products = ArrayHelper::toArray(BouquetCompositionProducts::getCompositionProducts($storeForecast['bouquet_id']));
             $productGuids = array_filter(array_column($products, 'product_guid'));