--- /dev/null
+<?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';
+ }
+}