<?php

namespace App\Services;

use App\Constants\HttpStatus;
use App\Constants\StepStatus;
use App\Models\ActivityUser;
use App\Models\Bank;
use App\Models\Config;
use App\Models\PaymentOrder;
use App\Models\Wallet;
use App\Services\Payment\JdPayService;
use App\Services\Payment\NoPayService;
use App\Services\Payment\QianBaoService;
use App\Services\Payment\ZimuPayService;
use Exception;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Telegram\Bot\Api;
use Telegram\Bot\Exceptions\TelegramSDKException;

class QianBaoWithdrawService
{
    /**
     * @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 === "withdraw@@qb_show_channel") {
            $res = QianBaoWithdrawService::chooseType($chatId, $messageId);
            $telegram->editMessageText($res);
        }

        $pattern = "/^withdraw@@qb_choose_.*$/";
        if (preg_match($pattern, $data)) {
            $type = preg_replace('/^withdraw@@qb_choose_/', '', $data);
            $res = QianBaoWithdrawService::showBanks($chatId, $messageId, $type);
            $telegram->editMessageText($res);
        }

        //选择银行卡号
        $pattern = "/^withdrawAddress@@choose_qb_\d+$/";
        if (preg_match($pattern, $data)) {
            $id = preg_replace('/^withdrawAddress@@choose_qb_/', '', $data);
            $res = QianBaoWithdrawService::chooseBank($chatId, $id);
            $telegram->deleteMessage([
                'chat_id' => $chatId,
                'message_id' => $messageId,
            ]);
            $telegram->sendMessage($res);
        }


        //确认提现信息
        if ($data === "withdraw@@qb_confirm") {
            $res = QianBaoWithdrawService::confirm($chatId, $messageId);
            $telegram->editMessageText($res);

        }


        if ($data === "withdraw@@qb_apply") {
            $res = QianBaoWithdrawService::qbApply($chatId, $messageId);
            $telegram->editMessageText($res);
        }


        //钱宝账单
        $pattern = "/^withdraw@@bank_bill_\d+$/";
        if (preg_match($pattern, $data)) {
            $page = preg_replace('/^withdraw@@bank_bill_/', '', $data);
            if (empty($page) || $page < 1) $page = 1;
            $page = intval($page);
            $res = QianBaoWithdrawService::bill($chatId, $firstName, $messageId, $page);
            $telegram->editMessageText($res);
        }


        //银行卡管理
        $pattern = "/^withdraw@@management_.*$/";
        if (preg_match($pattern, $data)) {
            $channel = preg_replace('/^withdraw@@management_/', '', $data);
            $res = QianBaoWithdrawService::banks($chatId, $messageId, $channel);
            $telegram->editMessageText($res);
        }

        //添加银行卡
//        $pattern = "/^withdraw@@bank_add.*$/";
//        if (preg_match($pattern, $data)) {
//            $channel = preg_replace('/^withdraw@@bank_add/', '', $data);
//            $res = QianBaoWithdrawService::chooseChannel($chatId, $messageId,$channel);
//            $telegram->editMessageText($res);
//        }


        //银行卡详情
        $pattern = "/^withdrawAddress@@bank_detail\d+$/";
        if (preg_match($pattern, $data)) {
            $id = preg_replace('/^withdrawAddress@@bank_detail/', '', $data);
            $res = static::bankDetails($chatId, $messageId, $id);
            $telegram->editMessageText($res);
        }

        $pattern = "/^withdraw@@bank_del_\d+$/";
        if (preg_match($pattern, $data)) {
            $id = preg_replace('/^withdraw@@bank_del_/', '', $data);
            $res = static::bankDelete($chatId, $messageId, $id);
            $telegram->editMessageText($res);
        }


        $pattern = "/^withdrawAddress@@bank_choose_channel_.*$/";
        if (preg_match($pattern, $data)) {
            $channel = preg_replace('/^withdrawAddress@@bank_choose_channel_/', '', $data);
            $res = static::chooseChannel($chatId, $messageId, $channel);
            $telegram->editMessageText($res);
        }


    }

    public static function onMessage($chatId, $text, $messageId, $stepStatus): null|array
    {
        return match ($stepStatus) {
            StepStatus::QB_INPUT_ALIAS => QianBaoWithdrawService::inputAliAs($chatId, $text, $messageId),
            StepStatus::INPUT_WITHDRAW_QB_MONEY => QianBaoWithdrawService::inputQbAmount($chatId, $text, $messageId),
            StepStatus::QB_INPUT_BANK_NAME => QianBaoWithdrawService::inputBankName($chatId, $text, $messageId),
            StepStatus::QB_INPUT_CARD_NO => QianBaoWithdrawService::inputCardNo($chatId, $text, $messageId),
            StepStatus::QB_INPUT_ACCOUNT => QianBaoWithdrawService::inputAccount($chatId, $text, $messageId),
            default => null,
        };
    }


    private static function chooseType($chatId, $messageId)
    {
        $serviceAccount = Config::where('field', 'service_customer')->first()->val;
        //是否封号
        $isBanned = UserService::getIsBanned($chatId);
        if ($isBanned) {
            $text = lang("账号异常") . "\n";
            $text .= lang("任何疑问都可以联系唯一客服") . "：@{$serviceAccount}";
            return [
                'chat_id' => $chatId,
                'text' => $text,
                'message_id' => $messageId,
            ];
        }

        $activityUser = ActivityUserService::findOne(['member_id' => $chatId, 'status' => ActivityUser::STATUS_IN_PROGRESS]);
        if ($activityUser) {
            $text = lang("您有未完成的活动") . "\n";
            $text .= lang("任何疑问都可以联系唯一客服") . "：@{$serviceAccount}";
            return [
                'chat_id' => $chatId,
                'text' => $text,
                'message_id' => $messageId,
            ];
        }


        $keyboard = [
            [
                ['text' => lang("USDT"), 'callback_data' => "withdraw@@apply"],
            ],
            [
                ['text' => lang("银行卡"), 'callback_data' => "withdraw@@qb_choose_bank"],
            ],
            [
                ['text' => lang("支付宝"), 'callback_data' => "withdraw@@qb_choose_aliPay"],
            ],
            [
                ['text' => lang("数字人民币"), 'callback_data' => "withdraw@@qb_choose_digital_RMB"],
            ],
            [
                ['text' => lang("返回"), 'callback_data' => "topUp@@home"],
            ],
        ];
//        $keyboard[] = [
//            ['text' => "提现账户管理", 'callback_data' => "withdraw@@banks"],
//        ];
        return [
            'chat_id' => $chatId,
            'text' => lang("请选择提现方式"),
            'message_id' => $messageId,
            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
        ];
    }

    private static function showBanks($chatId, $messageId, $type)
    {
        $channel = '';
        $card = "";
        $text = "";
        switch ($type) {
            case "bank":
                $card = lang("银行卡");
                $text = lang("请选择提现的银行卡");
                $channel = 'DF001';
                break;
            case "aliPay":
                $card = lang("支付宝");
                $text = lang("请选择提现的支付宝");
                $channel = "DF002";
                break;
            case "digital_RMB":
                $card = lang("数字人民币");
                $text = lang("请选择提现的账户");
                $channel = "DF005";
                break;
        }
        $list = Bank::where('member_id', $chatId)->where('channel', $channel)->get();
        $keyboard = [];
        foreach ($list as $item) {
            $keyboard[] = [['text' => $item->getAlias(), 'callback_data' => "withdrawAddress@@choose_qb_{$item->getId()}"]];
        }
        $keyboard[] = [
            ['text' => "{$card}" . lang("管理"), 'callback_data' => "withdraw@@management_{$channel}"],
            ['text' => lang("返回"), 'callback_data' => "withdraw@@qb_show_channel"]];
        return [
            'chat_id' => $chatId,
            'text' => $text,
            'message_id' => $messageId,
            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
        ];


    }

    //钱宝账单
    private static function bill($chatId, $firstName, $messageId, $page = 1, $limit = 5)
    {
        $list = PaymentOrder::where('member_id', $chatId)
            ->where('type', 2)
            ->orderByDesc('created_at')
            ->forPage($page, $limit)
            ->get();

        $count = PaymentOrder::where('member_id', $chatId)
            ->where('type', 2)
            ->count();


        $text = "👤 {$firstName}({$chatId})    " . lang('钱宝提现记录') . "\n\n";
        foreach ($list as $item) {
            $amount = floatval($item->amount);

            $amount = $item->type == 2 ? "➖ {$amount}" : "➕ $amount";
            $text .= "-------------------------------------\n";
            $text .= "{$amount} \n";
            $text .= lang("订单号") . "：{$item->order_no}\n";

            $text .= lang('银行') . "：{$item->bank_name}\n";
            $text .= lang("姓名") . "：{$item->account}\n";
            $text .= lang("卡号") . "：{$item->card_no}\n";
            $status = [lang('待处理'), lang('处理中'), lang('成功'), lang('失败')];
            $text .= lang("状态") . "：{$status[$item->status]}\n";
            if ($item->remark) {
                $text .= lang("说明") . "：{$item->remark}\n";
            }
            $text .= lang('日期') . "：{$item->created_at}\n";
        }

        if ($page > 1) {
            $keyboard[] = [
                ['text' => lang("👆上一页"), 'callback_data' => "withdraw@@bank_bill_" . ($page - 1)]
            ];
        }
        $allPage = ceil($count / $limit);
        if ($allPage > $page) {
            if ($page > 1) {
                $keyboard[count($keyboard) - 1][] = ['text' => lang("👇下一页"), 'callback_data' => "withdraw@@bank_bill_" . ($page + 1)];
            } else {
                $keyboard[] = [
                    ['text' => lang("👇下一页"), 'callback_data' => "withdraw@@bank_bill_" . ($page + 1)]
                ];
            }
        }
        $keyboard[] = [
            ['text' => lang("返回"), 'callback_data' => "topUp@@home"]
        ];
        return [
            'chat_id' => $chatId,
            'text' => $text,
            'message_id' => $messageId,
            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
        ];
    }

    //1.钱宝提现
    private static function qbApply($chatId, $messageId)
    {
        $three_payment_switch = Config::where('field', 'three_payment_switch')->first()->val;
        if ($three_payment_switch != 1) {
            $res = WalletService::getBalance($chatId);
            $res['message_id'] = $messageId;
            return $res;
        }

        $wallet = Wallet::where('member_id', $chatId)->first();
        $temp = floatval($wallet->available_balance);
        $text = lang("请发送提现金额") . "\n";
        $text .= "💰 " . lang("当前余额") . "{$temp} USDT\n";


//        Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
        return [
            'chat_id' => $chatId,
            'text' => $text,
            'message_id' => $messageId,
        ];
    }

    //2.选择银行卡号
    private static function chooseBank($chatId, $id)
    {
        Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
        Cache::put("{$chatId}_QB_BANK_ID", $id);
        return [
            'chat_id' => $chatId,
            'text' => lang("请输入提现的金额"),
        ];
    }

    //3.输入钱宝提现金额
    private static function inputQbAmount($chatId, $amount, $messageId)
    {
        if (!preg_match('/^\d+(\.\d{1,2})?$/', $amount)) {
            return [
                'chat_id' => $chatId,
                'text' => lang('金额输入不正确，请发送提现数字'),
                'reply_to_message_id' => $messageId
            ];
        }
        $amount = floatval($amount);
        $wallet = Wallet::where('member_id', $chatId)->first();
        $temp = floatval($wallet->available_balance);

        if ($amount > $temp) {
            return [
                'chat_id' => $chatId,
                'text' => lang("可用余额不足，请重试"),
                'reply_to_message_id' => $messageId
            ];
        }


        if ($amount < 100) {
            return [
                'chat_id' => $chatId,
                'text' => lang("提现不能少于100 RMB，请重试"),
                'reply_to_message_id' => $messageId
            ];
        }
        if ($amount > 49999) {
            return [
                'chat_id' => $chatId,
                'text' => lang("最多提现 49999 RMB，请重试"),
                'reply_to_message_id' => $messageId
            ];
        }


        $bankId = Cache::get("{$chatId}_QB_BANK_ID");
        $bank = Bank::where('id', $bankId)->first();
        $text = "";
        switch ($bank->getChannel()) {
            case "DF001":
                $text = lang('银行卡提现确认') . "\n";
                $text .= lang('开户行') . "：{$bank->getBankName()}\n";
                $text .= lang('姓名') . "：{$bank->getAccount()}\n";
                $text .= lang('提现账号') . "：{$bank->getCardNo()}\n";
                $text .= lang('提现金额') . "：{$amount}\n";
                break;
            case "DF002":
                $text = lang("支付宝提现确认") . "\n";
                $text .= lang('姓名') . "：{$bank->getAccount()}\n";
                $text .= lang('提现账号') . "：{$bank->getCardNo()}\n";
                $text .= lang('提现金额') . "：{$amount}\n";
                break;
            case "DF005":
                $text = lang('数字人民币提现确认') . "\n";
                $text .= lang('姓名') . "：{$bank->getAccount()}\n";
                $text .= lang('提现账号') . "：{$bank->getCardNo()}\n";
                $text .= lang('提现金额') . "：{$amount}\n";
                break;
        }
        $keyboard = [
            [
                ['text' => lang("确认"), 'callback_data' => 'withdraw@@qb_confirm']
            ],
            [
                ['text' => '❌取消', 'callback_data' => "message@@close"]
            ]];
        Cache::put("{$chatId}_WITHDRAW_QB_MONEY", $amount);
        return [
            'chat_id' => $chatId,
            'text' => $text,
//            'reply_to_message_id' => $messageId,
            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
        ];
    }

    private static function confirm($chatId, $messageId)
    {
        $serviceAccount = Config::where('field', 'service_customer')->first()->val;
        $activityUser = ActivityUserService::findOne(['member_id' => $chatId, 'status' => ActivityUser::STATUS_IN_PROGRESS]);
        if ($activityUser) {
            $text = lang("您有未完成的活动") . "\n";
            $text .= lang("任何疑问都可以联系唯一客服") . "：@{$serviceAccount}";
            return [
                'chat_id' => $chatId,
                'text' => $text,
                'message_id' => $messageId,
            ];
        }

        $id = Cache::get("{$chatId}_QB_BANK_ID");
        $bank = Bank::where('id', $id)->first();
        $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY");

        //提现是否自动转到三方到账，否的话，需要后台审核，审核通过后才会进行第三方转账
        //目前客户要求手动到账，后续也可以做到config 表，从后台进行控制
        $isAutoDeposit = false;
        if ($isAutoDeposit) {
            $res = PaymentOrderService::autoCreatePayout($chatId, $amount, $bank->getChannel(), $bank->getBankName(), $bank->getAccount(), $bank->getCardNo());
        } else {
            $res = static::createOrder($chatId, $amount, $bank->getChannel(), $bank->getBankName(), $bank->getAccount(), $bank->getCardNo());

        }


        $res['message_id'] = $messageId;
        return $res;
    }

    //创建提现订单
    public static function createOrder($memberId, $amount, $channel, $bank_name, $account, $card_no)
    {
        DB::beginTransaction();
        $result['chat_id'] = $memberId;
        $result['code'] = 0;
        $default_amount = $amount;
        try {
            $wallet = WalletService::findOne(['member_id' => $memberId]);
            if (!$wallet) throw new Exception('钱包不存在', HttpStatus::CUSTOM_ERROR);
            $balance = $wallet->available_balance;
            if (bccomp($balance, $amount, 2) < 0) {
                throw new Exception("您的钱包余额不足！", HttpStatus::CUSTOM_ERROR);
            }
            $available_balance = bcsub($balance, $amount, 10);

            // 先预扣款（锁定资金）
            $wallet->available_balance = $available_balance;
            if (!$wallet->save()) throw new Exception('钱包更新失败！', HttpStatus::CUSTOM_ERROR);


            $data = [];
            $data['type'] = PaymentOrderService::TYPE_PAYOUT;
            $data['order_no'] = PaymentOrderService::createOrderNo('sj' . $data['type'] . '_', $memberId);
            $data['member_id'] = $memberId;
            $data['fee'] = $amount * 0.002 + 2;
            $data['amount'] = number_format($amount, 2, '.', '');
            $data['channel'] = $channel;
            $data['bank_name'] = $bank_name;
            $data['account'] = $account;
            $data['card_no'] = $card_no;
            if (NoPayService::isWithdrawChannel($channel)) {
                $data['callback_url'] = NoPayService::getWithdrawNotifyUrl();
            } elseif (JdPayService::isChannel($channel)) {
                $data['callback_url'] = JdPayService::getRemitNotifyUrl();
            } elseif (ZimuPayService::isPayoutChannel($channel)) {
                $data['callback_url'] = ZimuPayService::getPayoutNotifyUrl();
            } else {
                $data['callback_url'] = QianBaoService::getNotifyUrl();
            }
            $data['status'] = PaymentOrderService::STATUS_STAY;
            $data['remark'] = '提现费率：0.2%+2';
            // 创建待处理状态的提现记录
            $info = PaymentOrder::create($data);
            // 记录余额变动日志
            BalanceLogService::addLog($memberId, $default_amount * -1, $balance, $available_balance, '三方提现', $info->id, '钱宝提现费率：0.2%+2');


            $balance = bcadd($available_balance, 0, 2);
            $text = "✅ 提现申请已提交！\n\n";
            $text .= "钱包余额：{$balance} RMB\n";
            $text .= "提现金额：{$default_amount} RMB\n";
            $text .= "⌛️请等待系统处理, 到账时间可能需要几分钟!\n";
            $result['text'] = $text;
            DB::commit();
        } //
        catch (Exception $e) {
            DB::rollBack();
            LogService::error($e);
            $result['text'] = "系统发生了错误，请联系管理员";
            $result['code'] = -1;
            if ($e->getCode() === HttpStatus::CUSTOM_ERROR) {
                $result['text'] = $e->getMessage();
            }
        }
        return $result;
    }

    //银行卡管理
    private static function banks($chatId, $messageId, $channel = ""): array
    {
        $text = '';
        switch ($channel) {
            case "DF001":
                $text = lang("银行卡列表") . "\n";
                break;
            case "DF002":
                $text = lang('支付宝账户列表') . "\n";
                break;
            case "DF005":
                $text = lang('数字人民币账户列表') . "\n";
                break;
        }


        $list = Bank::where('member_id', $chatId)
            ->where("channel", $channel)
            ->get();

        $keyboard = [];
        foreach ($list as $item) {
            $keyboard[] = [['text' => $item->getAlias(), 'callback_data' => "withdrawAddress@@bank_detail{$item->getId()}"]];
        }
        if (count($list) < 5) {
            $keyboard[] = [
                ['text' => lang("➕ 添加"), 'callback_data' => "withdrawAddress@@bank_choose_channel_{$channel}"],
                ['text' => lang("↩️返回"), 'callback_data' => "topUp@@home"]
            ];
        } else {
            $keyboard[] = [['text' => lang("↩️返回"), 'callback_data' => "topUp@@home"]];
        }

        return [
            'chat_id' => $chatId,
            'text' => $text,
            'message_id' => $messageId,
            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
        ];
    }

    //银行卡详情
    private static function bankDetails($chatId, $messageId, $id)
    {
        $bank = Bank::where('id', $id)
            ->where('member_id', $chatId)->first();
        switch ($bank->getChannel()) {
            case "DF001":
                $text = "*" . lang('银行卡管理') . "*\n\n";
                $text .= lang('姓名') . "：{$bank->getAccount()}\n";
                $text .= lang('银行') . "：{$bank->getAccount()}\n";
                $text .= lang('卡号') . "：{$bank->getCardNo()}\n";
                break;
            case "DF002":
                $text = "*" . lang('支付宝管理') . "*\n\n";
                $text .= lang('姓名') . "：{$bank->getAccount()}\n";
                $text .= lang('银行') . "：{$bank->getBankName()}\n";
                $text .= lang('账号') . "：{$bank->getCardNo()}\n";
                break;
            default:
                $text = "*" . lang('银行卡管理') . "*\n\n";
                $text .= lang('姓名') . "：{$bank->getAccount()}\n";
                $text .= lang('银行') . "：{$bank->getBankName()}\n";
                $text .= lang('卡号') . "：{$bank->getCardNo()}\n";
                break;
        }


        $keyboard = [
            [
                ['text' => lang('❌删除'), 'callback_data' => "withdraw@@bank_del_{$id}"],
                ['text' => lang('↩️返回列表'), 'callback_data' => "withdraw@@management_{$bank->getChannel()}"]
            ],
        ];
        return [
            'chat_id' => $chatId,
            'parse_mode' => 'MarkdownV2',
            'text' => $text,
            'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
            'message_id' => $messageId
        ];
    }

    //删除银行卡
    private static function bankDelete($chatId, $messageId, $id): array
    {
        $channel = Bank::where('id', $id)
            ->where('member_id', $chatId)->first()->getChannel();
        Bank::where('id', $id)->where('member_id', $chatId)->delete();
        return static::banks($chatId, $messageId, $channel);
    }

    //选择通道
    private static function chooseChannel($chatId, $messageId, $channel)
    {
        Cache::put("{$chatId}_QB_WITHDRAW_CHANNEL", $channel);

        switch ($channel) {
            case "DF001"://银行卡
                Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_BANK_NAME);
                return [
                    'chat_id' => $chatId,
                    'text' => lang("请输入开户银行卡开户名称"),
                    'message_id' => $messageId,
                ];
            case "DF002"://支付宝
                Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '支付宝');
                Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
                return [
                    'chat_id' => $chatId,
                    'text' => lang("请输入支付宝账号"),
                    'message_id' => $messageId,
                ];
            case "DF005"://数字人民币
                Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '数字人民币');
                Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
                return [
                    'chat_id' => $chatId,
                    'text' => lang("请输入数字人民币账号"),
                    'message_id' => $messageId,
                ];

            default:
                return [
                    'chat_id' => $chatId,
                    'text' => lang("选择通道错误"),
                    'message_id' => $messageId,
                ];
        }
    }

    //输入银行名称
    private static function inputBankName($chatId, $bankName, $messageId): array
    {
        Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", $bankName);
        Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
        return [
            'chat_id' => $chatId,
            'text' => lang("请输入银行卡号"),
            'message_id' => $messageId,
        ];
    }

    //输入卡号
    private static function inputCardNo($chatId, $cardNo, $messageId): array
    {
        $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
        if ($channel === 'DF001' && !preg_match('/^\d+$/', $cardNo)) {
            return [
                'chat_id' => $chatId,
                'text' => lang("输入的银行卡号有误，请重新输入"),
                'reply_to_message_id' => $messageId,
            ];
        }


        Cache::put("{$chatId}_QB_WITHDRAW_CARD_NO", $cardNo);
        Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_ACCOUNT);

        return [
            'chat_id' => $chatId,
            'text' => lang("请输入姓名"),
            'message_id' => $messageId,
        ];
    }

    //输入姓名
    private static function inputAccount($chatId, $account, $messageId): array
    {
        Cache::put("{$chatId}_QB_ACCOUNT", $account);
        Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_ALIAS);
        $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
        $text = lang("请输入别名");
        switch ($channel) {
            case "DF005":
            case "DF001":
                $text = lang('请输入账号别名');
                break;
        }
        return [
            'chat_id' => $chatId,
            'text' => $text,
            'message_id' => $messageId,
        ];
    }

    //输入别名，并保存到数据库
    private static function inputAliAs($chatId, $alias, $messageId): array
    {
        $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
        $cardNo = Cache::get("{$chatId}_QB_WITHDRAW_CARD_NO");
        $bankName = Cache::get("{$chatId}_QB_WITHDRAW_BANK_NAME");
        $account = Cache::get("{$chatId}_QB_ACCOUNT");
        Bank::create([
            'member_id' => $chatId,
            'account' => $account,
            'channel' => $channel,
            'card_no' => $cardNo,
            'bank_name' => $bankName,
            'alias' => $alias
        ]);
        Cache::delete(get_step_key($chatId));
        return static::banks($chatId, $messageId, $channel);
    }
}
