From 952d8e58da2972ff834d7f6609749b6dbd15a938 Mon Sep 17 00:00:00 2001 From: Nikita Kiselev Date: Mon, 24 Nov 2025 14:08:56 +0300 Subject: [PATCH] feat(customers): track order meta and OC sync - add telecart_order_meta table and orders_count column for customers - introduce OcCustomerService and OrderMetaService for syncing OC data - rework OrderCreateService transaction flow, metadata handling and tests - increment telegram customer orders_count and expose it via handlers/UI - update stats dashboard with rub formatting, tooltips and customers count - sync SPA theme colors with Telegram WebApp and fix dark variant behavior - add helpers for RUB formatting and bool casting; simplify logs handler --- frontend/admin/src/components/TopLead.vue | 28 ++- frontend/admin/src/stores/stats.js | 4 +- frontend/admin/src/utils/helpers.js | 8 + frontend/admin/src/views/CustomersView.vue | 36 ++- frontend/spa/src/main.js | 18 +- frontend/spa/src/style.css | 2 +- .../bastion/Handlers/LogsHandler.php | 44 ++-- .../bastion/Handlers/StatsHandler.php | 25 +- .../Handlers/TelegramCustomersHandler.php | 10 + ...00007_create_telecart_order_meta_table.php | 29 +++ ...ders_count_to_telecart_customers_table.php | 16 ++ .../framework/Support/Utils.php | 5 + .../src/Models/TelegramCustomer.php | 8 + .../src/Services/OcCustomerService.php | 62 +++++ .../src/Services/OrderCreateService.php | 232 +++++++++++------- .../src/Services/OrderMetaService.php | 27 ++ .../src/Services/TelegramCustomerService.php | 52 ++-- .../Unit/Services/OrderCreateServiceTest.php | 55 ++++- 18 files changed, 489 insertions(+), 172 deletions(-) create mode 100644 module/oc_telegram_shop/upload/oc_telegram_shop/database/migrations/20260101000007_create_telecart_order_meta_table.php create mode 100644 module/oc_telegram_shop/upload/oc_telegram_shop/database/migrations/20260101000008_add_orders_count_to_telecart_customers_table.php create mode 100644 module/oc_telegram_shop/upload/oc_telegram_shop/src/Services/OcCustomerService.php create mode 100644 module/oc_telegram_shop/upload/oc_telegram_shop/src/Services/OrderMetaService.php diff --git a/frontend/admin/src/components/TopLead.vue b/frontend/admin/src/components/TopLead.vue index 62ba02e..3838dc3 100644 --- a/frontend/admin/src/components/TopLead.vue +++ b/frontend/admin/src/components/TopLead.vue @@ -17,28 +17,41 @@
- Количество заказов + + Количество заказов +
+ class="tw:text-surface-700 tw:dark:text-surface-100 tw:mt-1 tw:text-sm tw:font-semibold" + > {{ stats.items.orders_count ?? '-' }}
- Общая сумма + Общая сумма
- {{ stats.items.orders_total_amount ?? '-' }} + {{ rub(stats.items.orders_total_amount ?? 0) }}
- Уникальные товары + Кол-во посетителей
- {{ stats.items.order_products_count ?? '-' }} + {{ stats.items.customers_count ?? 0 }}
- Статус магазина + Статус магазина
@@ -102,6 +115,7 @@ import OcImagePicker from "@/components/OcImagePicker.vue"; import {apiGet} from "@/utils/http.js"; import ResetCacheBtn from "@/components/Form/ResetCacheBtn.vue"; import {Button, ButtonGroup} from "primevue"; +import {rub} from "@/utils/helpers.js"; const settings = useSettingsStore(); const stats = useStatsStore(); diff --git a/frontend/admin/src/stores/stats.js b/frontend/admin/src/stores/stats.js index 2afac9a..16f361b 100644 --- a/frontend/admin/src/stores/stats.js +++ b/frontend/admin/src/stores/stats.js @@ -6,7 +6,7 @@ export const useStatsStore = defineStore('stats', { items: { orders_count: null, orders_total_amount: null, - order_products_count: null, + customers_count: null, } }), @@ -15,7 +15,7 @@ export const useStatsStore = defineStore('stats', { const response = await apiPost('getDashboardStats'); this.items.orders_count = response.data?.data?.orders_count; this.items.orders_total_amount = response.data?.data?.orders_total_amount; - this.items.order_products_count = response.data?.data?.order_products_count; + this.items.customers_count = response.data?.data?.customers_count; } }, diff --git a/frontend/admin/src/utils/helpers.js b/frontend/admin/src/utils/helpers.js index 338adc0..1aea486 100644 --- a/frontend/admin/src/utils/helpers.js +++ b/frontend/admin/src/utils/helpers.js @@ -5,3 +5,11 @@ export function getThumb(imageUrl) { const filename = imageUrl.substring(0, extIndex); return `/image/cache/${filename}-100x100${ext}`; } + +export function rub(value) { + return new Intl.NumberFormat('ru-RU', { + style: 'currency', + currency: 'RUB', + maximumFractionDigits: 0 + }).format(value); +} diff --git a/frontend/admin/src/views/CustomersView.vue b/frontend/admin/src/views/CustomersView.vue index 14a992d..13215ea 100644 --- a/frontend/admin/src/views/CustomersView.vue +++ b/frontend/admin/src/views/CustomersView.vue @@ -140,6 +140,9 @@ + -