]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-399] matrix_erp_property_dynamic
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 14 Apr 2025 11:39:56 +0000 (14:39 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 14 Apr 2025 11:39:56 +0000 (14:39 +0300)
erp24/commands/MatrixErpController.php [new file with mode: 0644]
erp24/migrations/m250414_094332_create_table_matrix_erp_property_dynamic.php [new file with mode: 0755]
erp24/records/MatrixErpPropertyDynamic.php [new file with mode: 0644]

diff --git a/erp24/commands/MatrixErpController.php b/erp24/commands/MatrixErpController.php
new file mode 100644 (file)
index 0000000..f88523b
--- /dev/null
@@ -0,0 +1,75 @@
+<?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
diff --git a/erp24/migrations/m250414_094332_create_table_matrix_erp_property_dynamic.php b/erp24/migrations/m250414_094332_create_table_matrix_erp_property_dynamic.php
new file mode 100755 (executable)
index 0000000..58a94ad
--- /dev/null
@@ -0,0 +1,42 @@
+<?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);
+        }
+    }
+}
diff --git a/erp24/records/MatrixErpPropertyDynamic.php b/erp24/records/MatrixErpPropertyDynamic.php
new file mode 100644 (file)
index 0000000..f5b660e
--- /dev/null
@@ -0,0 +1,58 @@
+<?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',
+        ];
+    }
+}