From: Alexander Smirnov Date: Thu, 13 Mar 2025 16:33:25 +0000 (+0300) Subject: [ERP-370] поправил логику X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=2f140e6ee0b5c069ac918fe1e5aa20ba5ea28817;p=erp24_rep%2Fyii-erp24%2F.git [ERP-370] поправил логику --- diff --git a/erp24/commands/PriceController.php b/erp24/commands/PriceController.php index 8e0b56ec..b18a158f 100644 --- a/erp24/commands/PriceController.php +++ b/erp24/commands/PriceController.php @@ -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'; } }