--- /dev/null
+<?php
+
+namespace yii_app\commands;
+
+use yii\console\Controller;
+use yii\helpers\Json;
+use yii_app\records\MatrixErp;
+use yii_app\records\MatrixErpProperty;
+use yii_app\records\MatrixErpPropertyDynamic;
+use yii_app\records\Products1c;
+use yii_app\services\MarketplaceService;
+
+class MatrixErpController extends Controller
+{
+ public function actionFromProductsOneC() {
+ $existings = MatrixErp::find()->all();
+ $existingMapGuidGroupNames = [];
+ foreach ($existings as $existing) {
+ /* @var $existing MatrixErp */
+ $existingMapGuidGroupNames[$existing->guid][] = $existing->group_name;
+ };
+
+ $products = MarketplaceService::getMarketplaceProducts();
+
+ foreach ($products as $product) {
+ /* @var $product Products1c */
+ if (in_array($product->id, array_keys($existingMapGuidGroupNames))
+ && (in_array('marketplace', $existingMapGuidGroupNames[$product->id]))) {
+ $matrixErp = MatrixErp::findOne(['guid' => $product->id]);
+ if ($matrixErp->components != $product->components) {
+ $matrixErpPropertyDynamic1 = MatrixErpPropertyDynamic::findOne(['product_id' => $matrixErp->guid, 'category' => 1]);
+ /* @var MatrixErpPropertyDynamic $matrixErpPropertyDynamic1 */
+ if ($matrixErpPropertyDynamic1) {
+ $matrixErpPropertyDynamic1->date_end = date("Y-m-d H:i:s");
+ $matrixErpPropertyDynamic1->save();
+ if ($matrixErpPropertyDynamic1->getErrors()) {
+ var_dump($matrixErpPropertyDynamic1->getErrors());
+ }
+ }
+ $matrixErpPropertyDynamic2 = new MatrixErpPropertyDynamic;
+ $matrixErpPropertyDynamic2->product_id = $matrixErp->guid;
+ $matrixErpPropertyDynamic2->value = $product->components;
+ $matrixErpPropertyDynamic2->category = 1;
+ $matrixErpPropertyDynamic2->date_from = date("Y-m-d H:i:s");
+ $matrixErpPropertyDynamic2->date_end = '2100-01-01 00:00:00';
+ $matrixErpPropertyDynamic2->save();
+ if ($matrixErpPropertyDynamic2->getErrors()) {
+ var_dump($matrixErpPropertyDynamic2->getErrors());
+ }
+ }
+ if ($matrixErp->articule != $product->articule) {
+ $matrixErpPropertyDynamic1 = MatrixErpPropertyDynamic::findOne(['product_id' => $matrixErp->guid, 'category' => 2]);
+ /* @var MatrixErpPropertyDynamic $matrixErpPropertyDynamic1 */
+ if ($matrixErpPropertyDynamic1) {
+ $matrixErpPropertyDynamic1->date_end = date("Y-m-d H:i:s");
+ $matrixErpPropertyDynamic1->save();
+ if ($matrixErpPropertyDynamic1->getErrors()) {
+ var_dump($matrixErpPropertyDynamic1->getErrors());
+ }
+ }
+ $matrixErpPropertyDynamic2 = new MatrixErpPropertyDynamic;
+ $matrixErpPropertyDynamic2->product_id = $matrixErp->guid;
+ $matrixErpPropertyDynamic2->value = $product->articule;
+ $matrixErpPropertyDynamic2->category = 2;
+ $matrixErpPropertyDynamic2->date_from = date("Y-m-d H:i:s");
+ $matrixErpPropertyDynamic2->date_end = '2100-01-01 00:00:00';
+ $matrixErpPropertyDynamic2->save();
+ if ($matrixErpPropertyDynamic2->getErrors()) {
+ var_dump($matrixErpPropertyDynamic2->getErrors());
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m250414_094332_create_table_matrix_erp_property_dynamic
+ */
+class m250414_094332_create_table_matrix_erp_property_dynamic extends Migration
+{
+ const TABLE_NAME = 'erp24.matrix_erp_property_dynamic';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+ if (!isset($tableSchema)) {
+ $this->createTable(self::TABLE_NAME, [
+ 'id' => $this->primaryKey(),
+ 'product_id' => $this->string(36)->notNull()->comment('GUID товара из таблицы products_1c'),
+ 'value' => $this->text()->null()->comment('значение components при category = 1, articule при category = 2'),
+ 'category' => $this->integer()->notNull()->comment('1 - value = components, 2 - value = articule'),
+ 'date_from' => $this->dateTime()->notNull()->comment('Дата и время начала активности'),
+ 'date_end' => $this->dateTime()->null()->comment('Дата и время окончания активности'),
+ 'active' => $this->tinyInteger()->notNull()->defaultValue(1)->comment('Активность записи'),
+ ]);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $tableSchema = $this->db->getTableSchema(self::TABLE_NAME);
+
+ if (isset($tableSchema)) {
+ $this->dropTable(self::TABLE_NAME);
+ }
+ }
+}
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "matrix_erp_property_dynamic".
+ *
+ * @property int $id
+ * @property string $product_id GUID товара из таблицы products_1c
+ * @property string|null $value значение components при category = 1, articule при category = 2
+ * @property int $category 1 - value = components, 2 - value = articule
+ * @property string $date_from Дата и время начала активности
+ * @property string|null $date_end Дата и время окончания активности
+ * @property int $active Активность записи
+ */
+class MatrixErpPropertyDynamic extends \yii\db\ActiveRecord
+{
+ /**
+ * {@inheritdoc}
+ */
+ public static function tableName()
+ {
+ return 'matrix_erp_property_dynamic';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [['product_id', 'category', 'date_from'], 'required'],
+ [['value'], 'string'],
+ [['category', 'active'], 'default', 'value' => null],
+ [['category', 'active'], 'integer'],
+ [['date_from', 'date_end'], 'safe'],
+ [['product_id'], 'string', 'max' => 36],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id' => 'ID',
+ 'product_id' => 'Product ID',
+ 'value' => 'Value',
+ 'category' => 'Category',
+ 'date_from' => 'Date From',
+ 'date_end' => 'Date End',
+ 'active' => 'Active',
+ ];
+ }
+}