Jelajahi Sumber

Merge branch 'master' of 47.76.126.2:seven/bot-28

seven 2 bulan lalu
induk
melakukan
143ec2a493
2 mengubah file dengan 64 tambahan dan 21 penghapusan
  1. 36 19
      app/Http/Controllers/api/TelegramWebHook.php
  2. 28 2
      app/Services/TopUpService.php

+ 36 - 19
app/Http/Controllers/api/TelegramWebHook.php

@@ -106,17 +106,27 @@ class TelegramWebHook extends Controller
                     BetService::alertNotice($callbackId, $alertText);
                 }
 
-                //点击充值按钮
-                if ($data === 'topup@@topup') {
+                //选择充值地址
+                if ($data === "topup@@TRC20" || $data === "topup@@ERC20") {
+                    $type = preg_replace('/^topup@@/', '', $data);
+                    $topService = new TopUpService();
+                    $res = $topService->scan($chatId, $messageId);
+
+
                     $telegram->deleteMessage([
                         'chat_id' => $chatId,
                         'message_id' => $messageId,
                     ]);
-                    $topService = new TopUpService();
-                    $res = $topService->scan($chatId, $messageId);
                     $telegram->sendPhoto($res);
                 }
 
+                //点击充值按钮
+                if ($data === 'topup@@topup') {
+
+                    $res = TopUpService::chooseAddress($chatId, $messageId);
+                    $telegram->editMessageText($res);
+                }
+
                 //点击充值的账单按钮
                 if ($data === 'topup@@bill') {
                     $res = (new TopUpService())->bill($chatId, $firstName, $messageId);
@@ -156,15 +166,22 @@ class TelegramWebHook extends Controller
 
                 //充值首页
                 if ($data === "topUp@@home" || $data === "topUp@@home1") {
-                    // $res = (new TopUpService())->index($chatId, $firstName, $messageId);
-                    $telegram->deleteMessage([
-                        'chat_id' => $chatId,
-                        'message_id' => $messageId
-                    ]);
                     $returnMsg = WalletService::getBalance($chatId);
                     if ($returnMsg) {
-                        $this->telegram->sendMessage($returnMsg);
+                        if ($data === "topUp@@home1") {
+                            $telegram->deleteMessage([
+                                'chat_id' => $chatId,
+                                'message_id' => $messageId
+                            ]);
+                            $this->telegram->sendMessage($returnMsg);
+                        } else {
+                            $returnMsg['message_id'] = $messageId;
+                            $telegram->editMessageText($returnMsg);
+                        }
+
                     }
+
+                    // $res = (new TopUpService())->index($chatId, $firstName, $messageId);
                     // if ($data === "topUp@@home1") {
                     //     $telegram->deleteMessage([
                     //         'chat_id' => $chatId,
@@ -353,12 +370,12 @@ class TelegramWebHook extends Controller
 
                     $returnMsg = $this->processChatMessage($chatId, $messageId, $message, $message['from']);
                     if ($returnMsg) {
-                        if(isset($returnMsg['photo']) && $returnMsg['photo'] != ''){
+                        if (isset($returnMsg['photo']) && $returnMsg['photo'] != '') {
                             $this->telegram->sendPhoto($returnMsg);
-                        }else{
+                        } else {
                             $this->telegram->sendMessage($returnMsg);
                         }
-                        
+
                     }
                     DB::commit();
                 } catch (MessageException $e) {
@@ -566,13 +583,13 @@ class TelegramWebHook extends Controller
                                 unset($res['text']);
                                 $res['caption'] = $text;
                                 $res['protect_content'] = true;  // 防止转发
-                                
+
                             }
 
                             return $res;
                             break;
                         }
-                        
+
                         $stepStatus = Cache::get(get_step_key($chatId), -1);
                         $stepStatus = intval($stepStatus);
                         switch ($stepStatus) {
@@ -619,20 +636,20 @@ class TelegramWebHook extends Controller
             ['投注大群']
         ];
 
-        if($replyInfo && $replyInfo->buttons){
+        if ($replyInfo && $replyInfo->buttons) {
             $keyboard = [];
             $buttons = json_decode($replyInfo->buttons, true);
 
             foreach ($buttons as $rowIndex => $row) {
-                if(!empty($row)){
+                if (!empty($row)) {
                     foreach ($row as $buttonIndex => $button) {
                         $keyboard[$rowIndex][$buttonIndex] = $button['text'];
                     }
                 }
-                
+
             }
             $keyboard = array_values($keyboard); // 重新索引数组
-            Log::error('自定义开始使用按钮: '.json_encode($keyboard));
+            Log::error('自定义开始使用按钮: ' . json_encode($keyboard));
 
         }
 

+ 28 - 2
app/Services/TopUpService.php

@@ -176,6 +176,32 @@ class TopUpService
         ];
     }
 
+    public static function chooseAddress($chatId, $messageId)
+    {
+//        $address = Config::where('field', 'receiving_address')->first()->val;
+//        $address1 = Config::where('field', 'receiving_address')->first()->val;
+
+        $keyboard = [
+            [
+                ['text' => 'TRC20', 'callback_data' => 'topUp@@TRC20'],
+                ['text' => 'ERC20', 'callback_data' => 'topUp@@ERC20']
+            ],
+            [
+                ['text' => "🔙返回", 'callback_data' => "topUp@@home"],
+            ]
+        ];
+
+        $text = '请选择网络类型';
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
+            'message_id' => $messageId,
+        ];
+
+
+    }
+
     //获取充值二维码
     public function scan($chatId, $messageId)
     {
@@ -198,9 +224,9 @@ class TopUpService
 
         $replyInfo = KeyboardService::findOne(['button' => '充值提示文字']);
         $caption = "\n";
-        if($replyInfo){
+        if ($replyInfo) {
             $caption .= "{$replyInfo->reply}\n\n";
-        }else{
+        } else {
             $caption .= "支持货币({$res['net']}):{$res['coin']}\n";
             $caption .= "专属收款地址:\n";
             $caption .= "{$address}\n";