From 4aa446000b6e0bdccdae19831e33d618953176ba Mon Sep 17 00:00:00 2001 From: fomichev Date: Thu, 21 Nov 2024 18:08:45 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20?= =?utf8?q?=D0=B8=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BA=D0=BE?= =?utf8?q?=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/ProductsController.php | 212 ++++++++++-------- .../modul/products/ajax_product_provider.php | 2 +- .../modul/products/ajax_products_in_group.php | 2 +- erp24/records/Products1cOptions.php | 4 +- erp24/records/ProductsClass.php | 13 ++ erp24/views/products/_tree.php | 47 ++++ erp24/views/products/products-1c.php | 116 ++++------ erp24/web/js/products/products-1c.js | 185 +++++++++++++++ 8 files changed, 406 insertions(+), 175 deletions(-) create mode 100644 erp24/views/products/_tree.php create mode 100644 erp24/web/js/products/products-1c.js diff --git a/erp24/controllers/ProductsController.php b/erp24/controllers/ProductsController.php index 21e562ec..5cdd39e5 100755 --- a/erp24/controllers/ProductsController.php +++ b/erp24/controllers/ProductsController.php @@ -288,131 +288,155 @@ class ProductsController extends Controller } - $dataResponse .= ''; - foreach ($data as $row) { - - $dataResponse .= "asJson([ + 'data' => $data, + 'prices' => $prices, + 'providers' => $providers, + 'colorsProducts' => $colorsProducts, + 'productsVarieties' => $products_varieties, + 'parent_id' => $parent_id, + ]); + } + return $this->asJson(['error' => 'parent_id не передан']); + } - $row['name']=str_replace('"','',$row['name']); - $row['name']=str_replace("'",'',$row['name']); + return $this->asJson(['error' => 'Неверный запрос']); + } - if($row["view"]==0) { - $dataResponse .= "скрыто"; - } - $dataResponse .= '
+ поставщика '.($providers[$row['id']]??'').'
'; + public function actionAjaxClassGroup() + { + if (Yii::$app->request->isAjax) { + $parent_id = Yii::$app->request->post('parent_id'); + $tip = Yii::$app->request->post('tip', 'wrap'); - if(!empty($colorsProducts[$row["id"]])) { - $s=0; - foreach($colorsProducts[$row["id"]] as $color) { - $color=trim($color); - if(!empty($color)) { - $s++; - $dataResponse .= "
$color"; + if (!empty($parent_id)) { - if(!empty($products_varieties[$row["id"]][$color])) { - $dataResponse .= "сорта "; - foreach($products_varieties[$row["id"]][$color] as $varieties => $nameV) { + $productClass = ProductsClass::findOne(['category_id' => $parent_id]); - $dataResponse .= ' '.$nameV.' '; - } - } - } - } + if (!$productClass) { - if($s>0) { - $dataResponse .= "+ добавить сорта"; - } - } - $dataResponse .= " GUID ".$row["id"]."
"; + return "Ошибка сохранения: " . implode(', ', $productClass->getFirstErrors()); + } + } + return "Ошибка: parent_id не передан."; + } - if(!empty($row["entity_id"])) { - - } + return "Некорректный запрос."; + } + + + public function actionAjaxClassGroupRemove() + { + if (Yii::$app->request->isAjax) { + $id = Yii::$app->request->post('id'); + $tip = Yii::$app->request->post('tip'); + + if (!empty($id) && !empty($tip)) { + $productClass = ProductsClass::findOne(['category_id' => $id, 'tip' => $tip]); + + + if ($productClass) { + if ($productClass->delete()) { + return "Метка удалена"; + } else { + return "Ошибка удаления метки"; + } + } else { + return "Запись не найдена"; } - $dataResponse .= '
"; + $productClass = new ProductsClass(); + $productClass->category_id = $parent_id; + } - if(!empty($prices[$row['id']]) and empty($row["entity_id"])) - $dataResponse .= '
внести цена '.$prices[$row['id']].'
'; - else { - $dataResponse .= '
внести цена '.($prices[$row['id']]??'').'
'; - } - $dataResponse .= "
".$row["entity_id"].""; + $productClass->tip = $tip; - if(!empty($row["entity_id"])) { - $dataResponse .= '
удалить продукт
-
- удалить только связь
'; - } + if ($productClass->save()) { + return "ok"; + } else { - $dataResponse .= "
'; - - } - - return $dataResponse; - /* return $this->renderPartial('ajax-products-in-group', [ - 'data' => $data, - 'prices' => $prices, - 'providers' => $providers, - 'colorsProducts' => $colorsProducts, - 'products_varieties' => $products_varieties, - ]);*/ + return "Ошибка: параметры не переданы"; } - // Возвращаем пустой ответ, если запрос не AJAX или parent_id пустой - return ''; + return "Некорректный запрос"; } - public function actionAjaxClassGroup() { return $this->renderPartial('ajax-class-group'); } - public function actionAjaxClassGroupRemove() { return $this->renderPartial('ajax-class-group-remove'); } + + public function actionAjaxAddProduct() { return $this->renderPartial('ajax-add-product'); } public function actionAjaxRemoveProduct() { return $this->renderPartial('ajax-remove-product'); } public function actionAjaxRemoveExport() { return $this->renderPartial('ajax-remove-export'); } - public function actionAjaxProductProviderAdd() { return $this->renderPartial('ajax-product-provider-add'); } - - public function build_tree($cats, $parent_id, $products_class_row, $only_parent = false) + public function actionAjaxProductProviderAdd() { - $products_class = [ - "wrap" => "Упаковка", - "potted" => "Горшечка", - "services" => "Услуги", - "services_delivery" => "Услуги по доставке", - "salut" => "Пиротехника", - "matrix" => "Матрица", - "marketplace" => "Товары для маркетплейсов", - "marketplace_additional" => "Доп. товары для маркетплейсов", - "related" => "Сопутка", - "other_items" => "Номенклатура 1%" - ]; - - $tree = ''; - return $tree; + return "Некорректный запрос."; } + + } diff --git a/erp24/modul/products/ajax_product_provider.php b/erp24/modul/products/ajax_product_provider.php index 69842857..965adf30 100644 --- a/erp24/modul/products/ajax_product_provider.php +++ b/erp24/modul/products/ajax_product_provider.php @@ -81,7 +81,7 @@ echo'
'; echo" показыввать товар в автозаказе'; echo'
diff --git a/erp24/modul/products/ajax_products_in_group.php b/erp24/modul/products/ajax_products_in_group.php index e96f87f4..490ab3e2 100644 --- a/erp24/modul/products/ajax_products_in_group.php +++ b/erp24/modul/products/ajax_products_in_group.php @@ -5,7 +5,7 @@ include_once(dirname(__DIR__, 2) . "/inc/db.php"); include_once(dirname(__DIR__, 2) . "/inc/base_new.php"); if(!empty($_REQUEST["parent_id"])) { $parent_id=htmlentities($_REQUEST["parent_id"]); -$q = "SELECT p.id, p.name, e.entity_id, p.view FROM products_1c as p LEFT JOIN export_import_table as e ON e.export_id='1' AND e.entity='products' AND e.export_val=p.id WHERE p.tip='products' AND p.parent_id=? order by p.name ASC"; +$q = "SELECT p.id, p.name, e.entity_id, p.view FROM products_1c as p LEFT JOIN export_import_table as e ON e.export_iD e.export_val=p.id='1' AND e.entity='products' ANd WHERE p.tip='products' AND p.parent_id=? order by p.name ASC"; $data = $db::getRows($q,[$parent_id]); diff --git a/erp24/records/Products1cOptions.php b/erp24/records/Products1cOptions.php index 4669c7d8..e2b19555 100644 --- a/erp24/records/Products1cOptions.php +++ b/erp24/records/Products1cOptions.php @@ -34,7 +34,9 @@ class Products1cOptions extends \yii\db\ActiveRecord public function rules() { return [ - [['id', 'options', 'provider_id', 'expiration_days', 'min_lot', 'min_order', 'price_zakup', 'colors'], 'required'], + + [['id', 'options', 'provider_id', 'expiration_days', 'min_lot', 'colors', 'price_zakup', 'min_order', 'group_id', 'main'], 'safe'], + [['id'], 'required'], [['options', 'colors'], 'string'], [['provider_id', 'expiration_days', 'min_lot', 'min_order', 'group_id', 'main'], 'integer'], [['price_zakup'], 'number'], diff --git a/erp24/records/ProductsClass.php b/erp24/records/ProductsClass.php index ab7a8db9..a018cdfc 100755 --- a/erp24/records/ProductsClass.php +++ b/erp24/records/ProductsClass.php @@ -12,6 +12,19 @@ use Yii; */ class ProductsClass extends \yii\db\ActiveRecord { + + const PRODUCTS_CLASS = [ + "wrap" => "Упаковка", + "potted" => "Горшечка", + "services" => "Услуги", + "services_delivery" => "Услуги по доставке", + "salut" => "Пиротехника", + "matrix" => "Матрица", + "marketplace" => "Товары для маркетплейсов", + "marketplace_additional" => "Доп. товары для маркетплейсов", + "related" => "Сопутка", + "other_items" => "Номенклатура 1%" + ]; /** * {@inheritdoc} */ diff --git a/erp24/views/products/_tree.php b/erp24/views/products/_tree.php new file mode 100644 index 00000000..6e8523d0 --- /dev/null +++ b/erp24/views/products/_tree.php @@ -0,0 +1,47 @@ +registerJsFile('/js/products/products-1c.js', ['position' => \yii\web\View::POS_END]); +if (!empty($cats[$parent_id])): ?> + + \ No newline at end of file diff --git a/erp24/views/products/products-1c.php b/erp24/views/products/products-1c.php index dd30810b..47bc0155 100644 --- a/erp24/views/products/products-1c.php +++ b/erp24/views/products/products-1c.php @@ -11,7 +11,7 @@ include 'modul/products/products_1c.php';*/ /* @var $prices array */ /* @var $groups array */ /* @var $groups_arr array */ - +$this->registerJsFile('/js/products/products-1c.js', ['position' => \yii\web\View::POS_END]); use yii\helpers\Html; $this->title = 'Каталог 1С'; @@ -20,7 +20,43 @@ $this->title = 'Каталог 1С';
- context->build_tree($groups_arr, "", $products_class_row) ?> +
    + +
  • + + + + + + +
    + + + name) ?> + + id] ?? [] as $tipi): ?> + + + + + + + настройки + +
    + + render('_tree', [ + 'cats' => $groups_arr, + 'parent_id' => $cat->id, + 'products_class_row' => $products_class_row, + 'products_class' => \yii_app\records\ProductsClass::PRODUCTS_CLASS, + ]) ?> +
  • + +

@@ -45,79 +81,3 @@ $this->title = 'Каталог 1С'; -registerJs(<<' + data + ''); - } - }); -} - -function save_providerder(){ - -const param3 = $('meta[name=csrf-param]').attr('content'); -const token3 = $('meta[name=csrf-token]').attr('content'); - -$.ajax({ - url: '/products/ajax-product-provider-add/', - method: 'post', - dataType: 'html', - data: {id: '', provider_id: $('#provider_id').val(), - options: $('#options').val(), expiration_days: $('#expiration_days').val(), - min_lot: $('#min_lot').val(), colors: $('#colors').val(), min_order: $('#min_order').val(), price_zakup: $('#price_zakup').val(), group_id: $('#group_id').val() , main: $('#main').val() , view: $('#view').val(), [param3]:token3 }, - success: function(data){ - $('#result_prov').html(data); - }}); -} - -// Добавьте остальные функции JavaScript аналогично -JS - , \yii\web\View::POS_END); -?> \ No newline at end of file diff --git a/erp24/web/js/products/products-1c.js b/erp24/web/js/products/products-1c.js new file mode 100644 index 00000000..a4055ab8 --- /dev/null +++ b/erp24/web/js/products/products-1c.js @@ -0,0 +1,185 @@ +//document.addEventListener('DOMContentLoaded', function () { + + function ajax_product_provider(id) { + $('#modal-7').modal('show', {backdrop: 'static'}); + $('#modal-7 .modal-title').text('Поставщики'); + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-product-provider/', + method: 'post', + dataType: 'html', + data: {id: '' + id + '', [param3]: token3}, + success: function(data) { + $('#modal-7 .modal-body').html(data); + } + }); + } + + function ajax_group_config(id) { + $('#modal-7').modal('show', {backdrop: 'static'}); + $('#modal-7 .modal-title').text('Настройка категории'); + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-group-config/', + method: 'post', + dataType: 'html', + data: {id: '' + id + '', [param3]: token3}, + success: function(data) { + + $('#modal-7 .modal-body').html(data); + } + }); + } + + function ajax_products_in_group(parent_id) { + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-products-in-group/', + method: 'post', + dataType: 'json', + data: {parent_id: parent_id, [param3]: token3}, + success: function(response) { + if (response.error) { + alert(response.error); + return; + } + + const { data, prices, providers, colorsProducts, productsVarieties } = response; + + let tableHtml = ''; + + data.forEach((row) => { + const isHidden = row.view === 0 ? 'скрыто' : ''; + const providerButton = `
+ + поставщика ${providers[row.id] ? providers[row.id] : ''}
`; + + let colorsHtml = ''; + if (colorsProducts[row.id]) { + colorsProducts[row.id].forEach((color) => { + color = color.trim(); + if (color) { + colorsHtml += `${color}`; + if (productsVarieties[row.id] && productsVarieties[row.id][color]) { + productsVarieties[row.id][color].forEach((variety) => { + colorsHtml += `${variety}`; + }); + } + } + }); + + if (colorsHtml) { + colorsHtml += `+ добавить сорта`; + } + } + + const addProductButton = `
внести цена ${prices[row.id]}'}
`; + + const removeProductButtons = row.entity_id + ? `
удалить продукт
+
удалить только связь
` + : ''; + + tableHtml += ` + + + + `; + }); + + tableHtml += '
+ ${row.name} ${isHidden} + ${providerButton} + ${colorsHtml} + GUID ${row.id} +
'; + $(`#tr_${parent_id}`).after(`${tableHtml}`); + }, + error: function() { + alert('Ошибка при выполнении запроса.'); + }, + }); + } + + function save_providerder(){ + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-product-provider-add/', + method: 'post', + dataType: 'html', + data: {id: '', + provider_id: $('#provider_id').val(), + options: $('#options').val(), + expiration_days: $('#expiration_days').val(), + min_lot: $('#min_lot').val(), + colors: $('#colors').val(), + min_order: $('#min_order').val(), + price_zakup: $('#price_zakup').val(), + group_id: $('#group_id').val() , + main: $('#main').val() , view: $('#view').val(), [param3]:token3 }, + success: function(data){ + $('#result_prov').html(data); + }}); + } + + + function ajax_add_product(id,parent_id,name,price){ + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-add-product/', + method: 'post', + dataType: 'html', + data: {id: ''+id+'', name: ''+name+'',parent_id: ''+parent_id+'',price: ''+price+'', [param3]:token3}, + success: function(data){ + $('#diver_'+id+'').html(data); + + }}); + } + function ajax_remove_product(id){ + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-remove-product/', + method: 'post', + dataType: 'html', + data: {id: ''+id+'', [param3]:token3}, + success: function(data){ + $('#diver_'+id+'').html(data); + + }}); + } + + + function ajaxRemoveExport(id){ + + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-remove-export/', + method: 'post', + dataType: 'html', + data: {id: ''+id+'', [param3]:token3}, + success: function(data){ + $('#diver2_'+id+'').html(data); + + }}); + } + +//}); \ No newline at end of file -- 2.39.5