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) {
->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 = [];
}
}
- $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];
$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);