]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-370] поправил логику
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 13 Mar 2025 16:33:25 +0000 (19:33 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 13 Mar 2025 16:33:25 +0000 (19:33 +0300)
erp24/commands/PriceController.php

index 8e0b56ecc43856ebcffe24edde6a4ffa311d835b..b18a158f9980d6150002c2b605f4033462047bcb 100644 (file)
@@ -8,19 +8,28 @@ use yii_app\records\PricesDynamic;
 
 class PriceController extends Controller {
     public function actionFixActiveNullRegion() {
-        $pricesDynamics = PricesDynamic::find()->where(['or', ['region_id' => null], ['region_id' => 52]])->andWhere(['active' => 1])->all();
+        $pricesDynamics = PricesDynamic::find()->where(['or', ['region_id' => null], ['region_id' => 52]])
+            ->andWhere(['active' => 1])->orderBy(['date_from' => SORT_ASC])->all();
         $p = [];
         foreach ($pricesDynamics as $pricesDynamic) {
             /** @var $pricesDynamic PricesDynamic */
-            $p[$pricesDynamic->region_id ?? 0][$pricesDynamic->product_id][$pricesDynamic->id] = true;
+            $p[$pricesDynamic->region_id ?? 0][$pricesDynamic->product_id][] = [
+                'id' => $pricesDynamic->id,
+                'date_to' => $pricesDynamic->date_to,
+            ];
         }
-        $indices = [];
-        foreach ($p[0] as $productId => $pdId) {
+        foreach ($p[0] as $productId => $priceDynamicDatas) {
             if ($p[52][$productId]) {
-                $indices[] = array_keys($pdId)[0];
+                $cnt = count($priceDynamicDatas);
+                for ($ind = 0; $ind < $cnt - 1; $cnt++) {
+                    if ($ind < $cnt - 1) {
+                        PricesDynamic::updateAll(['active' => 0, 'date_to' => $priceDynamicDatas[$ind+1]['date_to']],
+                            ['id' => $priceDynamicDatas[$ind]['id']]);
+                        echo '1';
+                    }
+                }
             }
         }
-        PricesDynamic::updateAll(['active' => 0], ['id' => $indices]);
         return 'ok';
     }
 }