| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace App\Services;
- use App\Constants\StepStatus;
- use App\Models\User;
- use App\Models\Wallet;
- use Illuminate\Support\Facades\Cache;
- use Telegram\Bot\Api;
- use Telegram\Bot\Exceptions\TelegramSDKException;
- class SecretService
- {
- /**
- * @param Api $telegram
- * @param $data
- * @param $chatId
- * @param $firstName
- * @param $messageId
- * @throws TelegramSDKException
- */
- public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
- {
- if ($data === "secret@@index") {
- $res = SecretService::index($chatId, $messageId);
- $telegram->editMessageText($res);
- }
- //找回账号
- if ($data === "secret@@retrieve") {
- $res = SecretService::retrieve($chatId, $messageId);
- $telegram->editMessageText($res);
- }
- }
- public static function onMessage($chatId, $text, $messageId, $stepStatus): null|array
- {
- return match ($stepStatus) {
- StepStatus::MY_INPUT_OLD_SECRET => SecretService::inputOldSecret($chatId, $text, $messageId),
- default => null
- };
- }
- private static function inputOldSecret($chatId, $secret, $messageId): array
- {
- $user = User::where(['secret_key' => $secret])->where('member_id', '!=', $chatId)->first();
- if (!$user) {
- return [
- 'chat_id' => $chatId,
- 'text' => "输入错误,请重新输入",
- 'reply_to_message_id' => $messageId
- ];
- }
- $wallet = Wallet::where('member_id', $user->getMemberId())->first();
- $keyboard = [
- [
- ['text' => '确认', 'callback_data' => 'secret@@confirm'],
- ]
- ];
- $text = "原账号信息:\n";
- $text .= "用户ID:{$user->getMemberId()}\n";
- $text .= "用户名:{$user->getUsername()}\n}";
- $text .= "昵称:{$user->getFirstName()}\n";
- $text .= "余额:{$wallet->available_balance}\n";
- $text .= "\n-------------------------------\n\n";
- $text .= "注意:请确认原账号信息,点击确认后,原账号将注销,原账号的余额以及其他信息将同步到新账号中!此操作不可撤销";
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
- ];
- }
- private static function retrieve($chatId, $messageId): array
- {
- Cache::put(get_step_key($chatId), StepStatus::MY_INPUT_OLD_SECRET);
- return [
- 'chat_id' => $chatId,
- 'text' => '请输入原账号的秘钥',
- 'message_id' => $messageId,
- ];
- }
- private static function index($chatId, $messageId): array
- {
- $keyboard = [
- [
- ['text' => '查看秘钥', 'callback_data' => 'secret@@view'],
- ['text' => '找回账号', 'callback_data' => 'secret@@retrieve'],
- ],
- [
- ['text' => '返回', 'callback_data' => 'topUp@@home'],
- ]
- ];
- $text = "秘钥管理\n";
- $text .= "请选择业务类型";
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'message_id' => $messageId,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
- ];
- }
- }
|