]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Загрузка и сохранение в таблицу
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 30 Jan 2025 12:59:14 +0000 (15:59 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 30 Jan 2025 12:59:14 +0000 (15:59 +0300)
erp24/api2/controllers/DataController.php
erp24/migrations/m250129_144216_create_table_products_1c_nomenclature.php
erp24/records/Products1cNomenclature.php [new file with mode: 0644]

index 6546e08fa24f5e07b2fde830cd930b51d7487107..7db1e3141b5e5cf6f43ec3f3955dc58dcd95bf4a 100644 (file)
@@ -29,6 +29,7 @@ use yii_app\records\PaymentTypes;
 use yii_app\records\Prices;
 use yii_app\records\PricesDynamic;
 use yii_app\records\PricesZakup;
+use yii_app\records\Products1cNomenclature;
 use yii_app\records\Products1cPropType;
 use yii_app\records\Products1c;
 use yii_app\records\Products1cAdditionalCharacteristics;
@@ -980,6 +981,100 @@ class DataController extends BaseController
                             }
                         }
                     }
+                    if (
+                        !empty($arr["type"])
+                        && str_starts_with($arr["type"], '[')
+                        && str_ends_with($arr["type"], ']')
+                    ) {
+                       // return [$arr["type"]];
+                        $product1cNomenclature = Products1cNomenclature::find()->where(['id' => $arr["id"]])->one();
+                        if (!$product1cNomenclature) {
+                            $product1cNomenclature = new Products1cNomenclature();
+                            $product1cNomenclature->id = $arr["id"];
+                        }
+                        $typeNomenclature = rtrim(ltrim($arr["type"], '['), ']');
+                        $typeArr = explode("/", $typeNomenclature);
+                        $category = $typeArr[0];
+                        $subcategory = $typeArr[1] ?? null;
+                        $product1cNomenclature->name = $arr["name"];
+                        $product1cNomenclature->location = $arr["type"];
+                        $product1cNomenclature->type_num = $typeNomenclature;
+                        $product1cNomenclature->category = $category;
+                        $product1cNomenclature->subcategory = $subcategory;
+                        $characteristics = Products1cAdditionalCharacteristics::find()
+                            ->select(['property_id', 'value'])
+                            ->where(['product_id' => $arr["id"]])
+                            ->indexBy(['property_id'])
+                            ->asArray()
+                            ->all();
+
+                        $propTypes = array_keys($characteristics);
+                        $propertyNames = Products1cPropType::find()
+                        ->select(['id','name'])
+                        ->where(['id' => $propTypes])
+                        ->indexBy('id')
+                        ->asArray()
+                        ->all();
+                        $characteristicsValues = [];
+
+                        foreach ($propertyNames as $propertyId => $property) {
+                            if (isset($characteristics[$propertyId])) {
+                                $characteristicsValues[$property['name']] = $characteristics[$propertyId]['value'];
+                            }
+                        }
+
+                        $sizeValue = null;
+                        if (isset($characteristicsValues['size']) && intval($characteristicsValues['size'])) {
+                            $sizeValue = $characteristicsValues['size'];
+                        }
+                        if (isset($characteristicsValues['размер']) && intval($characteristicsValues['размер'])) {
+                            $sizeValue = $characteristicsValues['размер'];
+                        }
+
+                        $speciesValue = null;
+                        if (isset($characteristicsValues['species']) && !empty($characteristicsValues['species'])) {
+                            $speciesValue = $characteristicsValues['species'];
+                        }
+                        if (isset($characteristicsValues['вид']) && !empty($characteristicsValues['вид'])) {
+                            $speciesValue = $characteristicsValues['вид'];
+                        }
+
+                        $sortValue = null;
+                        if (isset($characteristicsValues['sort']) && !empty($characteristicsValues['sort'])) {
+                            $sortValue = $characteristicsValues['sort'];
+                        }
+                        if (isset($characteristicsValues['сорт']) && !empty($characteristicsValues['сорт'])) {
+                            $sortValue = $characteristicsValues['сорт'];
+                        }
+
+                        $measureValue = null;
+                        if (isset($characteristicsValues['measure']) && !empty($characteristicsValues['measure'])) {
+                            $measureValue = $characteristicsValues['measure'];
+                        }
+
+                        $colorValue = null;
+                        if (isset($characteristicsValues['color']) && !empty($characteristicsValues['color'])) {
+                            $colorValue = $characteristicsValues['color'];
+                        }
+                        if (isset($characteristicsValues['цвет']) && !empty($characteristicsValues['цвет'])) {
+                            $colorValue = $characteristicsValues['цвет'];
+                        }
+
+                        $product1cNomenclature->species = $speciesValue;
+                        $product1cNomenclature->sort = $sortValue;
+                        $product1cNomenclature->size = $sizeValue;
+                        $product1cNomenclature->measure = $measureValue;
+                        $product1cNomenclature->color = $colorValue;
+
+                        if (!$product1cNomenclature->save()) {
+                            LogService::apiErrorLog(
+                                json_encode(
+                                    ["error_id" => 8.3, "error" => $product1cNomenclature->getErrors()],
+                                    JSON_UNESCAPED_UNICODE
+                                )
+                            );
+                        }
+                    }
                 }
             }
 
index 39677ba68aa7c19d4e3d30aed3a9c3fd4438a472..82d637ce88bd54629139bdce18794cce1012ffbf 100644 (file)
@@ -28,12 +28,12 @@ class m250129_144216_create_table_products_1c_nomenclature extends Migration
                     ->notNull()
                     ->comment('Название вида номенклатуры из логического условия, без квадратных скобок.'),
                 'category' => $this->string()->notNull()->comment('Категория'),
-                'subcategory' => $this->string()->notNull()->comment('Подкатегория'),
-                'species' => $this->string()->comment('Вид'),
-                'sort' => $this->string()->comment('Сорт'),
-                'size' => $this->integer()->comment('Размер'),
-                'measure' => $this->string()->comment('Единица измерения'),
-                'color' => $this->string()->comment('Цвет'),
+                'subcategory' => $this->string()->null()->comment('Подкатегория'),
+                'species' => $this->string()->null()->comment('Вид'),
+                'sort' => $this->string()->null()->comment('Сорт'),
+                'size' => $this->integer()->null()->comment('Размер'),
+                'measure' => $this->string()->null()->comment('Единица измерения'),
+                'color' => $this->string()->null()->comment('Цвет'),
                 'PRIMARY KEY(id)',
             ]);
         }
diff --git a/erp24/records/Products1cNomenclature.php b/erp24/records/Products1cNomenclature.php
new file mode 100644 (file)
index 0000000..0549cc9
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "products_1c_nomenclature".
+ *
+ * @property string $id GUID - уникальный номер номенклатуры в 1С
+ * @property string $location расположение номенклатуры в системе 1С, т.е. путь до папки где храниться номенклатура
+ * @property string $name имя номенклатуры
+ * @property string $type_num Название вида номенклатуры из логического условия, без квадратных скобок.
+ * @property string $category Категория
+ * @property string|null $subcategory Подкатегория
+ * @property string|null $species Вид
+ * @property string|null $sort Сорт
+ * @property int|null $size Размер
+ * @property string|null $measure Единица измерения
+ * @property string|null $color Цвет
+ */
+class Products1cNomenclature extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'products_1c_nomenclature';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['id', 'location', 'name', 'type_num', 'category'], 'required'],
+            [['size', 'species', 'subcategory', 'sort', 'measure', 'color'], 'default', 'value' => null],
+            [['size'], 'integer'],
+            [['id', 'location', 'name', 'type_num', 'category', 'subcategory', 'species', 'sort', 'measure', 'color'], 'string', 'max' => 255],
+            [['id'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'GUID - уникальный номер номенклатуры в 1С',
+            'location' => 'расположение номенклатуры в системе 1С, т.е. путь до папки где храниться номенклатура',
+            'name' => 'имя номенклатуры',
+            'type_num' => 'Название вида номенклатуры из логического условия, без квадратных скобок.',
+            'category' => 'Категория',
+            'subcategory' => 'Подкатегория',
+            'species' => 'Вид',
+            'sort' => 'Сорт',
+            'size' => 'Размер',
+            'measure' => 'Единица измерения',
+            'color' => 'Цвет',
+        ];
+    }
+}