From 20aad1344d8a125874e51abed159b731219ca296 Mon Sep 17 00:00:00 2001 From: fomichev Date: Mon, 19 May 2025 16:00:35 +0300 Subject: [PATCH] =?utf8?q?=D0=9A=D0=B5=D1=88=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=B2=D1=8B=D0=BD=D0=BE=D1=81=20?= =?utf8?q?=D1=86=D0=B5=D0=BD=D1=8B=20=D0=B8=D0=B7=20=D1=86=D0=B8=D0=BA?= =?utf8?q?=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/services/StorePlanService.php | 47 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index 4b651d33..bea2bb5d 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -834,7 +834,7 @@ class StorePlanService foreach ($matrixTypesIds as $matrixTypeId) { $bouquetsArray = StorePlanService::getBouqetsByDate($month, $year, $matrixTypeId); $forecasts = ArrayHelper::getColumn($bouquetsArray, 'bouquetForecast'); - + var_dump($bouquetsArray); die(); foreach ($forecasts as $forecastArray) { if (is_array($forecastArray)) { foreach ($forecastArray as $fc) { @@ -960,25 +960,25 @@ class StorePlanService ->asArray() ->all(); - $guidList = array_column($forecasts, 'guid'); + $bouquetGuidList = array_column($forecasts, 'guid'); $productComponents = Products1c::find() ->select(['id', 'components']) - ->where(['id' => $guidList]) + ->where(['id' => $bouquetGuidList]) ->indexBy('id') ->asArray() ->all(); - $allGuids = []; + $allComponentGuids = []; foreach ($productComponents as $comp) { if ($json = $comp['components']) { $decoded = @json_decode($json,true); if (json_last_error()===JSON_ERROR_NONE) { - $allGuids = array_merge($allGuids, array_keys($decoded)); + $allComponentGuids = array_merge($allComponentGuids, array_keys($decoded)); } } } $speciesCache = Products1cNomenclature::find() - ->select(['id','species']) - ->where(['id'=>array_unique($allGuids)]) + ->select(['id', 'species']) + ->where(['id' => array_unique($allComponentGuids)]) ->indexBy('id')->asArray()->all(); foreach ($forecasts as $forecast) { $products = []; @@ -992,7 +992,19 @@ class StorePlanService } } - $productGuids = array_column($products, 'product_guid'); + $productComponentGuids = array_column($products, 'product_guid'); + + $pricesData = + PricesDynamic::find() + ->select(['price', 'product_id', 'region_id']) + ->where(['product_id' => $productComponentGuids]) + ->andWhere(['active' => 1]) + ->asArray() + ->all(); + foreach ($pricesData as $price) { + $priceCache[$price['region_id']][$price['product_id']] = $price['price']; + } + foreach ($types as $field => $typeSales) { $typeSalesValue = (int)$forecast[$field]; @@ -1005,29 +1017,14 @@ class StorePlanService $regionId = $params['address_region'] ?: match ($storeCities[$sid] ?? null) { 1342 => BouquetComposition::REGION_NN, - 1 => BouquetComposition::REGION_MSK, + 1 => BouquetComposition::REGION_MSK, default => BouquetComposition::REGION_NN, }; - $priceKey = $regionId . ':' . md5(implode(',', $productGuids)); - if (!isset($priceCache[$priceKey])) { - $priceCache[$priceKey] = ArrayHelper::map( - PricesDynamic::find() - ->select(['price', 'product_id']) - ->where(['product_id' => $productGuids]) - ->andWhere(['active' => 1, 'region_id' => $regionId]) - ->asArray() - ->all(), - 'product_id', - 'price' - ); - } - $prices = $priceCache[$priceKey]; - foreach ($products as $product) { $guid = $product['product_guid']; $species = $speciesCache[$guid]['species'] ?? 'Неизвестно'; - $price = $prices[$guid] ?? 0; + $price = $priceCache[$regionId][$guid] ?? 0; $raw = $price * $product['count'] * $typeSalesValue; $cost = round($raw * BouquetCompositionPrice::SURCHARGE_ASSEMBLY, 2); -- 2.39.5