From: marina Date: Wed, 5 Mar 2025 10:43:48 +0000 (+0300) Subject: ERP-329 Новый интерфейс для работы с заказами мп и амо X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ed5e9ca8e71d9a464fd5e95143fe9ca906298d4d;p=erp24_rep%2Fyii-erp24%2F.git ERP-329 Новый интерфейс для работы с заказами мп и амо --- diff --git a/erp24/lib/yandex_market_api/Model/OrderPaymentMethodType.php b/erp24/lib/yandex_market_api/Model/OrderPaymentMethodType.php index 742078ad..2c10dad5 100644 --- a/erp24/lib/yandex_market_api/Model/OrderPaymentMethodType.php +++ b/erp24/lib/yandex_market_api/Model/OrderPaymentMethodType.php @@ -27,6 +27,7 @@ */ namespace OpenAPI\Client\Model; + use \OpenAPI\Client\ObjectSerializer; /** @@ -94,6 +95,23 @@ class OrderPaymentMethodType self::UNKNOWN ]; } + + public const PAYMENT_LABELS = [ + self::CASH_ON_DELIVERY => 'Наличными при получении', + self::CARD_ON_DELIVERY => 'Картой при получении', + self::BOUND_CARD_ON_DELIVERY => 'Привязанной картой при получении', + self::YANDEX => 'Банковской картой', + self::APPLE_PAY => 'Apple Pay', + self::EXTERNAL_CERTIFICATE => 'Подарочным сертификатом', + self::CREDIT => 'Кредит', + self::GOOGLE_PAY => 'Google Pay', + self::TINKOFF_CREDIT => 'Кредит в Тинькофф Банке', + self::SBP => 'СБП (Cистема быстрых платежей)', + self::TINKOFF_INSTALLMENTS => 'Рассрочка в Тинькофф Банке', + self::B2_B_ACCOUNT_PREPAYMENT => 'Заказ оплачивает организация при получении', + self::B2_B_ACCOUNT_POSTPAYMENT => 'Заказ оплачивает организация после доставки', + self::UNKNOWN => 'Неизвестный тип оплаты', + ]; } diff --git a/erp24/records/OrdersAmo.php b/erp24/records/OrdersAmo.php index dbda3769..c39f32a7 100644 --- a/erp24/records/OrdersAmo.php +++ b/erp24/records/OrdersAmo.php @@ -143,6 +143,12 @@ use Yii; */ class OrdersAmo extends \yii\db\ActiveRecord { + + public const STATUS_NAMES = [ + 142 => 'Успешно', + 143 => 'Отказ', + ]; + /** * {@inheritdoc} */ diff --git a/erp24/records/OrdersUnion.php b/erp24/records/OrdersUnion.php index f59b2e38..d7b777fd 100644 --- a/erp24/records/OrdersUnion.php +++ b/erp24/records/OrdersUnion.php @@ -17,7 +17,13 @@ class OrdersUnion extends ActiveRecord return ['id']; } - public static function getOrders($params = []) + public const SOURCES = [ + 'amo' => 'AMO', + 'yandex' => 'ЯндексМаркет', + 'flowwow' => 'Flowwow', + ]; + + public static function getOrders($params = null) { $queryAmo = (new Query()) ->select([ @@ -51,15 +57,21 @@ class OrdersUnion extends ActiveRecord ]) ->from('orders_amo o'); + $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', - 'mo.payment_method AS payment_type_id', - 'mo.total AS price', + new \yii\db\Expression(" + CASE + WHEN ms.warehouse_id = 2 THEN 'yandex' + WHEN ms.warehouse_id = 1 THEN 'flowwow' + ELSE 'Marketplace' + END AS source"), + 'mo.id', + 'mod.delivery_end AS delivery_date', + 'mo.status_id', + 'mo.store_id', + 'payment_method', + 'mo.total', new \yii\db\Expression("NULLIF(concat(country, ' ', city, ' ', street, ' ', house, ' ', apartment), '')::TEXT AS delivery_address"), new \yii\db\Expression("( SELECT jsonb_agg(jsonb_build_object( @@ -92,23 +104,15 @@ class OrdersUnion extends ActiveRecord ) AS products_json") ]) ->from(['mo' => 'marketplace_orders']) - ->leftJoin(['mod' => 'marketplace_order_delivery'], 'mo.id = mod.order_id'); + ->leftJoin(['mod' => 'marketplace_order_delivery'], 'mo.id = mod.order_id') + ->leftJoin(['ms' => 'marketplace_store'], 'ms.warehouse_guid::TEXT = mo.warehouse_guid::TEXT'); $query = (new Query()) - ->from(['orders' => $queryAmo->union($queryMarketplace, true)]); - - // Фильтрация данных - if (!empty($params['source'])) { - $query->andWhere(['orders.source' => $params['source']]); - } - - if (!empty($params['delivery_date'])) { - $query->andWhere(['orders.delivery_date' => $params['delivery_date']]); - } - - if (!empty($params['store_id'])) { - $query->andWhere(['orders.store_id' => (int) $params['store_id']]); - } + ->andFilterWhere(['source' => $params['source']]) + ->andFilterWhere(['store_id' => $params['store_id']]) + ->andFilterWhere(['delivery_date' => $params['delivery_date']]) + ->from(['orders' => $queryAmo->union($queryMarketplace, true)]) + ->orderBy('id desc'); return new \yii\data\ArrayDataProvider([ 'allModels' => $query->all(), diff --git a/erp24/views/marketplace-orders/all-orders.php b/erp24/views/marketplace-orders/all-orders.php index 8308ea59..f92bcbcd 100644 --- a/erp24/views/marketplace-orders/all-orders.php +++ b/erp24/views/marketplace-orders/all-orders.php @@ -1,112 +1,145 @@ title = 'Все заказы'; ?> +
+

title) ?>

-

title) ?>

+
+ 'get', + 'action' => ['all-orders'], -
- 'get', - 'action' => ['all-orders'], - - ]); ?> - -
- 'source', - 'value' => Yii::$app->request->get('source'), - 'data' => ['amo' => 'Amo', 'marketplace' => 'Marketplace'], - 'options' => ['placeholder' => 'Выберите источник'], - 'pluginOptions' => ['allowClear' => true], ]); ?> - 'delivery_date', - 'value' => Yii::$app->request->get('delivery_date'), - 'options' => ['placeholder' => 'Выберите дату'], - 'pluginOptions' => [ - 'format' => 'yyyy-mm-dd', - 'autoclose' => true, - ], - ]); ?> +
+
+ 'source', + 'value' => Yii::$app->request->get('source'), + 'data' => OrdersUnion::SOURCES, + 'options' => ['placeholder' => 'Выберите источник'], + 'pluginOptions' => ['allowClear' => true], + ]); ?> +
+
- 'store_id', - 'value' => Yii::$app->request->get('store_id'), - 'data' => [1 => 'Магазин 1', 2 => 'Магазин 2', 3 => 'Магазин 3'], // Должны быть реальные магазины - 'options' => ['placeholder' => 'Выберите магазин'], - 'pluginOptions' => ['allowClear' => true], - ]); ?> - -
- 'btn btn-primary']) ?> - 'btn btn-default']) ?> + 'delivery_date', + 'value' => Yii::$app->request->get('delivery_date'), + 'options' => ['placeholder' => 'Выберите дату'], + 'pluginOptions' => [ + 'format' => 'yyyy-mm-dd', + 'autoclose' => true, + ], + ]); ?> +
+
+ 'store_id', + 'value' => Yii::$app->request->get('store_id'), + 'data' => \yii\helpers\ArrayHelper::map(CityStore::find()->all(), 'id', 'name'), + 'options' => ['placeholder' => 'Выберите магазин'], + 'pluginOptions' => ['allowClear' => true], + ]); ?> +
+
+
+ 'btn btn-primary']) ?> +
+
+ +
- -
+ $dataProvider, + 'columns' => [ + 'id', + [ + 'attribute' => 'source', + 'label' => 'Источник', + 'value' => function ($model) { + return $model['source'] ? OrdersUnion::SOURCES[$model['source']] : 'Неизвестный маркетплейс'; + } + ], + [ + 'attribute' => 'delivery_date', + 'label' => 'Дата доставки', + ], + [ + 'attribute' => 'store_id', + 'label' => 'Магазин сборщик', + 'value' => function ($model) { + return $model['store_id'] ? CityStore::findOne($model['store_id'])->name : 'ул. Аэродромная 28 (к-р Москва)'; + } + ], - $dataProvider, - 'columns' => [ - 'id', - [ - 'attribute' => 'source', - 'label' => 'Источник', - ], - [ - 'attribute' => 'delivery_date', - 'label' => 'Дата доставки', - ], - [ - 'attribute' => 'store_id', - 'label' => 'Магазин сборщик', - ], - [ - 'attribute' => 'status_id', - 'label' => 'Статус', - ], - [ - 'attribute' => 'payment_type_id', - 'label' => 'Способ оплаты', - ], - [ - 'attribute' => 'price', - 'label' => 'Цена', - ], - [ - 'attribute' => 'delivery_address', - 'label' => 'Адрес доставки', - ], - [ - 'attribute' => 'products_json', - 'label' => 'Состав', - 'format' => 'raw', - 'value' => function ($model) { - $products = json_decode($model['products_json'], true); - if (empty($products)) { - return '(Нет данных)'; + [ + 'attribute' => 'status_id', + 'label' => 'Статус', + 'value' => function ($model) { + if ($model['source'] == 'amo') { + return OrdersAmo::STATUS_NAMES[intval($model['status_id'])] ?? 'Неизвестный статус'; + } else { + return MarketplaceStatus::findOne($model['status_id'])->name ?? 'Неизвестный статус'; + } } + ], - $output = ''; - foreach ($products as $product) { - $output .= "

{$product['name']}

"; - $output .= ''; - foreach ($product['items'] as $item) { - $output .= ""; + [ + 'attribute' => 'payment_type_id', + 'label' => 'Способ оплаты', + 'value' => function ($model) { + if ($model['source'] != 'amo') { + return OrderPaymentMethodType::PAYMENT_LABELS[$model['payment_type_id']]; } - $output .= '
НазваниеКол-воЦена
{$item['name']}{$item['quantity']}{$item['price']} ₽
'; + return 'payment_type_id'; } - return $output; - } + ], + [ + 'attribute' => 'price', + 'label' => 'Цена', + ], + [ + 'attribute' => 'delivery_address', + 'label' => 'Адрес доставки', + ], + [ + 'attribute' => 'products_json', + 'label' => 'Состав', + 'format' => 'raw', + 'value' => function ($model) { + $products = json_decode($model['products_json'], true); + + if (empty($products)) { + return '(Нет данных)'; + } + + $output = ''; + foreach ($products as $product) { + $output .= "

{$product['name']}

"; + $output .= ''; + foreach ($product['items'] as $item) { + $output .= ""; + } + $output .= '
НазваниеКол-воЦена
{$item['name']}{$item['quantity']}{$item['price']} ₽
'; + } + return $output; + } + ], ], - ], -]); ?> + ]); ?> +