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

index add0fd36289d6e64e1a7d4dd27fc21550ce2067e..abc784912a8167239d69d741168cfc09ed10995b 100644 (file)
@@ -2,17 +2,15 @@
 
 namespace app\controllers;
 
+use app\records\OrdersUnion;
 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;
 
 /**
@@ -239,78 +237,12 @@ class MarketplaceOrdersController extends Controller
 
     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();
+        $data = OrdersUnion::getOrders();
 
         $dataProvider = new ArrayDataProvider([
-            'allModels' => $orders,
+            'allModels' => $data,
             'pagination' => [
-                'pageSize' => 20
-            ],
-            'sort' => [
-                'attributes' => ['id', 'store_id', 'status_id', 'updated_at'],
+                'pageSize' => 20,
             ],
         ]);
 
index ceb8bb2222d18ba44b88d30680d9cba1d1e0e616..95064542247b13c1376e2aeb5cabb3cde6a19d48 100644 (file)
@@ -50,5 +50,4 @@ class MarketplaceOrderStatusTypes extends \yii\db\ActiveRecord
             'description' => 'Описание статуса',
         ];
     }
-
 }
diff --git a/erp24/records/OrdersUnion.php b/erp24/records/OrdersUnion.php
new file mode 100644 (file)
index 0000000..7bea583
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+namespace app\records;
+
+use yii\db\ActiveRecord;
+use yii\db\Query;
+class OrdersUnion extends ActiveRecord
+{
+    public $delivery_date;
+    public $delivery_address;
+    public const AMO = 'amo';
+    public const MARKETPLACE = 'marketplace';
+
+    public static function primaryKey()
+    {
+        return ['id'];
+    }
+
+    public static function getOrders()
+    {
+        $queryAmo = (new Query())
+            ->select([
+                new \yii\db\Expression("'amo' AS source"),
+                'id',
+                'delivery_date',
+                'status_id',
+                new \yii\db\Expression('NULLIF(store_id, \'\')::INTEGER AS store_id'),
+                'payment_type_id',
+                'price',
+                'delivery_adress as delivery_address'
+            ])
+            ->from('orders_amo');
+
+        $queryMarketplace = (new Query())
+            ->select([
+                new \yii\db\Expression("'marketplace' AS source"),
+                'mo.id',
+                'mod.delivery_end AS delivery_date',
+                'mo.status_id',
+                'mo.store_id',
+                'payment_method',
+                'total',
+                new \yii\db\Expression("NULLIF(concat(country, ' ', city, ' ', street, ' ', house, ' ', apartment), '')::TEXT AS delivery_address"),
+            ])
+            ->from(['mo' => 'marketplace_orders'])
+            ->leftJoin(['mod' => 'marketplace_order_delivery'], 'mo.id = mod.order_id');
+
+        return (new Query())
+            ->from(['orders' => $queryAmo->union($queryMarketplace, true)])
+            ->all();
+    }
+    
+    public function attributes()
+    {
+        return array_merge(parent::attributes(), ['delivery_date']);
+    }
+}
index d20c486f787362d7ff7af14e453092890bb66733..937fb1612186d4bbf59085a03fc2564c840d9469 100644 (file)
@@ -12,18 +12,36 @@ $this->title = 'Все заказы';
 
 <?= GridView::widget([
     'dataProvider' => $dataProvider,
-    'filterModel' => null, 
+    'filterModel' => null,
     'columns' => [
+        'id',
         [
             'attribute' => 'source',
             'label' => 'Источник',
         ],
-        'id',
-        'store_id',
-        'status_id',
         [
-            'attribute' => 'updated_at',
-            'format' => ['date', 'php:Y-m-d H:i'],
+            'attribute' => 'delivery_date',
+            'label' => 'Дата доставки',
+        ],
+        [
+            'attribute' => 'store_id',
+            'label' => 'Магазин сборщик',
+        ],
+        [
+            'attribute' => 'status_id',
+            'label' => 'Статус',
+        ],
+        [
+            'attribute' => 'payment_type_id',
+            'label' => 'Способ оплаты',
+        ],
+        [
+            'attribute' => 'price',
+            'label' => 'Цена',
+        ],
+        [
+            'attribute' => 'delivery_address',
+            'label' => 'Адрес доставки',
         ],
     ],
 ]); ?>