From b95f72892b337c6f5e05929dacd3797b087fb3bb Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Wed, 1 Oct 2025 15:19:59 +0300 Subject: [PATCH] =?utf8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?utf8?q?=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../MarketplacePricesController.php | 144 ++++++++++++++++++ .../MarketplacePricesLogController.php | 144 ++++++++++++++++++ ...01_083230_add_marketplace_prices_table.php | 54 +++++++ ...83252_add_marketplace_prices_log_table.php | 55 +++++++ erp24/records/MarketplacePrices.php | 71 +++++++++ erp24/records/MarketplacePricesLog.php | 65 ++++++++ erp24/views/marketplace-prices-log/_form.php | 37 +++++ erp24/views/marketplace-prices-log/create.php | 20 +++ erp24/views/marketplace-prices-log/index.php | 48 ++++++ erp24/views/marketplace-prices-log/update.php | 21 +++ erp24/views/marketplace-prices-log/view.php | 44 ++++++ erp24/views/marketplace-prices/_form.php | 35 +++++ erp24/views/marketplace-prices/create.php | 20 +++ erp24/views/marketplace-prices/index.php | 47 ++++++ erp24/views/marketplace-prices/update.php | 21 +++ erp24/views/marketplace-prices/view.php | 43 ++++++ 16 files changed, 869 insertions(+) create mode 100644 erp24/controllers/MarketplacePricesController.php create mode 100644 erp24/controllers/MarketplacePricesLogController.php create mode 100644 erp24/migrations/m251001_083230_add_marketplace_prices_table.php create mode 100644 erp24/migrations/m251001_083252_add_marketplace_prices_log_table.php create mode 100644 erp24/records/MarketplacePrices.php create mode 100644 erp24/records/MarketplacePricesLog.php create mode 100644 erp24/views/marketplace-prices-log/_form.php create mode 100644 erp24/views/marketplace-prices-log/create.php create mode 100644 erp24/views/marketplace-prices-log/index.php create mode 100644 erp24/views/marketplace-prices-log/update.php create mode 100644 erp24/views/marketplace-prices-log/view.php create mode 100644 erp24/views/marketplace-prices/_form.php create mode 100644 erp24/views/marketplace-prices/create.php create mode 100644 erp24/views/marketplace-prices/index.php create mode 100644 erp24/views/marketplace-prices/update.php create mode 100644 erp24/views/marketplace-prices/view.php diff --git a/erp24/controllers/MarketplacePricesController.php b/erp24/controllers/MarketplacePricesController.php new file mode 100644 index 00000000..1fafc469 --- /dev/null +++ b/erp24/controllers/MarketplacePricesController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all MarketplacePrices models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => MarketplacePrices::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single MarketplacePrices model. + * @param int $id ID + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new MarketplacePrices model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new MarketplacePrices(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing MarketplacePrices model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param int $id ID + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing MarketplacePrices model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param int $id ID + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the MarketplacePrices model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param int $id ID + * @return MarketplacePrices the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = MarketplacePrices::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/controllers/MarketplacePricesLogController.php b/erp24/controllers/MarketplacePricesLogController.php new file mode 100644 index 00000000..63ae3c88 --- /dev/null +++ b/erp24/controllers/MarketplacePricesLogController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all MarketplacePricesLog models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => MarketplacePricesLog::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single MarketplacePricesLog model. + * @param int $id ID + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new MarketplacePricesLog model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new MarketplacePricesLog(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing MarketplacePricesLog model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param int $id ID + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing MarketplacePricesLog model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param int $id ID + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the MarketplacePricesLog model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param int $id ID + * @return MarketplacePricesLog the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = MarketplacePricesLog::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/migrations/m251001_083230_add_marketplace_prices_table.php b/erp24/migrations/m251001_083230_add_marketplace_prices_table.php new file mode 100644 index 00000000..6e771065 --- /dev/null +++ b/erp24/migrations/m251001_083230_add_marketplace_prices_table.php @@ -0,0 +1,54 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey()->comment('ID'), + 'matrix_erp_id' => $this->integer()->notNull()->unique()->comment('ID товара матрицы'), + 'marketplace_id' => $this->integer()->notNull()->comment('ID маркетплейса 1 - YM, 2 - FW'), + 'marketplace_alias' => $this->string()->notNull()->comment('Алиас маркетплейса - YM, FW'), + 'price' => $this->decimal(12,2)->notNull()->comment('Цена товара для МП'), + 'old_price' => $this->decimal(12,2)->null()->comment('Старая цена для скидки'), + 'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()')->comment('Когда создано'), + 'updated_at' => $this->dateTime()->null()->comment('Когда обновлено'), + ]); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m251001_083230_add_marketplace_prices_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/erp24/migrations/m251001_083252_add_marketplace_prices_log_table.php b/erp24/migrations/m251001_083252_add_marketplace_prices_log_table.php new file mode 100644 index 00000000..bdfaa438 --- /dev/null +++ b/erp24/migrations/m251001_083252_add_marketplace_prices_log_table.php @@ -0,0 +1,55 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->bigPrimaryKey(), + 'marketplace_prices_id' => $this->integer()->notNull()->comment('FK на marketplace_prices.id'), + 'action' => $this->smallInteger()->notNull()->comment('1=create, 2=update'), + 'changed_at' => $this->dateTime()->notNull()->defaultExpression('NOW()')->comment('Когда изменено'), + 'changed_by' => $this->integer()->null()->comment('Кем изменено - admin id'), + 'price_before' => $this->decimal(12,2)->null(), + 'price_after' => $this->decimal(12,2)->null(), + 'old_price_before' => $this->decimal(12,2)->null(), + 'old_price_after' => $this->decimal(12,2)->null(), + ]); + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if (isset($tableSchema)) { + $this->dropTable(self::TABLE_NAME); + } + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m251001_083252_add_marketplace_prices_log_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/erp24/records/MarketplacePrices.php b/erp24/records/MarketplacePrices.php new file mode 100644 index 00000000..e118d0a5 --- /dev/null +++ b/erp24/records/MarketplacePrices.php @@ -0,0 +1,71 @@ + null], + [['matrix_erp_id', 'marketplace_id', 'marketplace_alias', 'price'], 'required'], + [['matrix_erp_id', 'marketplace_id'], 'default', 'value' => null], + [['matrix_erp_id', 'marketplace_id'], 'integer'], + [['price', 'old_price'], 'number'], + [['created_at', 'updated_at'], 'safe'], + [['marketplace_alias'], 'string', 'max' => 255], + [['matrix_erp_id'], 'unique'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'matrix_erp_id' => 'ID товара матрицы', + 'marketplace_id' => 'ID маркетплейса 1 - YM, 2 - FW', + 'marketplace_alias' => 'Алиас маркетплейса - YM, FW', + 'price' => 'Цена товара для МП', + 'old_price' => 'Старая цена для скидки', + 'created_at' => 'Когда создано', + 'updated_at' => 'Когда обновлено', + ]; + } + + public function getHistory() + { + return $this->hasMany(MarketplacePricesLog::class, ['marketplace_prices_id' => 'id']) + ->orderBy(['changed_at' => SORT_DESC, 'id' => SORT_DESC]); + } + +} diff --git a/erp24/records/MarketplacePricesLog.php b/erp24/records/MarketplacePricesLog.php new file mode 100644 index 00000000..dadb38f6 --- /dev/null +++ b/erp24/records/MarketplacePricesLog.php @@ -0,0 +1,65 @@ + null], + [['marketplace_prices_id', 'action'], 'required'], + [['marketplace_prices_id', 'action', 'changed_by'], 'default', 'value' => null], + [['marketplace_prices_id', 'action', 'changed_by'], 'integer'], + [['changed_at'], 'safe'], + [['price_before', 'price_after', 'old_price_before', 'old_price_after'], 'number'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'marketplace_prices_id' => 'FK на marketplace_prices.id', + 'action' => '1=create, 2=update', + 'changed_at' => 'Когда изменено', + 'changed_by' => 'Кем изменено - admin id', + 'price_before' => 'Price Before', + 'price_after' => 'Price After', + 'old_price_before' => 'Old Price Before', + 'old_price_after' => 'Old Price After', + ]; + } + +} diff --git a/erp24/views/marketplace-prices-log/_form.php b/erp24/views/marketplace-prices-log/_form.php new file mode 100644 index 00000000..3f4842c3 --- /dev/null +++ b/erp24/views/marketplace-prices-log/_form.php @@ -0,0 +1,37 @@ + + +
+ + + + field($model, 'marketplace_prices_id')->textInput() ?> + + field($model, 'action')->textInput() ?> + + field($model, 'changed_at')->textInput() ?> + + field($model, 'changed_by')->textInput() ?> + + field($model, 'price_before')->textInput() ?> + + field($model, 'price_after')->textInput() ?> + + field($model, 'old_price_before')->textInput() ?> + + field($model, 'old_price_after')->textInput() ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/erp24/views/marketplace-prices-log/create.php b/erp24/views/marketplace-prices-log/create.php new file mode 100644 index 00000000..1c5955b5 --- /dev/null +++ b/erp24/views/marketplace-prices-log/create.php @@ -0,0 +1,20 @@ +title = 'Create Marketplace Prices Log'; +$this->params['breadcrumbs'][] = ['label' => 'Marketplace Prices Logs', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/marketplace-prices-log/index.php b/erp24/views/marketplace-prices-log/index.php new file mode 100644 index 00000000..89fc713e --- /dev/null +++ b/erp24/views/marketplace-prices-log/index.php @@ -0,0 +1,48 @@ +title = 'Marketplace Prices Logs'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'marketplace_prices_id', + 'action', + 'changed_at', + 'changed_by', + //'price_before', + //'price_after', + //'old_price_before', + //'old_price_after', + [ + 'class' => ActionColumn::className(), + 'urlCreator' => function ($action, MarketplacePricesLog $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/marketplace-prices-log/update.php b/erp24/views/marketplace-prices-log/update.php new file mode 100644 index 00000000..53c2ad5e --- /dev/null +++ b/erp24/views/marketplace-prices-log/update.php @@ -0,0 +1,21 @@ +title = 'Update Marketplace Prices Log: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Marketplace Prices Logs', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/marketplace-prices-log/view.php b/erp24/views/marketplace-prices-log/view.php new file mode 100644 index 00000000..bfa3932d --- /dev/null +++ b/erp24/views/marketplace-prices-log/view.php @@ -0,0 +1,44 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Marketplace Prices Logs', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'marketplace_prices_id', + 'action', + 'changed_at', + 'changed_by', + 'price_before', + 'price_after', + 'old_price_before', + 'old_price_after', + ], + ]) ?> + +
diff --git a/erp24/views/marketplace-prices/_form.php b/erp24/views/marketplace-prices/_form.php new file mode 100644 index 00000000..003c9f79 --- /dev/null +++ b/erp24/views/marketplace-prices/_form.php @@ -0,0 +1,35 @@ + + +
+ + + + field($model, 'matrix_erp_id')->textInput() ?> + + field($model, 'marketplace_id')->textInput() ?> + + field($model, 'marketplace_alias')->textInput(['maxlength' => true]) ?> + + field($model, 'price')->textInput() ?> + + field($model, 'old_price')->textInput() ?> + + field($model, 'created_at')->textInput() ?> + + field($model, 'updated_at')->textInput() ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/erp24/views/marketplace-prices/create.php b/erp24/views/marketplace-prices/create.php new file mode 100644 index 00000000..22a8b2e8 --- /dev/null +++ b/erp24/views/marketplace-prices/create.php @@ -0,0 +1,20 @@ +title = 'Create Marketplace Prices'; +$this->params['breadcrumbs'][] = ['label' => 'Marketplace Prices', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/marketplace-prices/index.php b/erp24/views/marketplace-prices/index.php new file mode 100644 index 00000000..f97103e1 --- /dev/null +++ b/erp24/views/marketplace-prices/index.php @@ -0,0 +1,47 @@ +title = 'Marketplace Prices'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'matrix_erp_id', + 'marketplace_id', + 'marketplace_alias', + 'price', + //'old_price', + //'created_at', + //'updated_at', + [ + 'class' => ActionColumn::className(), + 'urlCreator' => function ($action, MarketplacePrices $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/marketplace-prices/update.php b/erp24/views/marketplace-prices/update.php new file mode 100644 index 00000000..a33c1555 --- /dev/null +++ b/erp24/views/marketplace-prices/update.php @@ -0,0 +1,21 @@ +title = 'Update Marketplace Prices: ' . $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Marketplace Prices', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/marketplace-prices/view.php b/erp24/views/marketplace-prices/view.php new file mode 100644 index 00000000..9fefbd78 --- /dev/null +++ b/erp24/views/marketplace-prices/view.php @@ -0,0 +1,43 @@ +title = $model->id; +$this->params['breadcrumbs'][] = ['label' => 'Marketplace Prices', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'matrix_erp_id', + 'marketplace_id', + 'marketplace_alias', + 'price', + 'old_price', + 'created_at', + 'updated_at', + ], + ]) ?> + +
-- 2.39.5