Ken há 2 semanas atrás
pai
commit
23ae6f6559

+ 1 - 1
app/Http/Controllers/api/TelegramWebHook.php

@@ -554,7 +554,7 @@ class TelegramWebHook extends BaseController
                         break;
                     case "选择语言":
                         Util::delCache($chatId);
-                        $returnMsg = UserService::getLanguages($chatId, $user->language);
+                        $returnMsg = UserService::getLanguages($chatId);
                         break;
                     case "查看余额":
                     case "💰查看余额":

+ 35 - 2
app/Services/UserService.php

@@ -9,6 +9,8 @@ use App\Models\User;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
+use Telegram\Bot\Api;
+use Telegram\Bot\Exceptions\TelegramSDKException;
 
 class UserService extends BaseService
 {
@@ -108,13 +110,44 @@ class UserService extends BaseService
         return ['chat_id' => $chatId, 'text' => "✅ 游戏ID设置成功\n游戏ID:{$gameId}"];
     }
 
-    public static function getLanguages($chatId, $language)
+    /**
+     * @param Api $telegram
+     * @param $data
+     * @param $chatId
+     * @param $firstName
+     * @param $messageId
+     * @return void
+     * @throws TelegramSDKException
+     */
+    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
+    {
+        $pattern = "/^setLanguage@@.*$/";
+        if (preg_match($pattern, $data)) {
+            $language = preg_replace('/^setLanguage@@/', '', $data);
+            $res = UserService::setLanguage($chatId, $language, $messageId);
+            $telegram->editMessageText($res);
+        }
+    }
+
+    public static function setLanguage($chatId, $language, $messageId): array
+    {
+        $userInfo = self::findOne(['member_id' => $chatId]);
+        $userInfo->language = $language;
+        $userInfo->save();
+        return [
+            'chat_id' => $chatId,
+            'text' => lang("语言设置成功"),
+            'message_id' => $messageId,
+        ];
+    }
+
+    public static function getLanguages($chatId): array
     {
         $keyboard = [
             [['text' => lang('en'), 'callback_data' => "setLanguage@@en"]],
             [['text' => lang('zh'), 'callback_data' => "setLanguage@@zh"]],
             [['text' => lang('vi'), 'callback_data' => "setLanguage@@vi"]],
-            [ ['text' => lang('❌取消'), 'callback_data' => "message@@close"]],
+            [['text' => lang('❌取消'), 'callback_data' => "message@@close"]],
         ];
         return [
             'chat_id' => $chatId,

+ 2 - 0
lang/en/messages.php

@@ -132,6 +132,8 @@ return [
     "en" => "English",
     "zh" => "Chinese",
     "vi" => "Vietnamese",
+    "语言设置成功" => "Language set successfully",
+
 
 
 

+ 2 - 0
lang/vi/messages.php

@@ -132,6 +132,8 @@ return [
     "en" => "Tiếng Anh",
     "zh" => "Tiếng Trung",
     "vi" => "Tiếng Việt",
+    "语言设置成功" => "Cài đặt ngôn ngữ thành công",
+
 
 
 ];

+ 1 - 0
lang/zh/messages.php

@@ -132,4 +132,5 @@ return [
     "en" => "英语",
     "zh" => "中文",
     "vi" => "越南语",
+    "语言设置成功"=>"语言设置成功",
 ];