diff --git a/frontend/spa/src/components/Dock.vue b/frontend/spa/src/components/Dock.vue index 782091b..6d15f03 100644 --- a/frontend/spa/src/components/Dock.vue +++ b/frontend/spa/src/components/Dock.vue @@ -60,6 +60,22 @@ Корзина + + +
+ avatar +
+
+ + + +
+ Профиль +
@@ -67,10 +83,12 @@ import {useRoute} from "vue-router"; import {useCartStore} from "@/stores/CartStore.js"; import {useSettingsStore} from "@/stores/SettingsStore.js"; +import {useTgData} from "@/composables/useTgData.js"; const route = useRoute(); const cart = useCartStore(); const settings = useSettingsStore(); +const tgData = useTgData(); const haptic = window.Telegram.WebApp.HapticFeedback; function onDockItemClick() { diff --git a/frontend/spa/src/components/Navbar.vue b/frontend/spa/src/components/Navbar.vue index 6d747bd..c84a754 100644 --- a/frontend/spa/src/components/Navbar.vue +++ b/frontend/spa/src/components/Navbar.vue @@ -21,32 +21,16 @@ + + + diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/src/Handlers/TelegramCustomerHandler.php b/module/oc_telegram_shop/upload/oc_telegram_shop/src/Handlers/TelegramCustomerHandler.php index 46cbb01..61de0a7 100755 --- a/module/oc_telegram_shop/upload/oc_telegram_shop/src/Handlers/TelegramCustomerHandler.php +++ b/module/oc_telegram_shop/upload/oc_telegram_shop/src/Handlers/TelegramCustomerHandler.php @@ -49,6 +49,7 @@ class TelegramCustomerHandler return new JsonResponse([ 'data' => [ 'tracking_id' => Arr::get($customer, 'tracking_id'), + 'created_at' => Arr::get($customer, 'created_at'), ], ], Response::HTTP_OK); } catch (Throwable $e) { @@ -58,6 +59,46 @@ class TelegramCustomerHandler } } + /** + * Получить данные текущего пользователя + * + * @param Request $request HTTP запрос + * @return JsonResponse JSON ответ с данными пользователя + */ + public function getCurrent(Request $request): JsonResponse + { + try { + $telegramUserData = $this->extractUserDataFromInitData($request); + $telegramUserId = (int)Arr::get($telegramUserData, 'id'); + + if ($telegramUserId <= 0) { + return new JsonResponse([ + 'data' => null, + ], Response::HTTP_OK); + } + + $customer = $this->telegramCustomerService->getByTelegramUserId($telegramUserId); + + if (!$customer) { + return new JsonResponse([ + 'data' => null, + ], Response::HTTP_OK); + } + + return new JsonResponse([ + 'data' => [ + 'created_at' => Arr::get($customer, 'created_at'), + ], + ], Response::HTTP_OK); + } catch (Throwable $e) { + $this->logger->error('Could not get current telegram customer data', ['exception' => $e]); + + return new JsonResponse([ + 'data' => null, + ], Response::HTTP_OK); + } + } + /** * Извлечь данные Telegram пользователя из запроса * diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/src/Services/TelecartCustomerService.php b/module/oc_telegram_shop/upload/oc_telegram_shop/src/Services/TelecartCustomerService.php index e18dc93..1edcb6c 100755 --- a/module/oc_telegram_shop/upload/oc_telegram_shop/src/Services/TelecartCustomerService.php +++ b/module/oc_telegram_shop/upload/oc_telegram_shop/src/Services/TelecartCustomerService.php @@ -111,4 +111,15 @@ class TelecartCustomerService { $this->telegramCustomer->increase($telecartCustomerId, 'orders_count'); } + + /** + * Получить данные пользователя по Telegram user ID + * + * @param int $telegramUserId Telegram user ID + * @return array|null Данные пользователя или null если не найдено + */ + public function getByTelegramUserId(int $telegramUserId): ?array + { + return $this->telegramCustomer->findByTelegramUserId($telegramUserId); + } } diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/src/routes.php b/module/oc_telegram_shop/upload/oc_telegram_shop/src/routes.php index fb40576..161031d 100755 --- a/module/oc_telegram_shop/upload/oc_telegram_shop/src/routes.php +++ b/module/oc_telegram_shop/upload/oc_telegram_shop/src/routes.php @@ -29,6 +29,7 @@ return [ 'product_show' => [ProductsHandler::class, 'show'], 'products' => [ProductsHandler::class, 'index'], 'saveTelegramCustomer' => [TelegramCustomerHandler::class, 'saveOrUpdate'], + 'getCurrentCustomer' => [TelegramCustomerHandler::class, 'getCurrent'], 'settings' => [SettingsHandler::class, 'index'], 'storeOrder' => [OrderHandler::class, 'store'], 'testTgMessage' => [SettingsHandler::class, 'testTgMessage'],