From: fomichev Date: Mon, 19 May 2025 14:03:19 +0000 (+0300) Subject: Оптимизация запросов и циклов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f2718c0f9124434349f9db55b703f8cf74030099;p=erp24_rep%2Fyii-erp24%2F.git Оптимизация запросов и циклов --- diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index 5ce67ab9..366491f7 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -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'));