Ken há 9 horas atrás
pai
commit
c0cf0c7d9b
1 ficheiros alterados com 16 adições e 37 exclusões
  1. 16 37
      app/Services/QianBaoWithdrawService.php

+ 16 - 37
app/Services/QianBaoWithdrawService.php

@@ -9,6 +9,7 @@ use App\Models\PaymentOrder;
 use App\Models\Wallet;
 use Illuminate\Support\Facades\Cache;
 use Telegram\Bot\Api;
+use Telegram\Bot\Exceptions\TelegramSDKException;
 
 class QianBaoWithdrawService
 {
@@ -18,12 +19,10 @@ class QianBaoWithdrawService
      * @param $chatId
      * @param $firstName
      * @param $messageId
-     * @throws \Telegram\Bot\Exceptions\TelegramSDKException
+     * @throws TelegramSDKException
      */
-    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId)
+    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
     {
-
-
         //点击钱宝提现按钮
         if ($data === "withdraw@@qb_show_channel") {
             $res = QianBaoWithdrawService::chooseType($chatId, $messageId);
@@ -118,30 +117,16 @@ class QianBaoWithdrawService
 
     }
 
-    public static function onMessage($chatId, $text, $messageId, $stepStatus)
+    public static function onMessage($chatId, $text, $messageId, $stepStatus): null|array
     {
-        switch ($stepStatus) {
-            case StepStatus::QB_INPUT_ALIAS:
-                $res = QianBaoWithdrawService::inputAliAs($chatId, $text, $messageId);
-                return $res;
-                break;
-            case StepStatus::INPUT_WITHDRAW_QB_MONEY://输入提现金额
-                $res = QianBaoWithdrawService::inputQbAmount($chatId, $text, $messageId);
-                return $res;
-                break;
-            case StepStatus::QB_INPUT_BANK_NAME://输入银行名称
-                $res = QianBaoWithdrawService::inputBankName($chatId, $text, $messageId);
-                return $res;
-            case StepStatus::QB_INPUT_CARD_NO://输入银行卡号/支付宝账号
-                $res = QianBaoWithdrawService::inputCardNo($chatId, $text, $messageId);
-                return $res;
-                break;
-            case StepStatus::QB_INPUT_ACCOUNT://输入姓名
-                $res = QianBaoWithdrawService::inputAccount($chatId, $text, $messageId);
-                return $res;
-                break;
-        }
-        return null;
+        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,
+        };
     }
 
 
@@ -402,7 +387,7 @@ class QianBaoWithdrawService
 
 
     //银行卡管理
-    private static function banks($chatId, $messageId, $channel)
+    private static function banks($chatId, $messageId, $channel = ""): array
     {
         switch ($channel) {
             case "DF001":
@@ -493,7 +478,7 @@ class QianBaoWithdrawService
     }
 
     //添加银行卡
-    private static function addBank($chatId, $messageId)
+    private static function addBank($chatId, $messageId): array
     {
         $text = "请选择 提现通道\n";
 
@@ -527,7 +512,6 @@ class QianBaoWithdrawService
                     'text' => "请输入开户银行卡开户名称",
                     'message_id' => $messageId,
                 ];
-                break;
             case "DF002"://支付宝
                 Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '支付宝');
                 Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
@@ -536,7 +520,6 @@ class QianBaoWithdrawService
                     'text' => "请输入支付宝账号",
                     'message_id' => $messageId,
                 ];
-                break;
             case "DF005"://数字人民币
                 Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '数字人民币');
                 Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
@@ -545,7 +528,6 @@ class QianBaoWithdrawService
                     'text' => "请输入数字人民币账号",
                     'message_id' => $messageId,
                 ];
-                break;
 
             default:
                 return [
@@ -553,14 +535,11 @@ class QianBaoWithdrawService
                     'text' => "选择通道错误",
                     'message_id' => $messageId,
                 ];
-                break;
         }
-
-
     }
 
     //输入银行名称
-    private static function inputBankName($chatId, $bankName, $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);
@@ -572,7 +551,7 @@ class QianBaoWithdrawService
     }
 
     //输入卡号
-    private static function inputCardNo($chatId, $cardNo, $messageId)
+    private static function inputCardNo($chatId, $cardNo, $messageId): array
     {
         $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
         if ($channel === 'DF001' && !preg_match('/^\d+$/', $cardNo)) {