From: Vladimir Fomichev Date: Thu, 31 Jul 2025 11:09:55 +0000 (+0300) Subject: Актуальность в планограмме X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=3f6e73aae699e98f77fd70335a2b118e44a228bf;p=erp24_rep%2Fyii-erp24%2F.git Актуальность в планограмме --- diff --git a/erp24/services/StorePlanService.php b/erp24/services/StorePlanService.php index df1fded4..b672979f 100755 --- a/erp24/services/StorePlanService.php +++ b/erp24/services/StorePlanService.php @@ -878,18 +878,14 @@ class StorePlanService */ private static function calculateMedianSalesForPeriod($storeId, $similarProductIds, $monthInfo) { - $t0 = hrtime(true); $startDate = sprintf('%04d-%02d-01', $monthInfo['year'], $monthInfo['month']); $endDate = sprintf('%04d-%02d-%02d', $monthInfo['year'], $monthInfo['month'], cal_days_in_month(CAL_GREGORIAN, $monthInfo['month'], $monthInfo['year'])); - $initTime = (hrtime(true) - $t0) / 1e6; // миллисекунды - Yii::warning( "Init (calculateMedianSalesForPeriod): {$initTime} ms\n"); - $t1 = hrtime(true); $rows = (new Query()) - ->select(['sp.product_id', 'cnt' => 'COUNT(*)']) + ->select(['sp.product_id', 'cnt' => 'SUM(sp.quantity)']) ->from(['s' => 'sales']) ->innerJoin(['sp' => 'sales_products'], 's.id = sp.check_id') ->where(['sp.product_id' => $similarProductIds]) @@ -899,9 +895,7 @@ class StorePlanService ->groupBy('sp.product_id') ->indexBy('product_id') ->all(); - $dur = (hrtime(true) - $t1) / 1e6; - Yii::warning( "Query {$storeId}: {$dur} ms\n"); - $t2 = hrtime(true); + $salesValues = []; foreach ($similarProductIds as $id) { $salesValues[] = isset($rows[$id]) ? (int)$rows[$id]['cnt'] : 0; @@ -910,10 +904,7 @@ class StorePlanService $nonZeroSales = array_filter($salesValues, function($val) { return $val > 0; }); - $dur = (hrtime(true) - $t2) / 1e6; - Yii::warning("count for store {$storeId}: {$dur} ms\n"); - $t3 = hrtime(true); sort($nonZeroSales, SORT_NUMERIC); $n = count($nonZeroSales); if ($n === 0) { @@ -923,11 +914,7 @@ class StorePlanService } else { $median = ($nonZeroSales[$n / 2 - 1] + $nonZeroSales[$n / 2]) / 2; } - $dur = (hrtime(true) - $t3) / 1e6; - Yii::warning( "sort for store {$storeId}: {$dur} ms\n"); - $totalTime = (hrtime(true) - $t0) / 1e6; - Yii::warning( "Total calculateMedianSalesForPeriod: {$totalTime} ms\n"); return [$median, $salesValues]; }