]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Логирование
authorVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 09:39:20 +0000 (12:39 +0300)
committerVladimir Fomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 2 Oct 2025 09:39:20 +0000 (12:39 +0300)
erp24/controllers/MarketplacePricesController.php

index 106b3a34fdeae96fc5105dff6f1c697ab9d01741..95f62e49ef25abdfadda2970641b9f7989ec1267 100644 (file)
@@ -163,6 +163,19 @@ class MarketplacePricesController extends Controller
 
         if ($this->request->isPost) {
             if ($model->load($this->request->post()) && $model->save()) {
+                // Логирование создания
+                $mpPriceLog = new MarketplacePricesLog([
+                    'marketplace_prices_id' => $model->id,
+                    'price_before'          => null,
+                    'price_after'           => $model->price,
+                    'old_price_before'      => null,
+                    'old_price_after'       => $model->old_price,
+                    'action'                => 1, // create
+                ]);
+                if (!$mpPriceLog->save()) {
+                    Yii::error("Ошибка создания лога цены: " . json_encode($mpPriceLog->getErrors()), __METHOD__);
+                }
+
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } else {
@@ -208,8 +221,29 @@ class MarketplacePricesController extends Controller
     {
         $model = $this->findModel($id);
 
-        if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
-            return $this->redirect(['view', 'id' => $model->id]);
+        if ($this->request->isPost && $model->load($this->request->post())) {
+            // Сохраняем предыдущие значения для логирования
+            $beforePrice = $model->price;
+            $beforeOldPrice = $model->old_price;
+
+            if ($model->save()) {
+                // Логирование обновления
+                if ($beforePrice !== $model->price || $beforeOldPrice !== $model->old_price) {
+                    $mpPriceLog = new MarketplacePricesLog([
+                        'marketplace_prices_id' => $model->id,
+                        'price_before'          => $beforePrice,
+                        'price_after'           => $model->price,
+                        'old_price_before'      => $beforeOldPrice,
+                        'old_price_after'       => $model->old_price,
+                        'action'                => 2, // update
+                    ]);
+                    if (!$mpPriceLog->save()) {
+                        Yii::error("Ошибка создания лога цены: " . json_encode($mpPriceLog->getErrors()), __METHOD__);
+                    }
+                }
+
+                return $this->redirect(['view', 'id' => $model->id]);
+            }
         }
 
         // Данные для выпадающих списков