From: Alexander Smirnov Date: Fri, 28 Mar 2025 15:04:20 +0000 (+0300) Subject: [ERP-370] fix bugs X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f004419591df527aa4e717b5e06cba72e133319f;p=erp24_rep%2Fyii-erp24%2F.git [ERP-370] fix bugs --- diff --git a/erp24/commands/PriceController.php b/erp24/commands/PriceController.php index 8c0cc0f8..0296a6ef 100644 --- a/erp24/commands/PriceController.php +++ b/erp24/commands/PriceController.php @@ -4,30 +4,34 @@ namespace yii_app\commands; use Yii; use yii\console\Controller; +use yii\db\Expression; 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])->orderBy(['date_from' => SORT_ASC])->all(); + ->andWhere(['active' => 1]) + //->andWhere(['product_id' => ['5466448f-946a-11e2-bf3d-1c6f659fb563', 'c552f4d8-0a1e-11e5-bd74-1c6f659fb563', '8476f3e1-a9ee-11e4-bedc-1c6f659fb563']]) + ->orderBy(['date_from' => SORT_ASC]) + ->all(); $p = []; foreach ($pricesDynamics as $pricesDynamic) { /** @var $pricesDynamic PricesDynamic */ $p[$pricesDynamic->region_id ?? 0][$pricesDynamic->product_id][] = [ 'id' => $pricesDynamic->id, - 'date_to' => $pricesDynamic->date_to, + 'date_from' => $pricesDynamic->date_from, ]; } - foreach ($p[0] as $productId => $priceDynamicDatas) { - if ($p[52][$productId]) { + foreach ($p[0] ?? [] as $productId => $priceDynamicDatas) { + if (isset($p[52][$productId])) { $cnt = count($priceDynamicDatas); - for ($ind = 0; $ind < $cnt - 1; $cnt++) { + for ($ind = 0; $ind < $cnt; $ind++) { if ($ind < $cnt - 1) { - PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $priceDynamicDatas[$ind+1]['date_to']], + PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $priceDynamicDatas[$ind+1]['date_from']], ['id' => $priceDynamicDatas[$ind]['id']]); echo '1'; } else { - PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $p[52][$productId][count($p[52][$productId]) - 1]['date_to']], + PricesDynamic::updateAll(['active' => 0, 'region_id' => 52, 'date_to' => $p[52][$productId][count($p[52][$productId]) - 1]['date_from']], ['id' => $priceDynamicDatas[$ind]['id']]); echo '2'; }