]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Загрузка из файла с логами
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 1 Oct 2025 14:07:11 +0000 (17:07 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 1 Oct 2025 14:07:11 +0000 (17:07 +0300)
erp24/controllers/MarketplacePricesController.php
erp24/records/MarketplacePrices.php
erp24/records/MarketplacePricesLog.php

index adf30c6d0e2439ab9bcbae178f926bff63991989..5d6d84b53db1b61aa935d6ae038dd3da04a0ccb4 100644 (file)
@@ -7,13 +7,13 @@ use Yii;
 use yii\base\DynamicModel;
 use yii\web\UploadedFile;
 use yii_app\records\MarketplacePrices;
+use yii_app\records\MarketplacePricesLog;
 use yii_app\records\MarketplacePricesSearch;
 use yii\web\Controller;
 use yii\web\NotFoundHttpException;
 use yii\filters\VerbFilter;
-use yii_app\records\MatrixBouquetForecast;
 use yii_app\records\MatrixErp;
-use yii_app\records\Products1c;
+
 
 /**
  * MarketplacePricesController implements the CRUD actions for MarketplacePrices model.
@@ -74,22 +74,36 @@ class MarketplacePricesController extends Controller
                     }
 
                     $mpPrice = $mpPrices[$matrixProduct->id] ?? null;
-
+                    $action = 2;
                     if ($mpPrice === null) {
                         $mpPrice = new MarketplacePrices();
                         $mpPrice->matrix_erp_id     = $matrixProduct->id;
                         $mpPrice->marketplace_alias = $mpAlias;
                         $mpPrice->marketplace_id    = $mpMap[$mpAlias] ?? null;
                         $mpPrices[$matrixProduct->id] = $mpPrice;
+                        $action = 1;
                     }
-
+                    $beforePrice = $mpPrice->price ?? null;
+                    $beforeOldPrice = $mpPrice->old_price ?? null;
                     $mpPrice->price     = $price;
                     $mpPrice->old_price = $oldPrice;
 
                     if (!$mpPrice->save()) {
                         Yii::error("Ошибка создания цены: " . json_encode($mpPrice->getErrors()), __METHOD__);
+                    } else {
+                        $mpPriceLog = new MarketplacePricesLog();
+                        $mpPriceLog->marketplace_prices_id = $mpPrice->id;
+                        $mpPriceLog->price_after = $mpPrice->price;
+                        $mpPriceLog->price_before = $beforePrice;
+                        $mpPriceLog->old_price_after = $mpPrice->old_price;
+                        $mpPriceLog->old_price_before = $beforeOldPrice;
+                        $mpPriceLog->changed_at = date('Y-m-d H:i:s');
+                        $mpPriceLog->changed_by = Yii::$app->user->id;
+                        $mpPriceLog->action = $action;
+                        if (!$mpPriceLog->save()) {
+                            Yii::error("Ошибка создания лога цены: " . json_encode($mpPriceLog->getErrors()), __METHOD__);
+                        }
                     }
-
                 }
 
                 Yii::$app->session->setFlash('success', 'Импорт завершён: записи добавлены или обновлены.');
index e118d0a54eca72eec6f844cce8dde01413d2e875..113a68d490dce1c51c97bc303e2c80576bec17b4 100644 (file)
@@ -28,6 +28,18 @@ class MarketplacePrices extends \yii\db\ActiveRecord
         return 'marketplace_prices';
     }
 
+    public function behaviors()
+    {
+        return [
+            'ts' => [
+                'class' => \yii\behaviors\TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new \yii\db\Expression('NOW()'),
+            ],
+        ];
+    }
+
     /**
      * {@inheritdoc}
      */
index dadb38f61b3268fce29d0999d1ff7c349b4bbd04..ebcf32096b72e0f60e40bc1988d20c24be0df1b0 100644 (file)
@@ -29,6 +29,23 @@ class MarketplacePricesLog extends \yii\db\ActiveRecord
         return 'marketplace_prices_log';
     }
 
+    public function behaviors()
+    {
+        return [
+            'ts' => [
+                'class' => \yii\behaviors\TimestampBehavior::class,
+                'createdAtAttribute' => 'changed_at',
+                'updatedAtAttribute' => 'changed_at',
+                'value' => new \yii\db\Expression('NOW()'),
+            ],
+            'blame' => [
+                'class' => \yii\behaviors\BlameableBehavior::class,
+                'createdByAttribute' => 'changed_by',
+                'updatedByAttribute' => 'changed_by',
+            ],
+        ];
+    }
+
     /**
      * {@inheritdoc}
      */