]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-370] command to active=0 excessive prices dynamics
authorAlexander Smirnov <fredeom@mail.ru>
Thu, 13 Mar 2025 10:51:25 +0000 (13:51 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Thu, 13 Mar 2025 10:51:25 +0000 (13:51 +0300)
erp24/commands/PriceController.php [new file with mode: 0644]

diff --git a/erp24/commands/PriceController.php b/erp24/commands/PriceController.php
new file mode 100644 (file)
index 0000000..8e0b56e
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+namespace yii_app\commands;
+
+use Yii;
+use yii\console\Controller;
+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();
+        $p = [];
+        foreach ($pricesDynamics as $pricesDynamic) {
+            /** @var $pricesDynamic PricesDynamic */
+            $p[$pricesDynamic->region_id ?? 0][$pricesDynamic->product_id][$pricesDynamic->id] = true;
+        }
+        $indices = [];
+        foreach ($p[0] as $productId => $pdId) {
+            if ($p[52][$productId]) {
+                $indices[] = array_keys($pdId)[0];
+            }
+        }
+        PricesDynamic::updateAll(['active' => 0], ['id' => $indices]);
+        return 'ok';
+    }
+}