]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Актуальность в планограмме
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 31 Jul 2025 11:09:55 +0000 (14:09 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 31 Jul 2025 11:09:55 +0000 (14:09 +0300)
erp24/services/StorePlanService.php

index df1fded4e10467ee80c7162e3fafdbe4deb5ceda..b672979fcad7456b7767147e4f0727dc7291e60c 100755 (executable)
@@ -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];
     }