From: kirostumm Date: Wed, 10 Jan 2024 07:05:47 +0000 (+0300) Subject: api integrations update X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=646b776af58cd56092f61e8dcceafd3296a96a6a;p=yii-erp24%2F.git api integrations update --- diff --git a/erp24/controllers/ApiController.php b/erp24/controllers/ApiController.php new file mode 100644 index 0000000..fec55e3 --- /dev/null +++ b/erp24/controllers/ApiController.php @@ -0,0 +1,355 @@ +select([ + 'id', + 'name' + ]) + ->asArray() + ->all(); + + $entityArr = []; + $cnt = 0; + + if ($entity === 'admin') { + $admins = Admin::find() + ->select([ + 'id', + 'name' + ]) + ->where(['>', 'group_id', 3]) + ->asArray() + ->all(); + + $entityArr = $admins; + $cnt = count($entityArr); + + } else if ($entity === 'city_store') { + $cityStore = CityStore::find() + ->select([ + 'name', + 'id' + ]) + ->asArray() + ->all(); + + $entityArr = $cityStore; + $cnt = count($entityArr); + + } else if ($entity === 'products') { + $infoItemsTableShop0 = InfoItemsTableShop0::find() + ->select([ + 'name' => 'title', + 'id' => 'item_id' + ]) + ->where([ + 'cat_items_id' => [ + 2, + 1219, + 1220, + 1224, + 1225, + 1226, + 1227 + ] + ]) + ->orderBy([ + 'cat_items_id' => SORT_ASC, + 'title' => SORT_ASC + ]) + ->limit(3000) + ->asArray() + ->all(); + + $entityArr = $infoItemsTableShop0; + + $balancesItems = Balances::find() + ->select([ + 'product_id', + 'quantity' + ]) + ->where([ + 'store_id' => "dbd70103-2c7b-11e9-9b87-c85b76f0e893" + ]) + ->asArray() + ->all(); + + $balances = ArrayHelper::map($balancesItems, 'product_id', 'quantity'); + $cnt = count($balances); + + } + + $expotImportTableItems = ExportImportTable::find() + ->where([ + 'entity' => $entity, + 'export_id' => $export_id + ]) + ->asArray() + ->all(); + + $inSore = ArrayHelper::map($expotImportTableItems, 'entity_id', 'export_val'); + $idgrid = ArrayHelper::getColumn($expotImportTableItems, 'export_val'); + + $products1C = []; + $entity___arr = []; + $entity___arr0 = []; + if ($entity === 'city_store') { + $products1C = Products1c::find() + ->where([ + 'AND', + ['tip' => 'city_store'], + ['view' => 1] + ]) + ->asArray() + ->all(); + + + } else if ($entity === 'admin') { + $expotImportTableItems = ExportImportTable::find() + ->select([ + 'export_val', + 'entity_id' + ]) + ->where([ + 'AND', + ['entity' => 'admin'], + ['export_id' => 1] + ]) + ->asArray() + ->all(); + + foreach ($expotImportTableItems as $expotImportTableItem) { + Admin::updateAll(['guid' => $expotImportTableItem['export_val']], ['id' => $expotImportTableItem['entity_id']]); + } + + Products1c::updateAll(['tip' => 'admin'], ['tip' => 'sellers']); + $products1C = Products1c::find() + ->where([ + 'tip' => 'admin' + ]) + ->asArray() + ->all(); + + foreach ($products1C as $row) { + $entity___arr[$row["id"]] = $row["name"] . ""; + $entity___arr0[$row["id"]] = $row["name"]; + } + + } else if ($entity === 'products') { + $products1C = Products1c::find() + ->where([ + 'tip' => 'products_group' + ]) + ->asArray() + ->all(); + + $group = ArrayHelper::map($products1C, 'id', 'name'); + + $products1C = Products1c::find() + ->select([ + 'name', + 'id', + 'parent_id' + ]) + ->where([ + 'tip' => 'products' + ]) + ->asArray() + ->all(); + + foreach ($products1C as $row) { + $entity___arr[$row["id"]] = $row["name"] . " (" . $group[$row["parent_id"]] . ")"; + $entity___arr0[$row["id"]] = $row["name"]; + } + } + + $dataProvider = new ArrayDataProvider([ + 'allModels' => $entityArr + ]); + + $columns = [ + [ + 'label' => 'ID в ERP', + 'value' => function ($model) { + return $model['id']; + } + ], + [ + 'label' => 'Название в ERP', + 'value' => function ($model) { + return $model['name']; + } + ], + [ + 'label' => 'Название в интеграции', + 'format' => 'raw', + 'value' => function ($model) use ($entity___arr, $inSore) { + if (isset($inSore[$model['id']])) { + return $entity___arr[$inSore[$model['id']]] ?? ''; + } + return ''; + } + ], + [ + 'label' => 'GUID или ID', + 'format' => 'raw', + 'value' => function ($model) use ($inSore) { + return Html::input('string', '', $inSore[$model['id']] ?? '', ['class' => 'form-control guid_input']); + } + ], + [ + 'label' => 'Поиск и сопоставление в интеграции', + 'format' => 'raw', + 'value' => function ($model) use ($inSore) { + return Select2::widget([ + 'name' => $model['id'], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"), + ], + 'ajax' => [ + 'url' => 'poisk-item', + 'dataType' => 'json', + 'data' => new JsExpression('function(params) { return {q:params.term}; }') + ], + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), + 'templateResult' => new JsExpression('function(city) { return city.text; }'), + 'templateSelection' => new JsExpression('function (city) { return city.text; }'), + ], + ]); + } + ], + ]; + + return $this->render('integrations_index', [ + 'entity' => $entity, + 'export_id' => $export_id, + 'exportImportIntegrationsList' => $exportImportIntegrationsList, + 'products1C' => $products1C, + 'idgrid' => $idgrid, + 'dataProvider' => $dataProvider, + 'columns' => $columns + ]); + } + + public function actionIntegrationSave() + { + if (Yii::$app->request->post('id')) { + $entity = Yii::$app->request->post('entity'); + $export_id = Yii::$app->request->post('export_id'); + $value = Yii::$app->request->post('val'); + $inid = Yii::$app->request->post('id'); + $expold = Yii::$app->request->post('expold'); + + if ($entity == "admin" && $export_id == 1) { + $admin = Admin::findOne(['id' => $inid]); + $admin->guid = $value; + $admin->save(); + return "Обновили admin id=$inid guid= $value "; + } + + if ($expold != $value or $expold == '') { + + $exportImportTableItem = new ExportImportTable(['export_id' => $export_id, 'entity' => $entity, 'entity_id' => $inid, 'export_val' => $value]); + $exportImportTableItem->save(); + + $apiIntegrationLogs = new ApiIntegrationLogs(['admin_id' => Yii::$app->user->id, 'date' => time(), 'export_id' => $export_id, 'entity' => $entity, 'entity_id' => $inid, 'export_val' => $value, 'export_val_old' => $expold]); + $apiIntegrationLogs->save(); + return "Данные сохранены"; + } + } + } + + public function actionPoiskItem() + { + $tip = "admin"; + + $s = Yii::$app->request->post('search'); + $id = Yii::$app->request->post('id'); + $tip = Yii::$app->request->post('tip'); + $tip = Yii::$app->request->post('entity') ?? $tip; + + if (strlen($s) > 2) { + + if ($tip == "products" or $tip == "product") { + $products1C = Products1c::find() + ->select([ + 'id', + 'name' + ]) + ->where([ + 'tip' => 'products_group' + ]) + ->asArray() + ->all(); + + $group = ArrayHelper::map($products1C, 'id', 'name'); + + $data = Products1c::find() + ->select([ + 'products_1c.id', + 'products_1c.parent_id', + 'products_1c.name', + 'products_1c.code', + 'products_1c.articule', + 'prices.price' + ]) + ->innerJoin('prices', 'products_1c.id = prices.product_id') + ->where([ + 'AND', + ['products_1c.tip' => 'products'], + ['LIKE', 'products_1c.name', '%' . $s . '%', false], + ]) + ->orderBy(['prices.price' => SORT_DESC]) + ->limit(20) + ->asArray() + ->all(); + + } else if ($tip == 'admin') { + $data = Products1c::find() + ->select([ + 'products_1c.id', + 'products_1c.name', + ]) + ->where([ + 'AND', + ['products_1c.tip' => 'admin'], + ['LIKE', 'products_1c.name', '%' . $s . '%', false], + ]) + ->orderBy(['products_1c.name' => SORT_ASC]) + ->limit(20) + ->asArray() + ->all(); + + } + + + + return $data; + } + } +} \ No newline at end of file diff --git a/erp24/records/Admin.php b/erp24/records/Admin.php index 9906770..58a3d02 100755 --- a/erp24/records/Admin.php +++ b/erp24/records/Admin.php @@ -25,6 +25,7 @@ use yii\web\IdentityInterface; * @property int $vcompany Пользователь является человеком * @property string store_arr * @property string $popular_modules + * @property string $guid * @package yii_app\records */ class Admin extends ActiveRecord implements IdentityInterface diff --git a/erp24/records/ApiIntegrationLogs.php b/erp24/records/ApiIntegrationLogs.php new file mode 100644 index 0000000..b887ac4 --- /dev/null +++ b/erp24/records/ApiIntegrationLogs.php @@ -0,0 +1,59 @@ + 36], + [['export_val', 'export_val_old'], 'string', 'max' => 120], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'export_id' => 'Export ID', + 'entity_id' => 'Entity ID', + 'entity' => 'Entity', + 'date' => 'Date', + 'export_val' => 'Export Val', + 'export_val_old' => 'Export Val Old', + 'admin_id' => 'Admin ID', + ]; + } +} diff --git a/erp24/records/ExportImportIntegrations.php b/erp24/records/ExportImportIntegrations.php new file mode 100644 index 0000000..73cc2a4 --- /dev/null +++ b/erp24/records/ExportImportIntegrations.php @@ -0,0 +1,44 @@ + 200], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'name' => 'Name', + ]; + } +} diff --git a/erp24/records/InfoItemsTableShop0.php b/erp24/records/InfoItemsTableShop0.php new file mode 100644 index 0000000..f18285b --- /dev/null +++ b/erp24/records/InfoItemsTableShop0.php @@ -0,0 +1,257 @@ + 32], + [['id_1c'], 'string', 'max' => 36], + [['title_from_url', 'title_url', 'image', 'image_sm', 'title_proizv'], 'string', 'max' => 255], + [['user_ip'], 'string', 'max' => 15], + [['nick'], 'string', 'max' => 35], + [['razmer', 'articul_proizv'], 'string', 'max' => 155], + [['srok'], 'string', 'max' => 20], + [['setka_arr'], 'string', 'max' => 150], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'item_id' => 'Item ID', + 'title' => 'Title', + 'price' => 'Price', + 'f_id' => 'F ID', + 'kod' => 'Kod', + 'id_1c' => 'Id 1c', + 'cat_items_id' => 'Cat Items ID', + 'cat_id_ishod' => 'Cat Id Ishod', + 'cat_items_id_dop' => 'Cat Items Id Dop', + 'cat_items_catalog_arr' => 'Cat Items Catalog Arr', + 'group_arr' => 'Group Arr', + 'tag_arr' => 'Tag Arr', + 'tags' => 'Tags', + 'tag_main' => 'Tag Main', + 'site_id' => 'Site ID', + 'sites_arr' => 'Sites Arr', + 'modul_id' => 'Modul ID', + 'data' => 'Data', + 'data_edit' => 'Data Edit', + 'data_edit_images' => 'Data Edit Images', + 'admin_id_edit' => 'Admin Id Edit', + 'data_start' => 'Data Start', + 'data_end' => 'Data End', + 'title_from_url' => 'Title From Url', + 'title_url' => 'Title Url', + 'title_url_dop' => 'Title Url Dop', + 'description' => 'Description', + 'description2' => 'Description2', + 'proizvoditel_id' => 'Proizvoditel ID', + 'content' => 'Content', + 'url' => 'Url', + 'image' => 'Image', + 'image_sm' => 'Image Sm', + 'price_zakup' => 'Price Zakup', + 'price_zakup_up' => 'Price Zakup Up', + 'price_old' => 'Price Old', + 'price_individ' => 'Price Individ', + 'price_m2' => 'Price M2', + 'm2_korobka' => 'M2 Korobka', + 'counter' => 'Counter', + 'counter_down' => 'Counter Down', + 'counter_com' => 'Counter Com', + 'counter_poll' => 'Counter Poll', + 'avg_ball' => 'Avg Ball', + 'order' => 'Order', + 'seo_title' => 'Seo Title', + 'seo_description' => 'Seo Description', + 'seo_keywords' => 'Seo Keywords', + 'user_ip' => 'User Ip', + 'user_access' => 'User Access', + 'user_id' => 'User ID', + 'nick' => 'Nick', + 'admin_id' => 'Admin ID', + 'moderator' => 'Moderator', + 'comments' => 'Comments', + 'video' => 'Video', + 'rss' => 'Rss', + 'status' => 'Status', + 'visible' => 'Visible', + 'rasprodazha' => 'Rasprodazha', + 'sale' => 'Sale', + 'sale_city_id' => 'Sale City ID', + 'instock' => 'Instock', + 'price_down' => 'Price Down', + 'price_30day' => 'Price 30day', + 'action' => 'Action', + 'exclusive' => 'Exclusive', + 'novinka' => 'Novinka', + 'hit' => 'Hit', + 'speed_delivery' => 'Speed Delivery', + 'super_price' => 'Super Price', + 'in_lp' => 'In Lp', + 'shop_dop' => 'Shop Dop', + 'shop_table' => 'Shop Table', + 'show_in_catalog' => 'Show In Catalog', + 'dop_items' => 'Dop Items', + 'default_on' => 'Default On', + 'kol' => 'Kol', + 'razmer' => 'Razmer', + 'dlina' => 'Dlina', + 'glubina' => 'Glubina', + 'visota' => 'Visota', + 'shirina' => 'Shirina', + 'kol_mest' => 'Kol Mest', + 'massa' => 'Massa', + 'molar_volume' => 'Molar Volume', + 'srok' => 'Srok', + 'title_proizv' => 'Title Proizv', + 'articul_proizv' => 'Articul Proizv', + 'shop_vmeste_array' => 'Shop Vmeste Array', + 'price_idivid' => 'Price Idivid', + 'colors_array' => 'Colors Array', + 'mmebel' => 'Mmebel', + 'krovat_osnova' => 'Krovat Osnova', + 'clear_tag' => 'Clear Tag', + 'items_id_site' => 'Items Id Site', + 'items_id_clon' => 'Items Id Clon', + 'archive' => 'Archive', + 'sostav' => 'Sostav', + 'setka_arr' => 'Setka Arr', + 'city_arr' => 'City Arr', + 'city_all' => 'City All', + 'no_bonus' => 'No Bonus', + ]; + } +} diff --git a/erp24/views/api/integrations_index.php b/erp24/views/api/integrations_index.php new file mode 100644 index 0000000..e416e82 --- /dev/null +++ b/erp24/views/api/integrations_index.php @@ -0,0 +1,104 @@ +registerJs(<<'+data+''); + } + }); + } + +JS); +?> + +
+

Интеграции

+ + $item['id'], 'entity' => $entity], + [ + 'class' => 'btn btn-' . (($export_id == $item['id']) ? 'success' : 'info'), + ] + ) ?> + + +

Списки для Интеграции

+ "Магазины", "products" => "Товары и услуги", "admin" => "Сотрудники"); ?> + + $item) : ?> + $export_id, 'entity' => $key], + [ + 'class' => 'btn btn-' . (($entity == $key) ? 'success' : 'info'), + ] + ) ?> + + + + + +
+ + + + + $dataProvider, + 'columns' => $columns + ]) ?> +