From: marina Date: Tue, 4 Mar 2025 06:38:03 +0000 (+0300) Subject: ERP-329 Новый интерфейс для работы с заказами мп и амо X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=87b75fac0d3cd42b6183ab6a0a2b643b2d777151;p=erp24_rep%2Fyii-erp24%2F.git ERP-329 Новый интерфейс для работы с заказами мп и амо --- diff --git a/erp24/controllers/MarketplaceOrdersController.php b/erp24/controllers/MarketplaceOrdersController.php index add0fd36..abc78491 100644 --- a/erp24/controllers/MarketplaceOrdersController.php +++ b/erp24/controllers/MarketplaceOrdersController.php @@ -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, ], ]); diff --git a/erp24/records/MarketplaceOrderStatusTypes.php b/erp24/records/MarketplaceOrderStatusTypes.php index ceb8bb22..95064542 100644 --- a/erp24/records/MarketplaceOrderStatusTypes.php +++ b/erp24/records/MarketplaceOrderStatusTypes.php @@ -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 index 00000000..7bea5836 --- /dev/null +++ b/erp24/records/OrdersUnion.php @@ -0,0 +1,57 @@ +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']); + } +} diff --git a/erp24/views/marketplace-orders/all-orders.php b/erp24/views/marketplace-orders/all-orders.php index d20c486f..937fb161 100644 --- a/erp24/views/marketplace-orders/all-orders.php +++ b/erp24/views/marketplace-orders/all-orders.php @@ -12,18 +12,36 @@ $this->title = 'Все заказы'; $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' => 'Адрес доставки', ], ], ]); ?>