Ken 2 mesi fa
parent
commit
7b2f9e2729

+ 3 - 27
app/Http/Controllers/api/TelegramWebHook.php

@@ -90,6 +90,9 @@ class TelegramWebHook extends Controller
                 WalletService::getUserWallet($chatId);
 
 
+                QianBaoWithdrawService::init($telegram, $data, $chatId, $firstName, $messageId);
+
+
                 // 查看余额弹窗
                 if ($data === 'balanceAlert') {
                     $alertText = WalletService::getBalance($chatId)['text'];
@@ -199,18 +202,6 @@ class TelegramWebHook extends Controller
                     $telegram->editMessageText($res);
                 }
 
-                //点击钱宝提现按钮
-                if ($data === "withdraw@@qb_apply") {
-                    $res = QianBaoWithdrawService::qbApply($chatId, $messageId);
-                    $telegram->editMessageText($res);
-                }
-
-
-                //银行卡管理
-                if ($data === 'withdraw@@banks') {
-                    $res = QianBaoWithdrawService::banks($chatId, $messageId);
-                    $telegram->editMessageText($res);
-                }
 
                 //地址管理
                 if ($data === 'withdraw@@address') {
@@ -227,10 +218,6 @@ class TelegramWebHook extends Controller
                     ]);
                 }
 
-                if ($data = "withdrawAddress@@bang_add") {
-
-                }
-
 
                 if ($data === 'withdrawAddress@@add') {
                     $res = WithdrawService::addAddress($chatId, $messageId);
@@ -297,17 +284,6 @@ class TelegramWebHook extends Controller
                     $telegram->sendMessage($returnMsg);
                 }
 
-                //选择提现地址
-                $pattern = "/^withdrawAddress@@choose_qb_\d+$/";
-                if (preg_match($pattern, $data)) {
-                    $id = preg_replace('/^withdrawAddress@@choose_qb_/', '', $data);
-                    $res = QianBaoWithdrawService::chooseBank($chatId, $firstName, $messageId, $id);
-                    $telegram->deleteMessage([
-                        'chat_id' => $chatId,
-                        'message_id' => $messageId,
-                    ]);
-                    $telegram->sendMessage($res);
-                }
 
                 //选择提现地址
                 $pattern = "/^withdrawAddress@@choose\d+$/";

+ 66 - 2
app/Services/QianBaoWithdrawService.php

@@ -9,9 +9,53 @@ 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);
+        }
+    }
+
+
     //1.钱宝提现
     static function qbApply($chatId, $messageId)
     {
@@ -99,7 +143,7 @@ class QianBaoWithdrawService
     }
 
     //3.选择银行卡号
-    static function chooseBank($chatId, $firstName, $messageId, $id)
+    static function chooseBank($chatId, $id)
     {
         $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY", '');
         if (!$amount) return WalletService::getBalance($chatId);
@@ -129,7 +173,7 @@ class QianBaoWithdrawService
             $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
         }
         if (count($list) < 5) {
-            $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bang_add"]];
+            $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bank_add"]];
         }
         $keyboard[] = [['text' => "↩️返回", 'callback_data' => "withdraw@@home"]];
         return [
@@ -140,6 +184,26 @@ class QianBaoWithdrawService
         ];
     }
 
+    static function addBank($chatId, $messageId)
+    {
+        $text = "请选择 提现通道\n";
+
+        $keyboard = [
+            [
+                ['text' => '银行卡', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF001"]
+            ],
+            [
+                ['text' => '支付宝', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF002"]
+            ]
+        ];
+
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'message_id' => $messageId,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
+        ];
+    }
 
 
 }