]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
add products item list
authorAlexander Smirnov <fredeom@mail.ru>
Sat, 27 Apr 2024 14:25:14 +0000 (17:25 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Sat, 27 Apr 2024 14:25:14 +0000 (17:25 +0300)
erp24/api3/modules/v1/controllers/ProductController.php [new file with mode: 0644]

diff --git a/erp24/api3/modules/v1/controllers/ProductController.php b/erp24/api3/modules/v1/controllers/ProductController.php
new file mode 100644 (file)
index 0000000..e858c89
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace yii_app\api3\modules\v1\controllers;
+
+use Yii;
+use yii\helpers\ArrayHelper;
+use yii_app\records\Prices;
+use yii_app\records\Products1c;
+
+class ProductController extends \yii_app\api3\controllers\NoActiveController
+{
+    public function actionItemList() {
+
+        $pricesData = Prices::find()->all();
+        $prices = ArrayHelper::map($pricesData, 'product_id', 'price');
+
+        $parentData = Products1c::find()
+            ->select(['id', 'name'])
+            ->where(['tip' => 'products_group'])
+            ->all();
+        $parent = ArrayHelper::map($parentData, 'id', 'name');
+
+        $noData = Products1C::find()
+            ->select('id')
+            ->where(['tip' => 'products_group'])
+            ->andWhere(['or', ['like', 'name', 'категории А'], ['like', 'name', 'духи']])
+            ->all();
+        $no = ArrayHelper::getColumn($noData, 'id');
+
+        $productsData = Products1C::find()
+            ->where(['tip' => 'products', 'view' => 1])
+            ->andWhere(['not in', 'parent_id', $no])
+            ->orderBy('name ASC')
+            ->all();
+
+        $products = [];
+        foreach ($productsData as $product) {
+            if (isset($prices[$product->id])) {
+                $products[] = [
+                    $product->id,
+                    trim($product->name),
+                    trim($parent[$product->parent_id] ?? null),
+                    $prices[$product->id]
+                ];
+            }
+        }
+
+        return $products;
+
+    }
+}