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.
}
$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', 'Импорт завершён: записи добавлены или обновлены.');
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}
*/
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}
*/