From: fomichev Date: Thu, 30 Jan 2025 12:59:14 +0000 (+0300) Subject: Загрузка и сохранение в таблицу X-Git-Tag: 1.7~22^2~1 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=b30666ddc47dc496c7e584d62962d560e5ad98c0;p=erp24_rep%2Fyii-erp24%2F.git Загрузка и сохранение в таблицу --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 6546e08f..7db1e314 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -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 + ) + ); + } + } } } diff --git a/erp24/migrations/m250129_144216_create_table_products_1c_nomenclature.php b/erp24/migrations/m250129_144216_create_table_products_1c_nomenclature.php index 39677ba6..82d637ce 100644 --- a/erp24/migrations/m250129_144216_create_table_products_1c_nomenclature.php +++ b/erp24/migrations/m250129_144216_create_table_products_1c_nomenclature.php @@ -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 index 00000000..0549cc9b --- /dev/null +++ b/erp24/records/Products1cNomenclature.php @@ -0,0 +1,65 @@ + 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' => 'Цвет', + ]; + } +}