|
|
@@ -198,6 +198,12 @@ class TelegramWebHook extends Controller
|
|
|
$telegram->editMessageText($res);
|
|
|
}
|
|
|
|
|
|
+ //点击提现按钮
|
|
|
+ if ($data === "withdraw@@qb_apply") {
|
|
|
+ $res =WithdrawService::qbApply($chatId, $messageId);
|
|
|
+ $telegram->editMessageText($res);
|
|
|
+ }
|
|
|
+
|
|
|
//地址管理
|
|
|
if ($data === 'withdraw@@address') {
|
|
|
$res = WithdrawService::getAddress($chatId, $messageId);
|
|
|
@@ -708,731 +714,4 @@ class TelegramWebHook extends Controller
|
|
|
|
|
|
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- public function handleMessage(Request $request)
|
|
|
- {
|
|
|
-
|
|
|
- $telegram = new Api(config('services.telegram.token'));
|
|
|
- $update = $telegram->getWebhookUpdate(); // 获取更新数据
|
|
|
- $update->callbackQuery;
|
|
|
- if ($update->has('callback_query')) {
|
|
|
-
|
|
|
- $json['type'] = 'callback_query';
|
|
|
- $callbackQuery = $update->callbackQuery;
|
|
|
- $json['update'] = $callbackQuery;
|
|
|
- $message = $callbackQuery->message;
|
|
|
- $from = $callbackQuery->from;
|
|
|
- $data = $callbackQuery->data; // 获取 callback_data
|
|
|
- $callbackId = $callbackQuery->id; // 获取 callback_query 的 ID
|
|
|
- $m = new Message();
|
|
|
- $m->json = $data;
|
|
|
- $m->save();
|
|
|
- Util::delCache($message->chat->id);
|
|
|
- DB::beginTransaction();
|
|
|
- try {
|
|
|
- $chatId = $message->chat->id;
|
|
|
- $firstName = $message->chat->firstName;
|
|
|
- $messageId = $message->messageId;
|
|
|
- if (!$from->isBot) {
|
|
|
- $chatId = $from->id;
|
|
|
- $firstName = $from->firstName;
|
|
|
- }
|
|
|
-
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => "你好{$data}"
|
|
|
- ]);
|
|
|
-
|
|
|
-
|
|
|
- $user = User::where('member_id', $chatId)->first();
|
|
|
- if (!$user) {
|
|
|
- $user = new User();
|
|
|
- $user->member_id = $chatId;
|
|
|
- }
|
|
|
- $user->first_name = $firstName;
|
|
|
- $user->save();
|
|
|
- //给每个用户生成一个专属的USDT钱包
|
|
|
- WalletService::getUserWallet($chatId);
|
|
|
-
|
|
|
- // 查看余额弹窗
|
|
|
- if ($data === 'balanceAlert') {
|
|
|
- Log::error('查看余额弹窗 balanceAlert: ' . $callbackId);
|
|
|
- // $alertText = WalletService::getBalance($chatId)['text'];
|
|
|
- WalletService::alertNotice($callbackId, '您好,您的余额为:');
|
|
|
- }
|
|
|
-
|
|
|
- //取消创建游戏
|
|
|
- if ($data === "games@@cancel") {
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->cancel($chatId, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- if ($data === 'withdrawAddress@@done') {
|
|
|
- $res = WithdrawService::done($chatId, $messageId, $firstName);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //选择提现地址
|
|
|
- $pattern = "/^withdrawAddress@@choose\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $id = preg_replace('/^withdrawAddress@@choose/', '', $data);
|
|
|
- $res = WithdrawService::chooseAddress($chatId, $firstName, $messageId, $id);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //删除地址
|
|
|
- $pattern = "/^withdrawAddress@@del\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $id = preg_replace('/^withdrawAddress@@del/', '', $data);
|
|
|
- $res = WithdrawService::delAddress($chatId, $id, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
- //地址详情
|
|
|
- $pattern = "/^withdrawAddress@@detail\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $id = preg_replace('/^withdrawAddress@@detail/', '', $data);
|
|
|
- $res = WithdrawService::addressDetails($chatId, $messageId, $id);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
- //教程帮助
|
|
|
- $pattern = "/^Tutorial@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $index = preg_replace('/^Tutorial@@/', '', $data);
|
|
|
- $res = TutorialService::help($chatId, $index, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
- if ($data === 'Tutorial@@home') {
|
|
|
- $res = (new TutorialService())->index($chatId);
|
|
|
- $res['message_id'] = $messageId;
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //游戏房间首页
|
|
|
- $pattern = "/^games@@home\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^games@@home/', '', $data);
|
|
|
- $res = (new RoomService($telegram))->gameHome($roomId, $chatId, $messageId);
|
|
|
- $m = new Message();
|
|
|
- $m->json = json_encode($res);
|
|
|
- $m->save();
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //选择游戏
|
|
|
- $pattern = "/^inputGameName@@.+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $gameName = preg_replace('/^inputGameName@@/', '', $data);
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setGameName($chatId, $gameName, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //选择中途加入
|
|
|
- $pattern = "/^setGameMidway@@.+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $midway = preg_replace('/^setGameMidway@@/', '', $data);
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setGameMidway($chatId, $midway, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //确认游戏ID
|
|
|
- $pattern = "/^inputGameID@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $gameId = preg_replace('/^inputGameID@@/', '', $data);
|
|
|
- $rs = new RoomService($telegram);
|
|
|
- $res = $rs->setGameID($chatId, $gameId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //房间低分
|
|
|
- $pattern = '/^roomMin@@.*/';
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setMin($data, $chatId, $messageId);
|
|
|
- if (isset($res['message_id'])) {
|
|
|
- $telegram->editMessageText($res);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($res);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //删除本条数据
|
|
|
- if ($data === 'del@@message') {
|
|
|
- $telegram->deleteMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'message_id' => $messageId,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- //确认创建房间
|
|
|
- if ($data === 'room@@done') {
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->done($chatId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //客服帮助
|
|
|
- if ($data === "/tutorial") {
|
|
|
- $res = (new TutorialService())->index($chatId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //点击提现按钮
|
|
|
- if ($data === "withdraw@@apply") {
|
|
|
- $res = (new WithdrawService())->apply($chatId, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //钱宝提现
|
|
|
- if ($data === 'withdraw@@qb_apply') {
|
|
|
- $res = WithdrawService::qbApply($chatId, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //地址管理
|
|
|
- if ($data === 'withdraw@@address') {
|
|
|
- $res = WithdrawService::getAddress($chatId, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //点击充值按钮
|
|
|
- if ($data === 'topup@@topup') {
|
|
|
- $telegram->deleteMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'message_id' => $messageId,
|
|
|
- ]);
|
|
|
-// $topService = new TopUpService();
|
|
|
-// $res = $topService->scan($chatId, $messageId);
|
|
|
-// $telegram->sendPhoto($res);
|
|
|
- }
|
|
|
-
|
|
|
- //点击充值的账单按钮
|
|
|
- if ($data === 'topup@@bill') {
|
|
|
- $res = (new TopUpService())->bill($chatId, $firstName, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
-
|
|
|
-
|
|
|
-// $text = "📅 请输入查询日期\n";
|
|
|
-// $date = date('Y-m-d');
|
|
|
-// $text .= "例如您要查询的日期 {$date}\n";
|
|
|
-// $text .= "那么请发送:【充值账单】{$date}\n";
|
|
|
-// $telegram->sendMessage([
|
|
|
-// 'chat_id' => $chatId,
|
|
|
-// 'text' => $text
|
|
|
-// ]);
|
|
|
- }
|
|
|
-
|
|
|
- //关闭本条消息
|
|
|
- if ($data === 'message@@close') {
|
|
|
- $telegram->deleteMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'message_id' => $messageId
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- if ($data === 'withdrawAddress@@add') {
|
|
|
- $res = WithdrawService::addAddress($chatId, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //提现管理
|
|
|
- if ($data === "withdraw@@home") {
|
|
|
- $res = WithdrawService::index($chatId, $firstName, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //点击提现的账单按钮
|
|
|
- if ($data === "withdraw@@bill") {
|
|
|
- $res = (new WithdrawService())->bill($chatId, $firstName, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
-// $telegram->sendMessage($res);
|
|
|
-// $text = "📅 请输入查询日期\n";
|
|
|
-// $date = date('Y-m-d');
|
|
|
-// $text .= "例如您要查询的日期 {$date}\n";
|
|
|
-// $text .= "那么请发送:【提现账单】{$date}\n";
|
|
|
-// $telegram->sendMessage([
|
|
|
-// 'chat_id' => $chatId,
|
|
|
-// 'text' => $text
|
|
|
-// ]);
|
|
|
- }
|
|
|
-
|
|
|
- //充值首页
|
|
|
- if ($data === "topUp@@home" || $data === "topUp@@home1") {
|
|
|
- $res = (new TopUpService())->index($chatId, $firstName, $messageId);
|
|
|
- if ($data === "topUp@@home1") {
|
|
|
- $telegram->deleteMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'message_id' => $messageId
|
|
|
- ]);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- } else {
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //点击我已付款按钮
|
|
|
- //手动充值(后台审核后到账)
|
|
|
- if ($data === 'topUp@@pay2') {
|
|
|
- $telegram->deleteMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'message_id' => $messageId
|
|
|
- ]);
|
|
|
- $res = TopUpService::pay2($chatId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- } //
|
|
|
- //自动充值
|
|
|
- elseif ($data === 'topUp@@pay') {
|
|
|
- $telegram->deleteMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'message_id' => $messageId
|
|
|
- ]);
|
|
|
- $topService = new TopUpService();
|
|
|
- $res = $topService->done($chatId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //充值账单,下一页
|
|
|
- $pattern = "/^topUpBillNextPage@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $page = preg_replace('/^topUpBillNextPage@@/', '', $data);
|
|
|
- $page = intval($page);
|
|
|
- $res = (new TopUpService())->bill($chatId, $firstName, $messageId, $page);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //提现账单,下一页
|
|
|
- $pattern = "/^withdrawBillNextPage@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $page = preg_replace('/^withdrawBillNextPage@@/', '', $data);
|
|
|
- $page = intval($page);
|
|
|
- $res = (new WithdrawService())->bill($chatId, $firstName, $messageId, $page);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //提前开始游戏
|
|
|
- $pattern = "/^games@@start\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^games@@start/', '', $data);
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->start($chatId, $roomId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //解散房间
|
|
|
- $pattern = "/^games@@Disband\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $roomId = preg_replace('/^games@@Disband/', '', $data);
|
|
|
- $res = $roomService->disband($roomId, $chatId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //退出房间
|
|
|
- $pattern = "/^games@@exit\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->exit($data, $chatId, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //人员/状态
|
|
|
- $pattern = "/^games@@status\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^games@@status/', '', $data);
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->userStatus($roomId, $chatId, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //准备
|
|
|
- $pattern = "/^games@@ready\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^games@@ready/', '', $data);
|
|
|
- $res = (new RoomService($telegram))->ready($roomId, $chatId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //结算游戏
|
|
|
- $pattern = "/^games@@settle\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^games@@settle/', '', $data);
|
|
|
- $res = (new SettlementService())->settle($roomId, $chatId, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- //在线房间,下一页
|
|
|
- $pattern = "/^onlineNextPage@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $page = preg_replace('/^onlineNextPage@@/', '', $data);
|
|
|
- $page = intval($page);
|
|
|
- $res = (new OnLineService())->getList($chatId, $messageId, $page);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //我的战绩,下一页
|
|
|
- $pattern = "/^recordNextPage@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $page = preg_replace('/^recordNextPage@@/', '', $data);
|
|
|
- $page = intval($page);
|
|
|
- $res = (new RecordService())->getList($chatId, $firstName, $messageId, $page);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //加入房间
|
|
|
- $pattern = "/^join@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^join@@/', '', $data);
|
|
|
- $res = (new RoomService($telegram))->join($chatId, $roomId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //输入房间号加入房间
|
|
|
- if ($data === 'join@@room') {
|
|
|
- $res = OnLineService::joinRoom($chatId, $messageId);
|
|
|
- $telegram->editMessageText($res);
|
|
|
- }
|
|
|
-
|
|
|
- //通过频道加入房间
|
|
|
- $pattern = "/^channelJoin@@\d+$/";
|
|
|
- if (preg_match($pattern, $data)) {
|
|
|
- $roomId = preg_replace('/^channelJoin@@/', '', $data);
|
|
|
- $res = (new RoomService($telegram))->join($from->id, $roomId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) {
|
|
|
- $telegram->editMessageText($r);
|
|
|
- } else {
|
|
|
- $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- DB::commit();
|
|
|
- } //
|
|
|
- catch (MessageException $e) {
|
|
|
- DB::rollBack();
|
|
|
- $msg = $e->getMessage();
|
|
|
- $msg = json_decode($msg, true);
|
|
|
- $telegram->sendMessage($msg);
|
|
|
- } //
|
|
|
- catch (TelegramSDKException $e) {
|
|
|
- DB::rollBack();
|
|
|
- $m = new Message();
|
|
|
- $m->json = $e->getMessage();
|
|
|
- $m->save();
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => '‼️‼️系统发生了错误,请联系客服'
|
|
|
- ]);
|
|
|
- }//
|
|
|
- catch (\Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
- $m = new Message();
|
|
|
- $m->json = json_encode([
|
|
|
- 'line' => $e->getLine(),
|
|
|
- 'message' => $e->getMessage()
|
|
|
- ]);
|
|
|
- $m->save();
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => '‼️‼️系统发生了错误,请联系客服'
|
|
|
- ]);
|
|
|
- }
|
|
|
- } //
|
|
|
- else {
|
|
|
- $update = $request->all();
|
|
|
- if (isset($update['message'])) {
|
|
|
- $message = $update['message'];
|
|
|
- $chatId = $message['chat']['id'];
|
|
|
- $messageId = $message['message_id'];
|
|
|
- DB::beginTransaction();
|
|
|
- try {
|
|
|
- $m = new Message();
|
|
|
- $m->json = json_encode($update);
|
|
|
- $m->save();
|
|
|
-
|
|
|
- $user = User::where('member_id', $chatId)->first();
|
|
|
- if (!$user) {
|
|
|
- $user = new User();
|
|
|
- $user->member_id = $chatId;
|
|
|
- }
|
|
|
- $user->first_name = $message['chat']['first_name'];
|
|
|
- $user->save();
|
|
|
- //给每个用户生成一个专属的USDT钱包
|
|
|
- WalletService::getUserWallet($chatId);
|
|
|
-
|
|
|
-
|
|
|
- //用户发送图片,结算截图
|
|
|
- if (isset($message['photo'])) {
|
|
|
- $stepStatus = Cache::get(get_step_key($chatId), -1);
|
|
|
- $stepStatus = intval($stepStatus);
|
|
|
- //结算截图
|
|
|
- if ($stepStatus === StepStatus::INPUT_IMAGE) {
|
|
|
- $photo = $message['photo'][count($message['photo']) - 1];
|
|
|
- $res = (new SettlementService())->photo($photo, $chatId);
|
|
|
- if ($res) $telegram->sendMessage($res);
|
|
|
- }//
|
|
|
- //充值截图
|
|
|
- else if ($stepStatus === StepStatus::INPUT_TOP_UP_IMAGE) {
|
|
|
- $photo = $message['photo'][count($message['photo']) - 1];
|
|
|
- $res = TopUpService::photo($chatId, $photo);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- }
|
|
|
-
|
|
|
- } //用户发送了消息
|
|
|
- else if (isset($message['text'])) {
|
|
|
- $text = $message['text'];
|
|
|
- if ($message['chat']['type'] === 'private') {
|
|
|
- switch ($text) {
|
|
|
- //教程帮助
|
|
|
- case "/tutorial":
|
|
|
- Util::delCache($chatId);
|
|
|
- $res = (new TutorialService())->index($chatId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //提现管理
|
|
|
- case "/withdraw":
|
|
|
- Util::delCache($chatId);
|
|
|
- $res = WithdrawService::index($chatId, $message['chat']['first_name']);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //我的战绩
|
|
|
- case "/record":
|
|
|
- Util::delCache($chatId);
|
|
|
- $res = (new RecordService())->getList($chatId, $message['chat']['first_name']);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //充值管理
|
|
|
- case "/topup":
|
|
|
- Util::delCache($chatId);
|
|
|
- $res = (new TopUpService())->index($chatId, $message['chat']['first_name']);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //在线房间
|
|
|
- case"/online":
|
|
|
- Util::delCache($chatId);
|
|
|
- $data = (new OnLineService())->getList($chatId, null, 1);
|
|
|
- $telegram->sendMessage($data);
|
|
|
- break;
|
|
|
- //创建房间
|
|
|
- case "/room":
|
|
|
- Util::delCache($chatId);
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->create($chatId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- case "/start":
|
|
|
- Util::delCache($chatId);
|
|
|
- $user = User::where('member_id', $chatId)->first();
|
|
|
- if (!$user) {
|
|
|
- $user = new User();
|
|
|
- $user->member_id = $chatId;
|
|
|
- }
|
|
|
- $user->first_name = $message['chat']['first_name'];
|
|
|
- $user->save();
|
|
|
- //给每个用户生成一个专属的USDT钱包
|
|
|
- WalletService::getUserWallet($chatId);
|
|
|
-
|
|
|
- $username = config('services.telegram.username');
|
|
|
- $telegram->sendMessage(['chat_id' => $chatId, 'text' => "🎉欢迎使用 @{$username}"]);
|
|
|
- break;
|
|
|
- default:
|
|
|
- $stepStatus = Cache::get(get_step_key($chatId), -1);
|
|
|
- $stepStatus = intval($stepStatus);
|
|
|
- switch ($stepStatus) {
|
|
|
- case StepStatus::INPUT_GAME_INTRODUCTION:
|
|
|
- $res = (new RoomService($telegram))->setIntroduction($chatId, $text, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_TOP_UP_MONEY:
|
|
|
- $res = TopUpService::inputAmount($chatId, $text, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_JOIN_ROOM_ID:
|
|
|
- $res = OnLineService::join($chatId, $text, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) $telegram->editMessageText($r);
|
|
|
- else $telegram->sendMessage($r);
|
|
|
- }
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_ADDRESS_ALIAS:
|
|
|
- $res = WithdrawService::inputAlias($chatId, $text, $messageId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_ADDRESS_TRC20:
|
|
|
- $res = WithdrawService::inputAddress($chatId, $text, $messageId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_WITHDRAW_MONEY:
|
|
|
- $res = (new WithdrawService())->inputAmount($chatId, $text, $messageId);
|
|
|
- foreach ($res as $r) $telegram->sendMessage($r);
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_TOP_UP_IMAGE:
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => "输入错误,请上传充值截图!",
|
|
|
- 'reply_to_message_id' => $messageId
|
|
|
- ]);
|
|
|
- break;
|
|
|
- case StepStatus::INPUT_IMAGE:
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => "输入错误,请上传战绩截图!",
|
|
|
- 'reply_to_message_id' => $messageId
|
|
|
- ]);
|
|
|
- break;
|
|
|
- //输入结算分数
|
|
|
- case StepStatus::INPUT_SCORE:
|
|
|
- $res = (new SettlementService())->submitSettle($chatId, $text, $messageId);
|
|
|
- foreach ($res['data'] as $r) $telegram->sendMessage($r);
|
|
|
- break;
|
|
|
- //输入游戏名称
|
|
|
- case StepStatus::INPUT_GAME_NAME:
|
|
|
- $gameName = $text;
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setGameName($chatId, $gameName, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //输入房间号
|
|
|
- case StepStatus::INPUT_ROOM_ID:
|
|
|
- $roomId = $text;
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setNum($chatId, $roomId, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //输入是否允许中途加入
|
|
|
- case StepStatus::INPUT_MIDWAY:
|
|
|
- $midway = $text;
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setGameMidway($chatId, $midway, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //输入 人数/局数
|
|
|
- case StepStatus::INPUT_ROOM_NUM:
|
|
|
- $array = explode('/', $text);
|
|
|
- $roomService = new RoomService($telegram);
|
|
|
- $res = $roomService->setNumberOfGames($chatId, $array, $messageId);
|
|
|
- if (isset($res['message_id'])) $telegram->editMessageText($res);
|
|
|
- else $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- //输入 游戏ID
|
|
|
- case StepStatus::INPUT_GAME_ID:
|
|
|
- $gameId = $text;
|
|
|
- $rs = new RoomService($telegram);
|
|
|
- $res = $rs->setGameID($chatId, $gameId, $messageId);
|
|
|
- foreach ($res as $r) {
|
|
|
- if (isset($r['message_id'])) $telegram->editMessageText($r);
|
|
|
- else $telegram->sendMessage($r);
|
|
|
- }
|
|
|
-
|
|
|
- break;
|
|
|
- break;
|
|
|
- default:
|
|
|
- Util::delCache($chatId);
|
|
|
- $res = (new TutorialService())->index($chatId);
|
|
|
- $telegram->sendMessage($res);
|
|
|
- break;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- DB::commit();
|
|
|
- } //
|
|
|
- catch (MessageException $e) {
|
|
|
- DB::rollBack();
|
|
|
- $m = new Message();
|
|
|
- $m->json = $e->getMessage();
|
|
|
- $m->save();
|
|
|
- try {
|
|
|
- $msg = $e->getMessage();
|
|
|
- $msg = json_decode($msg, true);
|
|
|
- $telegram->sendMessage($msg);
|
|
|
- } catch (TelegramSDKException $e) {
|
|
|
- }
|
|
|
- } //
|
|
|
- catch (TelegramSDKException $e) {
|
|
|
- DB::rollBack();
|
|
|
- $m = new Message();
|
|
|
- $m->json = $e->getMessage();
|
|
|
- $m->save();
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => '‼️‼️系统发生了错误,请联系客服'
|
|
|
- ]);
|
|
|
- }//
|
|
|
- catch (\Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
- $m = new Message();
|
|
|
- $m->json = $e->getMessage();
|
|
|
- $m->save();
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => '‼️‼️系统发生了错误,请联系客服'
|
|
|
- ]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- return response()->json(['status' => 'ok']);
|
|
|
- }
|
|
|
}
|