| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- namespace App\Services;
- use App\Constants\StepStatus;
- use App\Models\Bank;
- use App\Models\Config;
- use App\Models\Wallet;
- use Illuminate\Support\Facades\Cache;
- use Telegram\Bot\Api;
- class QianBaoWithdrawService
- {
- /**
- * @param Api $telegram
- * @param $data
- * @param $chatId
- * @param $firstName
- * @param $messageId
- * @throws \Telegram\Bot\Exceptions\TelegramSDKException
- */
- static function init(Api $telegram, $data, $chatId, $firstName, $messageId)
- {
- //点击钱宝提现按钮
- if ($data === "withdraw@@qb_apply") {
- $res = QianBaoWithdrawService::qbApply($chatId, $messageId);
- $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@@banks') {
- $res = QianBaoWithdrawService::banks($chatId, $messageId);
- $telegram->editMessageText($res);
- }
- //添加银行卡
- if ($data === "withdrawAddress@@bank_add") {
- $res = QianBaoWithdrawService::addBank($chatId, $messageId);
- $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);
- }
- }
- //1.钱宝提现
- 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 = "请发送提现金额\n";
- $text .= "💰 当前余额{$temp} RMB\n";
- Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'message_id' => $messageId,
- ];
- }
- //2.输入钱宝提现金额
- static function inputQbAmount($chatId, $amount, $messageId)
- {
- if (!preg_match('/^\d+(\.\d{1,2})?$/', $amount)) {
- return [
- 'chat_id' => $chatId,
- 'text' => "金额输入不正确,请发送提现数字",
- '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' => "⚠️可用余额不足,请重试",
- 'reply_to_message_id' => $messageId
- ];
- }
- if ($amount < 100) {
- return [
- 'chat_id' => $chatId,
- 'text' => "⚠️提现不能少于100 RMB,请重试",
- 'reply_to_message_id' => $messageId
- ];
- }
- if ($amount > 49999) {
- return [
- 'chat_id' => $chatId,
- 'text' => "⚠️最多提现 49999 RMB,请重试",
- 'reply_to_message_id' => $messageId
- ];
- }
- Cache::put("{$chatId}_WITHDRAW_MONEY", $amount);
- $list = Bank::where('member_id', $chatId)->get();
- $keyboard = [];
- foreach ($list as $item) {
- $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@choose_qb_{$item->id}"]];
- }
- $keyboard[] = [
- ['text' => '🏠 银行卡管理', 'callback_data' => "withdraw@@banks"],
- ['text' => '❌取消', 'callback_data' => "message@@close"]
- ];
- $text = "请直接选择下面的地址\n";
- $text .= "⚠️提示:请务必确认提现地址正确无误,\n否则资金丢失将无法找回请自负!";
- Cache::put("{$chatId}_WITHDRAW_QB_MONEY", $amount);
- Cache::put(get_step_key($chatId), StepStatus::CHOOSE_WITHDRAW_QB_ADDRESS);
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'reply_to_message_id' => $messageId,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
- ];
- }
- //3.选择银行卡号
- static function chooseBank($chatId, $id)
- {
- $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY", '');
- if (!$amount) return WalletService::getBalance($chatId);
- $bank = Bank::where('id', $id)->first();
- // PaymentOrderService::createPayout($chatId, $amount, $bank->channel, $bank->bank_name, $bank->account, $bank->card_no);
- $text = "提交成功\n";
- $text .= "结果将在稍后通知您,请留意通知!!!";
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- ];
- }
- //银行卡管理
- static function banks($chatId, $messageId)
- {
- $text = "🏠 银行卡管理\n";
- $text .= "--------------------------\n";
- $list = Bank::where('member_id', $chatId)
- ->get();
- $keyboard = [];
- foreach ($list as $item) {
- $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
- }
- if (count($list) < 5) {
- $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bank_add"]];
- }
- $keyboard[] = [['text' => "↩️返回", 'callback_data' => "withdraw@@home"]];
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'message_id' => $messageId,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
- ];
- }
- static function addBank($chatId, $messageId)
- {
- $text = "请选择 提现通道\n";
- $keyboard = [
- [
- ['text' => '银行卡', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF001"],
- ['text' => '支付宝', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF002"]
- ],
- [
- ['text' => '❌取消', 'callback_data' => "message@@close"]
- ]
- ];
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'message_id' => $messageId,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
- ];
- }
- static function chooseChannel($chatId, $messageId, $channel)
- {
- Cache::put("{$chatId}_QB_WITHDRAW_CHANNEL", $channel);
- switch ($channel) {
- 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' => "请输入支付宝账号",
- 'message_id' => $messageId,
- ];
- break;
- case "DF001"://银行卡
- Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_BANK_NAME);
- return [
- 'chat_id' => $chatId,
- 'text' => "请输入银行名称",
- 'message_id' => $messageId,
- ];
- break;
- default:
- return [
- 'chat_id' => $chatId,
- 'text' => "选择通道错误",
- 'message_id' => $messageId,
- ];
- break;
- }
- }
- static function inputBankName($chatId, $bankName, $messageId)
- {
- Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", $bankName);
- Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
- return [
- 'chat_id' => $chatId,
- 'text' => "请输入银行卡号",
- 'message_id' => $messageId,
- ];
- }
- static function inputCardNo($chatId, $cardNo, $messageId)
- {
- Cache::put("{$chatId}_QB_WITHDRAW_CARD_NO", $cardNo);
- Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_ACCOUNT);
- return [
- 'chat_id' => $chatId,
- 'text' => "请输入姓名",
- 'message_id' => $messageId,
- ];
- }
- static function inputAccount($chatId, $account, $messageId)
- {
- $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
- $cardNo = Cache::get("{$chatId}_QB_WITHDRAW_CARD_NO");
- $bankName = Cache::get("{$chatId}_QB_WITHDRAW_BANK_NAME");
- Bank::create([
- 'member_id' => $chatId,
- 'account' => $account,
- 'channel' => $channel,
- 'card_no' => $cardNo,
- 'bank_name' => $bankName
- ]);
- return static::banks($chatId, $messageId);
- }
- }
|