Ken пре 1 недеља
родитељ
комит
82a7005cbc

+ 8 - 241
app/Http/Controllers/api/TelegramWebHook.php

@@ -7,6 +7,7 @@ use App\Constants\Util;
 use App\Exceptions\MessageException;
 use App\Models\Message;
 use App\Models\User;
+use App\Services\PublicService;
 use App\Services\QianBaoWithdrawService;
 use App\Services\SanJinRechargeService;
 use App\Services\SecretService;
@@ -92,253 +93,19 @@ class TelegramWebHook extends BaseController
                     WalletService::getUserWallet($chatId);
 
 
+                    PublicService::init($telegram, $data, $chatId, $firstName, $messageId);
+                    WalletService::init($telegram, $data, $chatId, $firstName, $messageId, $callbackId);
+                    TopUpService::init($telegram, $data, $chatId, $firstName, $messageId);
                     QianBaoWithdrawService::init($telegram, $data, $chatId, $firstName, $messageId);
                     SanJinRechargeService::init($telegram, $data, $chatId, $firstName, $messageId);
                     SecretService::init($telegram, $data, $chatId, $firstName, $messageId);
                     UserService::init($telegram, $data, $chatId, $firstName, $messageId);
+                    WithdrawService::init($telegram, $data, $chatId, $firstName, $messageId);
+                    BetService::init($telegram, $data, $chatId, $firstName, $messageId, $callbackId);
+                    BalanceLogService::init($telegram, $data, $chatId, $firstName, $messageId, $callbackId);
+                    IssueService::init($telegram, $data, $chatId, $firstName, $messageId);
 
 
-                    // 查看余额弹窗
-                    if ($data === 'balanceAlert') {
-                        $alertText = WalletService::getBalance($chatId)['text'];
-                        WalletService::alertNotice($callbackId, $alertText);
-                    }
-                    // 今日流水弹窗
-                    if ($data === 'todayFlowAlert') {
-                        $alertText = BalanceLogService::getTodayFlowing($chatId)['text'];
-                        BalanceLogService::alertNotice($callbackId, $alertText);
-                    }
-                    // 近期注单弹窗
-                    if ($data === 'betsAlert') {
-                        Cache::put('message_id_bet_record_' . $chatId, 0, 600);
-                        $alertText = BetService::recentlyRecord($chatId);
-                        BetService::alertNotice($callbackId, $alertText);
-                    }
-
-                    //选择充值地址
-                    if ($data === "topUp@@TRC20" || $data === "topUp@@ERC20") {
-                        $type = preg_replace('/^topUp@@/', '', $data);
-                        $topService = new TopUpService();
-                        $res = $topService->scan($chatId, $messageId, $type);
-                        $telegram->deleteMessage([
-                            'chat_id' => $chatId,
-                            'message_id' => $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);
-                        $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);
-                    }
-
-                    //充值首页
-                    if ($data === "topUp@@home" || $data === "topUp@@home1") {
-                        $returnMsg = WalletService::getBalance($chatId);
-                        if ($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,
-                        //         'message_id' => $messageId
-                        //     ]);
-                        //     $telegram->sendMessage($res);
-                        // } else {
-                        //     $telegram->editMessageText($res);
-                        // }
-                    }
-
-
-                    //点击提现按钮
-                    if ($data === "withdraw@@apply") {
-                        $res = (new WithdrawService())->apply($chatId, $messageId);
-                        $telegram->editMessageText($res);
-                    }
-
-
-                    //地址管理
-                    if ($data === 'withdraw@@address') {
-                        $res = WithdrawService::getAddress($chatId, $messageId);
-                        $telegram->editMessageText($res);
-                    }
-
-
-                    //关闭本条消息
-                    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);
-                        $telegram->deleteMessage([
-                            'chat_id' => $chatId,
-                            'message_id' => $messageId
-                        ]);
-                        $returnMsg = WalletService::getBalance($chatId);
-                        if ($returnMsg) {
-                            $this->telegram->sendMessage($returnMsg);
-                        }
-                    }
-
-                    //点击提现的账单按钮
-                    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 === 'withdrawAddress@@done') {
-                        $res = WithdrawService::done($chatId, $messageId, $firstName);
-                        $telegram->editMessageText($res);
-                    }
-
-                    // 今日汇率
-                    if ($data === 'todayExchangeRate@@rate') {
-                        BetService::todayExchangeRate($chatId);
-                        // $telegram->sendMessage($res);
-                    }
-
-                    //查看开奖历史图片
-                    $pattern = "/^showLotteryHistory@@\d+$/";
-                    if (preg_match($pattern, $data)) {
-                        $id = preg_replace('/^showLotteryHistory@@/', '', $data);
-                        IssueService::sendLotteryImage($chatId, $id);
-                    }
-
-                    //选择投注记录
-                    $pattern = "/^betRecordType@@\d+$/";
-                    if (preg_match($pattern, $data)) {
-                        $type = preg_replace('/^betRecordType@@/', '', $data);
-                        Cache::put('message_id_bet_record_' . $chatId, intval($type), 600);
-                        $telegram->deleteMessage([
-                            'chat_id' => $chatId,
-                            'message_id' => $messageId,
-                        ]);
-                        $returnMsg = BetService::record($chatId);
-                        $telegram->sendMessage($returnMsg);
-                    }
-
-
-                    //选择提现地址
-                    $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 = "/^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 = "/^FlowingHistoryPage@@\d+$/";
-                    if (preg_match($pattern, $data)) {
-                        $page = preg_replace('/^FlowingHistoryPage@@/', '', $data);
-                        $page = intval($page);
-                        $returnMsg = BalanceLogService::getFlowingHistory($chatId, $messageId, $page);
-                        $telegram->editMessageText($returnMsg);
-                    }
-
-
-                    //提现账单,下一页
-                    $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 = "/^betRecordNextPage@@\d+$/";
-                    if (preg_match($pattern, $data)) {
-                        $page = preg_replace('/^betRecordNextPage@@/', '', $data);
-                        $page = intval($page);
-                        $res = BetService::record($chatId, $messageId, $page);
-                        $telegram->editMessageText($res);
-                    }
                     DB::commit();
                 } //
                 catch (MessageException $e) {

+ 29 - 10
app/Services/BalanceLogService.php

@@ -8,9 +8,28 @@ use App\Models\BalanceLog;
 class BalanceLogService extends BaseService
 {
 
-    public static $RW = ['充值','提现','人工充值','人工扣款','三方提现','三方充值','中奖','资产转移','比比返','投注','返水','回水','笔笔返','投注退分'];
-    public static $MODEL= BalanceLog::class;
+    public static $RW = ['充值', '提现', '人工充值', '人工扣款', '三方提现', '三方充值', '中奖', '资产转移', '比比返', '投注', '返水', '回水', '笔笔返', '投注退分'];
+    public static $MODEL = BalanceLog::class;
 
+    public static function init($telegram, $data, $chatId, $firstName, $messageId, $callbackId): void
+    {
+        switch ($data) {
+            case"todayFlowAlert":// 今日流水弹窗
+                $alertText = BalanceLogService::getTodayFlowing($chatId)['text'];
+                BalanceLogService::alertNotice($callbackId, $alertText);
+                break;
+            default:
+                //流水列表,下一页
+                $pattern = "/^FlowingHistoryPage@@\d+$/";
+                if (preg_match($pattern, $data)) {
+                    $page = preg_replace('/^FlowingHistoryPage@@/', '', $data);
+                    $page = intval($page);
+                    $returnMsg = BalanceLogService::getFlowingHistory($chatId, $messageId, $page);
+                    $telegram->editMessageText($returnMsg);
+                }
+                break;
+        }
+    }
 
 
     /**
@@ -134,7 +153,7 @@ class BalanceLogService extends BaseService
 
         $walletInfo = WalletService::model()::where('member_id', $memberId)->first();
         $text = '';
-        $text .= "当日流水: " . number_format((0-$flow), 2) . "\n";
+        $text .= "当日流水: " . number_format((0 - $flow), 2) . "\n";
         $text .= "返水额度: " . number_format($refund, 2) . "\n";
         $text .= "当日盈亏: " . number_format(($profit + $refund + $flow), 2) . "\n";
         $text .= "余额: " . number_format($walletInfo['available_balance'], 2) . "\n";
@@ -185,20 +204,20 @@ class BalanceLogService extends BaseService
         //     ->orderBy('created_at', 'desc')
         //     ->get();
 
-        $text = lang("流水历史")." \n";
+        $text = lang("流水历史") . " \n";
         foreach ($list as $item) {
             $text .= "---------------------\n";
-            $text .= lang("日期").": {$item['date']} \n";
-            $text .= lang("流水").": {$item['flow']} \n";
-            $text .= lang("返水").": {$item['refund']} \n";
-            $text .= lang("盈利").": {$item['profit']} \n";
+            $text .= lang("日期") . ": {$item['date']} \n";
+            $text .= lang("流水") . ": {$item['flow']} \n";
+            $text .= lang("返水") . ": {$item['refund']} \n";
+            $text .= lang("盈利") . ": {$item['profit']} \n";
         }
 
         $keyboard = [[
-            ['text' => "👇".lang("下一页"), 'callback_data' => "FlowingHistoryPage@@" . ($page + 1)]
+            ['text' => "👇" . lang("下一页"), 'callback_data' => "FlowingHistoryPage@@" . ($page + 1)]
         ]];
         if ($page > 1) {
-            array_unshift($keyboard[0], ['text' => "👆".lang("上一页"), 'callback_data' => "FlowingHistoryPage@@" . ($page - 1)]);
+            array_unshift($keyboard[0], ['text' => "👆" . lang("上一页"), 'callback_data' => "FlowingHistoryPage@@" . ($page - 1)]);
         }
         return [
             'chat_id' => $memberId,

+ 55 - 2
app/Services/BetService.php

@@ -16,12 +16,65 @@ use App\Jobs\SendTelegramMessageJob;
 use App\Jobs\SendTelegramGroupMessageJob;
 use Exception;
 use Illuminate\Support\Facades\Log;
+use Telegram\Bot\Api;
+use Telegram\Bot\Exceptions\TelegramSDKException;
 
 /**
  * 投注
  */
 class BetService extends BaseService
 {
+
+    /**
+     * @param Api $telegram
+     * @param $data
+     * @param $chatId
+     * @param $firstName
+     * @param $messageId
+     * @param $callbackId
+     * @return void
+     * @throws TelegramSDKException
+     */
+    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId, $callbackId): void
+    {
+        switch ($data) {
+            case "todayExchangeRate@@rate":  // 今日汇率
+                BetService::todayExchangeRate($chatId);
+                break;
+            case "betsAlert":// 近期注单弹窗
+                Cache::put('message_id_bet_record_' . $chatId, 0, 600);
+                $alertText = BetService::recentlyRecord($chatId);
+                BetService::alertNotice($callbackId, $alertText);
+                break;
+            default:
+                //选择投注记录
+                $pattern = "/^betRecordType@@\d+$/";
+                if (preg_match($pattern, $data)) {
+                    $type = preg_replace('/^betRecordType@@/', '', $data);
+                    Cache::put('message_id_bet_record_' . $chatId, intval($type), 600);
+                    $telegram->deleteMessage([
+                        'chat_id' => $chatId,
+                        'message_id' => $messageId,
+                    ]);
+                    $returnMsg = BetService::record($chatId);
+                    $telegram->sendMessage($returnMsg);
+                }
+
+
+                //近期注单,下一页
+                $pattern = "/^betRecordNextPage@@\d+$/";
+                if (preg_match($pattern, $data)) {
+                    $page = preg_replace('/^betRecordNextPage@@/', '', $data);
+                    $page = intval($page);
+                    $res = BetService::record($chatId, $messageId, $page);
+                    $telegram->editMessageText($res);
+                }
+                break;
+        }
+
+    }
+
+
     public static $OTHER_BET_1 = [
         '大',
         '小',
@@ -693,7 +746,7 @@ class BetService extends BaseService
             $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
             $balance = $walletInfo['available_balance'];
 
-            BalanceLogService::addLog($v['member_id'], $profit, ($balance - $profit),$balance, '投注退分', $v['id'], '');
+            BalanceLogService::addLog($v['member_id'], $profit, ($balance - $profit), $balance, '投注退分', $v['id'], '');
 
             $text = $issue_no . "期开奖失败 \n";
             $text .= "投注类型:{$v['keywords']} \n";
@@ -793,7 +846,7 @@ class BetService extends BaseService
                     'profit' => $profit,
                     'yl' => $yl,
                 ];
-                
+
                 $walletInfo = WalletService::findOne(['member_id' => $v['member_id']]);
                 $balance = $walletInfo['available_balance'];
                 WalletService::updateBalance($v['member_id'], $profit);

+ 84 - 37
app/Services/IssueService.php

@@ -31,11 +31,29 @@ class IssueService extends BaseService
 
     const COUNTDOWN_TO_CLOSING_THE_MARKET = 60;//提前xx秒封盘
 
+
+    public static function init($telegram, $data, $chatId, $firstName, $messageId): void
+    {
+        switch ($data) {
+            default:
+                //查看开奖历史图片
+                $pattern = "/^showLotteryHistory@@\d+$/";
+                if (preg_match($pattern, $data)) {
+                    $id = preg_replace('/^showLotteryHistory@@/', '', $data);
+                    IssueService::sendLotteryImage($chatId, $id);
+                }
+                break;
+        }
+
+    }
+
+
     /**
      * @description: 模型
      * @return {string}
      */
-    public static function model(): string
+    public
+    static function model(): string
     {
         return Issue::class;
     }
@@ -44,7 +62,8 @@ class IssueService extends BaseService
      * @description: 枚举
      * @return {*}
      */
-    public static function enum(): string
+    public
+    static function enum(): string
     {
         return '';
     }
@@ -54,7 +73,8 @@ class IssueService extends BaseService
      * @param {array} $search 查询内容
      * @return {array}
      */
-    public static function getWhere(array $search = []): array
+    public
+    static function getWhere(array $search = []): array
     {
         $where = [];
         if (isset($search['issue_no']) && !empty($search['issue_no'])) {
@@ -78,7 +98,8 @@ class IssueService extends BaseService
      * @param array $search
      * @return \App\Models\Coin|null
      */
-    public static function findOne(array $search): ?Issue
+    public
+    static function findOne(array $search): ?Issue
     {
         return self::model()::where(self::getWhere($search))->first();
     }
@@ -88,7 +109,8 @@ class IssueService extends BaseService
      * @param array $search
      * @return \Illuminate\Database\Eloquent\Collection
      */
-    public static function findAll(array $search = [])
+    public
+    static function findAll(array $search = [])
     {
         return self::model()::where(self::getWhere($search))->get();
     }
@@ -98,7 +120,8 @@ class IssueService extends BaseService
      * @param array $search
      * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
      */
-    public static function paginate(array $search = [])
+    public
+    static function paginate(array $search = [])
     {
         $limit = isset($search['limit']) ? $search['limit'] : 15;
         $paginator = self::model()::where(self::getWhere($search))->orderBy('issue_no', 'desc')->paginate($limit);
@@ -110,7 +133,8 @@ class IssueService extends BaseService
      * @param {*} $params
      * @return {*}
      */
-    public static function submit($params = [])
+    public
+    static function submit($params = [])
     {
         $result = false;
         $msg['code'] = self::NOT;
@@ -149,7 +173,8 @@ class IssueService extends BaseService
      * @param {*} $id
      * @return {*}
      */
-    public static function betting($id)
+    public
+    static function betting($id)
     {
         $info = self::findOne(['id' => $id]);
         if (!$info) {
@@ -203,7 +228,8 @@ class IssueService extends BaseService
      * @param {*} $id
      * @return {*}
      */
-    public static function closeBetting($id)
+    public
+    static function closeBetting($id)
     {
         $info = self::findOne(['id' => $id]);
         if (!$info) {
@@ -252,7 +278,8 @@ class IssueService extends BaseService
      * @param {*} $id
      * @return {*}
      */
-    public static function lotteryDrawFail($id)
+    public
+    static function lotteryDrawFail($id)
     {
 
         $result = false;
@@ -298,7 +325,8 @@ class IssueService extends BaseService
      * @param {*} $recordImage 开奖图片
      * @return {*}
      */
-    public static function lotteryDraw($id, $winning_numbers, $combo, $recordImage)
+    public
+    static function lotteryDraw($id, $winning_numbers, $combo, $recordImage)
     {
         $info = self::findOne(['id' => $id]);
         if (!$info) {
@@ -373,8 +401,9 @@ class IssueService extends BaseService
     }
 
 
-    // 虚拟开奖
-    public static function fakeLotteryDraw($issue_no, $awards)
+// 虚拟开奖
+    public
+    static function fakeLotteryDraw($issue_no, $awards)
     {
 
         $fake_bet_list = Cache::get('fake_bet_' . $issue_no, []);
@@ -412,7 +441,8 @@ class IssueService extends BaseService
      * @param {*} $winning_numbers
      * @return {*}
      */
-    public static function award($winning_numbers)
+    public
+    static function award($winning_numbers)
     {
         $result = [];
 
@@ -508,7 +538,8 @@ class IssueService extends BaseService
      * @param {*} $number
      * @return {*}
      */
-    public static function calculateOddEven($number)
+    public
+    static function calculateOddEven($number)
     {
         if ($number & 1) {
             return GameplayRuleEnum::SINGLE;
@@ -522,7 +553,8 @@ class IssueService extends BaseService
      * @param {*} $number
      * @return {*}
      */
-    public static function calculateSumSize($number)
+    public
+    static function calculateSumSize($number)
     {
         if ($number >= GameplayRuleEnum::SUM_BIG) {
             return GameplayRuleEnum::BIG;
@@ -538,7 +570,8 @@ class IssueService extends BaseService
      * @param {*} $number
      * @return {*}
      */
-    public static function calculateSumExtremeSize($number)
+    public
+    static function calculateSumExtremeSize($number)
     {
         $result = '';
         if ($number >= GameplayRuleEnum::SUM_EXTREME_BIG) {
@@ -559,7 +592,8 @@ class IssueService extends BaseService
      * @param {int} $c
      * @return {*}
      */
-    public static function isBaoZi(int $a, int $b, int $c)
+    public
+    static function isBaoZi(int $a, int $b, int $c)
     {
         $result = '';
         if ($a === $b && $b === $c) {
@@ -576,7 +610,8 @@ class IssueService extends BaseService
      * @param {int} $c
      * @return {*}
      */
-    public static function isPair($a, $b, $c)
+    public
+    static function isPair($a, $b, $c)
     {
         $result = '';
         // 确保输入都是个位数
@@ -601,7 +636,8 @@ class IssueService extends BaseService
      * @param {int} $c
      * @return {*}
      */
-    public static function isStraight($a, $b, $c)
+    public
+    static function isStraight($a, $b, $c)
     {
         $result = '';
         // 确保输入都是个位数(0-9)
@@ -636,7 +672,8 @@ class IssueService extends BaseService
      * @param int $number 输入数字
      * @return int 尾数
      */
-    public static function getLastDigit($number)
+    public
+    static function getLastDigit($number)
     {
         // 确保输入是整数
         $number = (int)$number;
@@ -652,7 +689,8 @@ class IssueService extends BaseService
      * @param {*} $number
      * @return {*}
      */
-    public static function calculateOneSize($number)
+    public
+    static function calculateOneSize($number)
     {
         if ($number >= GameplayRuleEnum::ONE_BIG) {
             return GameplayRuleEnum::BIG;
@@ -668,7 +706,8 @@ class IssueService extends BaseService
      * @param {*} $number
      * @return {*}
      */
-    public static function getSection($number)
+    public
+    static function getSection($number)
     {
         $result = '';
         if ($number >= GameplayRuleEnum::SECTION_1[0] && $number <= GameplayRuleEnum::SECTION_1[1]) {
@@ -687,7 +726,8 @@ class IssueService extends BaseService
      * @description: 近期开奖记录
      * @return {*}
      */
-    public static function currentLotteryResults($memberId)
+    public
+    static function currentLotteryResults($memberId)
     {
         // $result = self::model()::where('status', self::model()::STATUS_DRAW)->orderBy('id','desc')->take(16)->get();
         // $text = "📅 近期开奖记录\n";
@@ -772,7 +812,8 @@ class IssueService extends BaseService
         }
     }
 
-    public static function getCombo($winArr)
+    public
+    static function getCombo($winArr)
     {
         // 组合
         $sum = array_sum($winArr);
@@ -813,8 +854,9 @@ class IssueService extends BaseService
 
     }
 
-    // 获取最新的开奖数据
-    public static function getLatestIssue()
+// 获取最新的开奖数据
+    public
+    static function getLatestIssue()
     {
         $url = "https://ydpc28.co/api/pc28/list";
         $result = file_get_contents($url);
@@ -897,8 +939,9 @@ class IssueService extends BaseService
         return $result['list'];
     }
 
-    // 获取最新的开奖数据
-    public static function getLatestIssue2()
+// 获取最新的开奖数据
+    public
+    static function getLatestIssue2()
     {
         $url = "https://ydpc28.co/api/pc28/list";
         $result = file_get_contents($url);
@@ -981,8 +1024,9 @@ class IssueService extends BaseService
         return $result;
     }
 
-    // 封盘倒数
-    public static function syncCountdownIssue()
+// 封盘倒数
+    public
+    static function syncCountdownIssue()
     {
         $info = self::model()::where('status', self::model()::STATUS_BETTING)->orderBy('end_time', 'asc')->first();
         if ($info) {
@@ -1012,8 +1056,9 @@ class IssueService extends BaseService
         }
     }
 
-    // 停止下注
-    public static function syncCloseIssue()
+// 停止下注
+    public
+    static function syncCloseIssue()
     {
         $now_date = date('Y-m-d H:i:s', time() + 30); // 提前30秒
         $list = self::findAll(['status' => self::model()::STATUS_BETTING]);
@@ -1025,8 +1070,9 @@ class IssueService extends BaseService
         }
     }
 
-    // 生成开奖图片
-    public static function lotteryImage($issue_no)
+// 生成开奖图片
+    public
+    static function lotteryImage($issue_no)
     {
         $list = self::model()::where('issue_no', '<=', $issue_no)->where(self::getWhere(['status' => self::model()::STATUS_DRAW]))->orderBy('issue_no', 'desc')->take(20)->get();
         $records = $list->toArray();
@@ -1068,8 +1114,9 @@ class IssueService extends BaseService
 
     }
 
-    // 发送开奖图片
-    public static function sendLotteryImage($chatId, $issueNo)
+// 发送开奖图片
+    public
+    static function sendLotteryImage($chatId, $issueNo)
     {
 
         $recordImage = self::lotteryImage($issueNo);

+ 15 - 0
app/Services/PublicService.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Services;
+
+class PublicService extends BaseService
+{
+    public static function init($telegram, $data, $chatId, $firstName, $messageId): void
+    {
+        switch ($data) {
+            case "message@@close"://关闭本条消息
+                $telegram->deleteMessage(['chat_id' => $chatId, 'message_id' => $messageId]);
+                break;
+        }
+    }
+}

+ 60 - 3
app/Services/TopUpService.php

@@ -20,6 +20,63 @@ use App\Services\BalanceLogService;
 class TopUpService
 {
 
+    /**
+     * @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
+    {
+
+
+        switch ($data) {
+            case "topUp@@pay2"://手动充值(后台审核后到账)
+                $telegram->deleteMessage(['chat_id' => $chatId, 'message_id' => $messageId]);
+                $res = TopUpService::pay2($chatId);
+                $telegram->sendMessage($res);
+                break;
+            case "topUp@@pay"://自动充值
+                $telegram->deleteMessage(['chat_id' => $chatId, 'message_id' => $messageId]);
+                $res = TopUpService::done($chatId);
+                $telegram->sendMessage($res);
+                break;
+            case "topup@@bill"://点击充值的账单按钮
+                $res = TopUpService::bill($chatId, $firstName, $messageId);
+                $telegram->editMessageText($res);
+                break;
+            case "topup@@topup"://点击充值按钮
+                $res = TopUpService::chooseAddress($chatId, $messageId);
+                $telegram->editMessageText($res);
+                break;
+            case "topUp@@TRC20"://选择充值地址
+            case "topUp@@ERC20"://选择充值地址
+                $type = preg_replace('/^topUp@@/', '', $data);
+                $res = TopUpService::scan($chatId, $messageId, $type);
+                $telegram->deleteMessage(['chat_id' => $chatId, 'message_id' => $messageId]);
+                $telegram->sendPhoto($res);
+                break;
+            default:
+                //充值账单,下一页
+                $pattern = "/^topUpBillNextPage@@\d+$/";
+                if (preg_match($pattern, $data)) {
+                    $page = preg_replace('/^topUpBillNextPage@@/', '', $data);
+                    $page = intval($page);
+                    $res = TopUpService::bill($chatId, $firstName, $messageId, $page);
+                    $telegram->editMessageText($res);
+                }
+
+
+
+
+                break;
+        }
+    }
+
+
     /**
      * 到账通知
      * @param $memberId string 要通知的TgID
@@ -37,7 +94,7 @@ class TopUpService
         return true;
     }
 
-    public function bill($chatId, $firstName, $messageId = null, $page = 1, $limit = 5)
+    public static function bill($chatId, $firstName, $messageId = null, $page = 1, $limit = 5)
     {
         RechargeService::syncUsdtRechargeRecords($chatId);
         $list = BalanceLog::where('member_id', $chatId)
@@ -174,7 +231,7 @@ class TopUpService
     }
 
     //用户点击我已付款
-    public function done($chatId)
+    public static function done($chatId)
     {
         RechargeService::syncUsdtRechargeRecords($chatId);
         $keyboard = [
@@ -211,7 +268,7 @@ class TopUpService
     }
 
     //获取充值二维码
-    public function scan($chatId, $messageId, $type)
+    public static function scan($chatId, $messageId, $type)
     {
 
         // $receivingType = Config::where('field', 'receiving_type')->first()->val;

+ 42 - 4
app/Services/WalletService.php

@@ -22,6 +22,44 @@ use Telegram\Bot\Exceptions\TelegramSDKException;
  */
 class WalletService extends BaseService
 {
+
+    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId, $callbackId): void
+    {
+
+
+        switch ($data) {
+            case "withdraw@@home"://提现管理
+                $telegram->deleteMessage(['chat_id' => $chatId, 'message_id' => $messageId]);
+                $returnMsg = WalletService::getBalance($chatId);
+                if ($returnMsg) {
+                    $telegram->sendMessage($returnMsg);
+                }
+                break;
+            case "balanceAlert"://查看余额弹窗
+                $alertText = WalletService::getBalance($chatId)['text'];
+                WalletService::alertNotice($callbackId, $alertText);
+                break;
+            case "topUp@@home"://充值首页
+            case "topUp@@home1"://充值首页
+                $returnMsg = WalletService::getBalance($chatId);
+                if ($returnMsg) {
+                    if ($data === "topUp@@home1") {
+                        $telegram->deleteMessage(['chat_id' => $chatId, 'message_id' => $messageId]);
+                        $telegram->sendMessage($returnMsg);
+                    } else {
+                        $returnMsg['message_id'] = $messageId;
+                        $telegram->editMessageText($returnMsg);
+                    }
+                }
+                break;
+
+
+        }
+
+
+    }
+
+
     /**
      * @description: 模型
      * @return {string}
@@ -156,24 +194,24 @@ class WalletService extends BaseService
         $end_date = '2026-01-31';   // 活动结束
 
         $date = date('Y-m-d');
-        if($date >= $start_date && $date <= $end_date){
+        if ($date >= $start_date && $date <= $end_date) {
             $user = UserService::findOne(['member_id' => $memberId]);
             $amount = 28;//活动金额
             // 有用户名的账号
-            if($user && $user->getUsername()){
+            if ($user && $user->getUsername()) {
                 $wallets = self::findOne(['member_id' => $memberId]);
                 $before_balance = $wallets->available_balance;
                 $after_balance = $before_balance + $amount;
                 $wallets->available_balance = $after_balance;
                 $wallets->save();
-                BalanceLogService::addLog($memberId,$amount,$before_balance,$after_balance,'人工充值',0,'双旦活动注册赠送28');
+                BalanceLogService::addLog($memberId, $amount, $before_balance, $after_balance, '人工充值', 0, '双旦活动注册赠送28');
                 $returnMsg = WalletService::getBalance($user->getMemberId());
                 $telegram = new Api(config('services.telegram.token'));
                 $telegram->sendMessage($returnMsg);
 
             }
         }
-        
+
     }
 
     /**

+ 77 - 7
app/Services/WithdrawService.php

@@ -22,6 +22,72 @@ class WithdrawService
 {
     private $serviceCharge;
 
+    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
+    {
+
+
+        switch ($data) {
+            case "withdraw@@address"://地址管理
+                $res = WithdrawService::getAddress($chatId, $messageId);
+                $telegram->editMessageText($res);
+                break;
+            case "withdrawAddress@@done":
+                $res = WithdrawService::done($chatId, $messageId, $firstName);
+                $telegram->editMessageText($res);
+                break;
+            case "withdraw@@bill"://点击提现的账单按钮
+                $res = WithdrawService::bill($chatId, $firstName, $messageId);
+                $telegram->editMessageText($res);
+                break;
+            case "withdrawAddress@@add":
+                $res = WithdrawService::addAddress($chatId, $messageId);
+                $telegram->editMessageText($res);
+                break;
+            case "withdraw@@apply"://点击提现按钮
+                $res = WithdrawService::apply($chatId, $messageId);
+                $telegram->editMessageText($res);
+                break;
+            default:
+                //选择提现地址
+                $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 = "/^withdrawBillNextPage@@\d+$/";
+                if (preg_match($pattern, $data)) {
+                    $page = preg_replace('/^withdrawBillNextPage@@/', '', $data);
+                    $page = intval($page);
+                    $res = WithdrawService::bill($chatId, $firstName, $messageId, $page);
+                    $telegram->editMessageText($res);
+                }
+                break;
+
+        }
+
+    }
+
 
     public static function model(): string
     {
@@ -76,6 +142,12 @@ class WithdrawService
         $this->serviceCharge = $serviceCharge;
     }
 
+    public static function getServiceCharge(): float
+    {
+        $serviceCharge = Config::where('field', 'service_charge')->first()->val;
+        return floatval($serviceCharge);
+    }
+
     public static function notify($data)
     {
         try {
@@ -89,7 +161,7 @@ class WithdrawService
 
 
     //提现账单
-    public function bill($chatId, $firstName, $messageId = null, $page = 1, $limit = 5)
+    public static function bill($chatId, $firstName, $messageId = null, $page = 1, $limit = 5)
     {
         $list = Withdraw::where('member_id', $chatId)
             ->orderBy('id', 'desc')
@@ -331,9 +403,6 @@ class WithdrawService
         }
 
 
-
-
-
         $withdraw = new Withdraw();
         $withdraw->member_id = $chatId;
         $withdraw->amount = $amount;
@@ -350,7 +419,7 @@ class WithdrawService
         $afterBalance = bcsub($wallet->available_balance, $rate_rmb_amount, 2);
         $wallet->available_balance = $afterBalance;
         $wallet->save();
-        BalanceLogService::addLog($chatId,$changeAmount,$beforeBalance,$afterBalance,'提现',$withdraw->id,'');
+        BalanceLogService::addLog($chatId, $changeAmount, $beforeBalance, $afterBalance, '提现', $withdraw->id, '');
         $temp = floatval($afterBalance);
         $text = "✅ " . lang("提现申请已提交!") . "\n\n";
         $text .= lang("钱包余额") . ":{$temp} RMB\n";
@@ -475,7 +544,7 @@ class WithdrawService
 
 
     //申请提现
-    public function apply($chatId, $messageId)
+    public static function apply($chatId, $messageId)
     {
         $wallet = Wallet::where('member_id', $chatId)->first();
         // 汇率
@@ -484,11 +553,12 @@ class WithdrawService
         $rate = bcadd($rate, $exchange_rate_difference, 2);
         $temp = floatval($wallet->available_balance);
         $amount = bcdiv($temp, $rate, 2);
+        $serviceCharge = static::getServiceCharge();
         $text = lang("请发送提现金额");
         $text .= "\n💰 " . lang('当前余额') . ":{$temp} RMB\n";
         $text .= "⚠️" . lang('汇率') . ":1 USDT = {$rate} RMB\n";
         $text .= "💰 " . lang('当前可用USDT余额') . ":{$amount} USDT\n";
-        $text .= "⚠️ " . lang('提现将收取') . "{$this->serviceCharge}" . lang('U作为手续费') . "\n";
+        $text .= "⚠️ " . lang('提现将收取') . "{$serviceCharge}" . lang('U作为手续费') . "\n";
 //        $keyboard = [[
 //            ['text' => "🔙返回", 'callback_data' => "withdraw@@home"],
 //        ]];