]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Перенос функционала каталога
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 21 Nov 2024 05:49:24 +0000 (08:49 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 21 Nov 2024 05:49:24 +0000 (08:49 +0300)
erp24/controllers/ProductsController.php
erp24/views/products/ajax-group-config.php
erp24/views/products/products-1c.php

index 429e8153d3264c613d598f878cc99ae187d0db5b..417f4cad13d65e79dcb672ca3396732dc751a6d9 100755 (executable)
 
 namespace app\controllers;
 
+use Yii;
+use yii\helpers\Html;
 use yii\web\Controller;
+use yii_app\records\Prices;
+use yii_app\records\Products1c;
+use yii_app\records\Products1cOptions;
+use yii_app\records\ProductsClass;
+use yii_app\records\ProductsVarieties;
+use yii_app\records\ShipmentProviders;
 
 class ProductsController extends Controller
 {
-    public function actionProducts1c() { return $this->render('products-1c'); }
+    public function actionProducts1c() {
+
+        $id = Yii::$app->request->get('id', null);
+        if (!empty($id)) {
+            $id = (int) $id;
+        }
+
+
+        $productsClassData = ProductsClass::find()->all();
+        $products_class_row = [];
+        foreach ($productsClassData as $row) {
+
+            $products_class_row[$row->category_id][] = $row->tip;
+        }
+
+
+        $pricesData = Prices::find()->all();
+        $prices = [];
+        foreach ($pricesData as $row) {
+
+            $prices[$row->product_id] = $row->price;
+        }
+
+
+        $groupsData = Products1c::find()
+            ->select(['id', 'name', 'parent_id'])
+            ->where(['tip' => 'products_group'])
+            ->orderBy(['name' => SORT_ASC])
+            ->all();
+
+        $groups = [];
+        $groups_arr = [];
+        foreach ($groupsData as $row) {
+
+            $groups[$row->id] = $row->name;
+
+            $groups_arr[$row->parent_id][$row->id] = $row;
+        }
+
+
+        return $this->render('products-1c', [
+            'id' => $id,
+            'products_class_row' => $products_class_row,
+            'prices' => $prices,
+            'groups' => $groups,
+            'groups_arr' => $groups_arr,
+        ]);
+
+
+    }
     public function actionAjaxProductProvider() { return $this->renderPartial('ajax-product-provider'); }
-    public function actionAjaxGroupConfig() { return $this->renderPartial('ajax-group-config'); }
-    public function actionAjaxProductsInGroup() { return $this->renderPartial('ajax-products-in-group'); }
+    public function actionAjaxGroupConfig() {
+
+        if (Yii::$app->request->isAjax) {
+            $id = Yii::$app->request->post('id');
+            if (!empty($id)) {
+                $id = htmlentities($id);
+
+
+                $data = ProductsClass::find()->where(['category_id' => $id])->all();
+                $data2 = [];
+                foreach ($data as $row) {
+                    $data2[$row->tip] = $id;
+                }
+
+                $array = [
+                    "wrap" => "Упаковка",
+                    "potted" => "Горшечка",
+                    "services" => "Услуги",
+                    "services_delivery" => "Услуги по доставке",
+                    "salut" => "Пиротехника",
+                    "matrix" => "Матрица",
+                    "marketplace" => "Товары для маркетплейсов",
+                    "marketplace_additional" => "Доп. товары для маркетплейсов",
+                    "related" => "Сопутка",
+                    "other_items" => "Номенклатура 1%"
+                ];
+
+                $dataString = '<table class=""><tbody>';
+
+                foreach($array as $k => $arr) {
+                    $dataString .= "<tr><td class=\"tixt-right\">$arr</td><td> ";
+                    if(!empty( $data2[$k] ))   {
+                        $dataString .= '<div class="dd' . $id . '' . $k .
+                            ' btn btn-sm btn-danger" onclick="ajax_class_group_remove(\'' . $id . '\',\'' . $k . '\'); " >удалить</div>';
+                    }
+                    else {
+                        $dataString .= '<div class="dd'.$id.''.$k.' dd'.$id.' btn btn-sm btn-success"  onclick="ajax_class_group(\''.$id.'\',\''.$k.'\'); " > добавить</div>';
+                    }
+
+                    $dataString .= ' ('.$k.')</td></tr>';
+                }
+                $dataString .= '</tbody></table>';
+
+
+            return $dataString;
+
+            }
+        }
+
+        return '';
+
+
+
+    }
+    public function actionAjaxProductsInGroup() {
+
+        if (Yii::$app->request->isAjax) {
+            $parent_id = Yii::$app->request->post('parent_id');
+            if (!empty($parent_id)) {
+                $parent_id = htmlentities($parent_id);
+
+
+                $data = Products1c::find()
+                    ->alias('p')
+                    ->select(['p.id', 'p.name', 'e.entity_id', 'p.view'])
+                    ->leftJoin('export_import_table e', "e.export_iD = p.id AND e.export_val = '1' AND e.entity = 'products'")
+                    ->where(['p.tip' => 'products', 'p.parent_id' => $parent_id])
+                    ->orderBy(['p.name' => SORT_ASC])
+                    ->asArray()
+                    ->all();
+
+
+                $prices = Prices::find()
+                    ->select(['product_id', 'price'])
+                    ->indexBy('product_id')
+                    ->column();
+
+
+                $providers = ShipmentProviders::find()
+                    ->select(['id', 'name'])
+                    ->indexBy('id')
+                    ->column();
+
+
+                $optionsData = Products1cOptions::find()
+                    ->select(['id', 'colors'])
+                    ->all();
+
+                $colorsProducts = [];
+                foreach ($optionsData as $option) {
+                    $colorsProducts[$option->id] = explode(';', $option->colors);
+                }
+
+
+                $varietiesData = ProductsVarieties::find()
+                    ->select(['product_id', 'color', 'name'])
+                    ->orderBy(['posit' => SORT_DESC])
+                    ->all();
+
+                $products_varieties = [];
+                foreach ($varietiesData as $variety) {
+                    $products_varieties[$variety->product_id][$variety->color][] = $variety->name;
+                }
+
+
+               /* return $this->renderPartial('ajax-products-in-group', [
+                    'data' => $data,
+                    'prices' => $prices,
+                    'providers' => $providers,
+                    'colorsProducts' => $colorsProducts,
+                    'products_varieties' => $products_varieties,
+                ]);*/
+            }
+        }
+
+        // Возвращаем пустой ответ, если запрос не AJAX или parent_id пустой
+        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'); }
-}
\ No newline at end of file
+
+    public function build_tree($cats, $parent_id, $products_class_row, $only_parent = false)
+    {
+        $products_class = [
+            "wrap" => "Упаковка",
+            "potted" => "Горшечка",
+            "services" => "Услуги",
+            "services_delivery" => "Услуги по доставке",
+            "salut" => "Пиротехника",
+            "matrix" => "Матрица",
+            "marketplace" => "Товары для маркетплейсов",
+            "marketplace_additional" => "Доп. товары для маркетплейсов",
+            "related" => "Сопутка",
+            "other_items" => "Номенклатура 1%"
+        ];
+
+        $tree = '<ul style="margin-left:30px;">';
+        if ($only_parent == false) {
+            foreach ($cats[$parent_id] ?? [] as $cat) {
+                $tree .= '<li class="grup"><table class="m-0 table table-hover"><tbody>';
+                $tree .= '<tr id="tr_' . $cat->id . '"><td><span class="btn btn-info btn-sm me-2" onclick="if(!document.getElementById(\'trr_' . $cat->id . '\')) ajax_products_in_group(\'' . $cat->id . '\'); $(\'#trr_' . $cat->id . '\').toggle();">+</span>
+                <b>' . Html::encode($cat->name) . '</b><span class="dd' . $cat->id . '">';
+
+                foreach ($products_class_row[$cat->id] ?? [] as $tipi) {
+                    $tree .= ' <span class="tag m-1 tag-info">' . Html::encode($products_class[$tipi]) . '  </span> ';
+                }
+
+                $tree .= '</span>
+                 <span  class="btn btn-light btn-sm" onclick="ajax_group_config(\'' . $cat->id . '\'); ">настройки</span>
+                 </td>';
+
+                $tree .= '</tr></tbody></table>';
+                $tree .= $this->build_tree($cats, $cat->id, $products_class_row);
+                $tree .= '</li>';
+            }
+        }
+        $tree .= '</ul>';
+
+        return $tree;
+    }
+
+}
index 042f73a31428bae2a97500150235e4e7f462caa1..a7530bdd0017a14377a50afc7e0d41425d9bf517 100644 (file)
@@ -1,5 +1,5 @@
 <?php
 
-chdir(__DIR__ . '/../../');
+/*chdir(__DIR__ . '/../../');
 
-include 'modul/products/ajax_group_config.php';
+include 'modul/products/ajax_group_config.php';*/
index 03862865202648079d10d4c1ac8d57f9f4e7b442..06d9d93f9d85fafa211026bfa5e348d51c654087 100644 (file)
@@ -1,5 +1,106 @@
 <?php
 
-chdir(__DIR__ . '/../../');
+/*chdir(__DIR__ . '/../../');
 
-include 'modul/products/products_1c.php';
\ No newline at end of file
+include 'modul/products/products_1c.php';*/
+
+
+/* @var $this yii\web\View */
+/* @var $id integer */
+/* @var $products_class_row array */
+/* @var $prices array */
+/* @var $groups array */
+/* @var $groups_arr array */
+
+use yii\helpers\Html;
+
+$this->title = 'Каталог 1С';
+?>
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <div class="groups">
+        <div class="table-responsive">
+            <?= $this->context->build_tree($groups_arr, "", $products_class_row) ?>
+        </div>
+    </div>
+    <hr>
+
+    <!-- MODAL -->
+    <div class="modal fade" id="modal-7">
+        <div class="modal-dialog modal-dialog-centered text-center" role="document">
+            <div class="modal-content modal-content-demo">
+                <div class="modal-header">
+                    <h6 class="modal-title"></h6>
+                    <button aria-label="Close" class="btn-close" data-bs-dismiss="modal" type="button">
+                        <span aria-hidden="true">&times;</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+
+                </div>
+                <div class="modal-footer">
+                    <button class="btn btn-secondary" data-bs-dismiss="modal" type="button">Закрыть</button>
+                </div>
+            </div>
+        </div>
+    </div>
+
+<?php
+// Регистрация JavaScript-кода
+$this->registerJs(<<<JS
+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: 'html',
+        data: {parent_id: '' + parent_id + '', [param3]: token3},
+        success: function(data) {
+            $('#tr_' + parent_id).after('<tr id="trr_' + parent_id + '"><td colspan="2">' + data + '</td></tr>');
+        }
+    });
+}
+
+// Добавьте остальные функции JavaScript аналогично
+JS
+    , \yii\web\View::POS_END);
+?>
\ No newline at end of file