]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-302 Новый интерфейс для работы с заказами мп и амо
authormarina <m.zozirova@gmail.com>
Mon, 3 Mar 2025 06:19:44 +0000 (09:19 +0300)
committermarina <m.zozirova@gmail.com>
Mon, 3 Mar 2025 06:19:44 +0000 (09:19 +0300)
erp24/controllers/MarketplaceOrdersController.php
erp24/views/marketplace-orders/all-orders.php [new file with mode: 0644]

index d655767a106a2440915df93a4bc0cd9b1db81b6b..add0fd36289d6e64e1a7d4dd27fc21550ce2067e 100644 (file)
@@ -4,12 +4,15 @@ namespace app\controllers;
 
 use Yii;
 use yii\base\Exception;
+use yii\data\ArrayDataProvider;
+use yii\db\Query;
 use yii_app\records\MarketplaceOrders;
 use yii_app\records\MarketplaceOrdersSearch;
 use yii\web\Controller;
 use yii\web\NotFoundHttpException;
 use yii\filters\VerbFilter;
 use yii_app\records\MarketplaceOrderStatusTypes;
+use yii_app\records\OrdersAmo;
 use yii_app\services\MarketplaceService;
 
 /**
@@ -232,4 +235,87 @@ class MarketplaceOrdersController extends Controller
 
         throw new NotFoundHttpException('The requested page does not exist.');
     }
+
+
+    public function actionAllOrders()
+    {
+        $queryAmo = (new Query())
+            ->select([
+                new \yii\db\Expression("'amo' AS source"),
+                'id',
+                new \yii\db\Expression('store_id::VARCHAR AS store_id'),
+                new \yii\db\Expression('status_id::BIGINT AS status_id'),
+                'updated_at',
+                new \yii\db\Expression('NULL::VARCHAR AS marketplace_order_id'),
+                new \yii\db\Expression('NULL::VARCHAR AS substatus_id'),
+                new \yii\db\Expression('NULL::VARCHAR AS warehouse_guid'),
+                new \yii\db\Expression('NULL::TIMESTAMP AS creation_date'),
+                new \yii\db\Expression('NULL::TIMESTAMP AS returned_at'),
+                new \yii\db\Expression('NULL::TEXT AS return_data'),
+                new \yii\db\Expression('NULL::INTEGER AS fake'),
+                new \yii\db\Expression('NULL::NUMERIC AS total'),
+                new \yii\db\Expression('NULL::NUMERIC AS delivery_total'),
+                new \yii\db\Expression('NULL::NUMERIC AS buyer_total_before_discount'),
+                new \yii\db\Expression('NULL::VARCHAR AS tax_system'),
+                new \yii\db\Expression('NULL::VARCHAR AS payment_type'),
+                new \yii\db\Expression('NULL::VARCHAR AS payment_method'),
+                new \yii\db\Expression('NULL::BOOLEAN AS cancel_requested'),
+                new \yii\db\Expression('NULL::TEXT AS raw_data'),
+                new \yii\db\Expression('NULL::VARCHAR AS guid'),
+                new \yii\db\Expression('NULL::VARCHAR AS status_1c')
+            ])
+            ->from(OrdersAmo::tableName());
+
+        $queryMarketplace = (new Query())
+            ->select([
+                new \yii\db\Expression("'marketplace' AS source"),
+                'id',
+                new \yii\db\Expression('store_id::VARCHAR AS store_id'),
+                new \yii\db\Expression('status_id::BIGINT AS status_id'),
+                'updated_at',
+                'marketplace_order_id',
+                new \yii\db\Expression('substatus_id::VARCHAR AS substatus_id'),
+                'warehouse_guid',
+                'creation_date',
+                'returned_at',
+                'return_data',
+                new \yii\db\Expression('fake::INTEGER AS fake'),
+                'total',
+                'delivery_total',
+                'buyer_total_before_discount',
+                'tax_system',
+                'payment_type',
+                'payment_method',
+                new \yii\db\Expression("
+                CASE 
+                    WHEN cancel_requested = 1 THEN TRUE
+                    WHEN cancel_requested = 0 THEN FALSE
+                    ELSE NULL 
+                END AS cancel_requested
+            "),
+                'raw_data',
+                'guid',
+                new \yii\db\Expression('status_1c::VARCHAR AS status_1c')
+            ])
+            ->from(MarketplaceOrders::tableName());
+
+        $unionQuery = (new Query())
+            ->from(['orders' => $queryAmo->union($queryMarketplace, true)]); // UNION ALL для скорости
+
+        $orders = $unionQuery->all();
+
+        $dataProvider = new ArrayDataProvider([
+            'allModels' => $orders,
+            'pagination' => [
+                'pageSize' => 20
+            ],
+            'sort' => [
+                'attributes' => ['id', 'store_id', 'status_id', 'updated_at'],
+            ],
+        ]);
+
+        return $this->render('all-orders', [
+            'dataProvider' => $dataProvider,
+        ]);
+    }
 }
diff --git a/erp24/views/marketplace-orders/all-orders.php b/erp24/views/marketplace-orders/all-orders.php
new file mode 100644 (file)
index 0000000..d20c486
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/** @var yii\web\View $this */
+/** @var yii\data\ArrayDataProvider $dataProvider */
+
+use yii\grid\GridView;
+use yii\helpers\Html;
+
+$this->title = 'Все заказы';
+?>
+
+<h1><?= Html::encode($this->title) ?></h1>
+
+<?= GridView::widget([
+    'dataProvider' => $dataProvider,
+    'filterModel' => null, 
+    'columns' => [
+        [
+            'attribute' => 'source',
+            'label' => 'Источник',
+        ],
+        'id',
+        'store_id',
+        'status_id',
+        [
+            'attribute' => 'updated_at',
+            'format' => ['date', 'php:Y-m-d H:i'],
+        ],
+    ],
+]); ?>