seven 3 päivää sitten
vanhempi
commit
3f97258171

+ 3 - 0
app/Http/Controllers/api/TelegramWebHook.php

@@ -10,6 +10,7 @@ use App\Models\Message;
 use App\Models\User;
 use App\Services\OnLineService;
 use App\Services\QianBaoWithdrawService;
+use App\Services\SanJinRechargeService;
 use App\Services\RecordService;
 use App\Services\RoomService;
 use App\Services\SettlementService;
@@ -92,6 +93,8 @@ class TelegramWebHook extends Controller
 
                 QianBaoWithdrawService::init($telegram, $data, $chatId, $firstName, $messageId);
 
+                SanJinRechargeService::init($telegram, $data, $chatId, $firstName, $messageId);
+
 
                 // 查看余额弹窗
                 if ($data === 'balanceAlert') {

+ 2 - 0
app/Services/Payment/SanJinService.php

@@ -11,8 +11,10 @@ class SanJinService extends BaseService
 {
     const REQUEST_URL = 'https://jkapi-sanjin.jkcbb.com/';
 
+    
     const PRODUCT_TEST = 'T888'; // 测试支付通道
 
+    public static $CHANNEL = ['test' => '测试' ,'zfb' => '支付宝'];
 
     public static $PRODUCT = [
         'T888' => [

+ 461 - 0
app/Services/SanJinRechargeService.php

@@ -0,0 +1,461 @@
+<?php
+
+namespace App\Services;
+
+use App\Constants\StepStatus;
+use App\Models\Bank;
+use App\Models\Config;
+use App\Models\PaymentOrder;
+use App\Models\Wallet;
+use Illuminate\Support\Facades\Cache;
+use Telegram\Bot\Api;
+
+class SanJinRechargeService
+{
+    /**
+     * @param Api $telegram
+     * @param $data
+     * @param $chatId
+     * @param $firstName
+     * @param $messageId
+     * @throws \Telegram\Bot\Exceptions\TelegramSDKException
+     */
+    public static function init(Api $telegram, $data, $chatId, $firstName, $messageId)
+    {
+        //点击三斤提现按钮
+        if ($data === "withdraw@@qb_apply") {
+            $res = SanJinRechargeService::qbApply($chatId, $messageId);
+            $telegram->editMessageText($res);
+        }
+
+
+        //三斤账单
+        $pattern = "/^topup@@sj_bill_\d+$/";
+        if (preg_match($pattern, $data)) {
+            $page = preg_replace('/^topup@@sj_bill_/', '', $data);
+            if (empty($page) || $page < 1) $page = 1;
+            $page = intval($page);
+            $res = SanJinRechargeService::bill($chatId, $firstName, $messageId, $page);
+            $telegram->editMessageText($res);
+        }
+
+
+        //选择银行卡号
+        $pattern = "/^withdrawAddress@@choose_qb_\d+$/";
+        if (preg_match($pattern, $data)) {
+            $id = preg_replace('/^withdrawAddress@@choose_qb_/', '', $data);
+            $res = SanJinRechargeService::chooseBank($chatId, $id);
+            $telegram->deleteMessage([
+                'chat_id' => $chatId,
+                'message_id' => $messageId,
+            ]);
+            $telegram->sendMessage($res);
+        }
+
+
+        //银行卡管理
+        if ($data === 'withdraw@@banks') {
+            $res = SanJinRechargeService::banks($chatId, $messageId);
+            $telegram->editMessageText($res);
+        }
+
+
+        //银行卡详情
+        $pattern = "/^withdrawAddress@@bank_detail\d+$/";
+        if (preg_match($pattern, $data)) {
+            $id = preg_replace('/^withdrawAddress@@bank_detail/', '', $data);
+            $res = static::bankDetails($chatId, $messageId, $id);
+            $telegram->editMessageText($res);
+        }
+
+        $pattern = "/^withdraw@@bank_del_\d+$/";
+        if (preg_match($pattern, $data)) {
+            $id = preg_replace('/^withdraw@@bank_del_/', '', $data);
+            $res = static::bankDelete($chatId, $messageId, $id);
+            $telegram->editMessageText($res);
+        }
+
+
+        //添加银行卡
+        if ($data === "withdrawAddress@@bank_add") {
+            $res = SanJinRechargeService::addBank($chatId, $messageId);
+            $telegram->editMessageText($res);
+        }
+
+        $pattern = "/^withdrawAddress@@bank_choose_channel_.*$/";
+        if (preg_match($pattern, $data)) {
+            $channel = preg_replace('/^withdrawAddress@@bank_choose_channel_/', '', $data);
+            $res = static::chooseChannel($chatId, $messageId, $channel);
+            $telegram->editMessageText($res);
+        }
+
+
+    }
+
+    public static function onMessage($chatId, $text, $messageId, $stepStatus)
+    {
+        switch ($stepStatus) {
+            case StepStatus::INPUT_WITHDRAW_QB_MONEY://输入提现金额
+                $res = SanJinRechargeService::inputQbAmount($chatId, $text, $messageId);
+                return $res;
+                break;
+            case StepStatus::QB_INPUT_BANK_NAME://输入银行名称
+                $res = SanJinRechargeService::inputBankName($chatId, $text, $messageId);
+                return $res;
+            case StepStatus::QB_INPUT_CARD_NO://输入银行卡号/支付宝账号
+                $res = SanJinRechargeService::inputCardNo($chatId, $text, $messageId);
+                return $res;
+                break;
+            case StepStatus::QB_INPUT_ACCOUNT://输入姓名
+                $res = SanJinRechargeService::inputAccount($chatId, $text, $messageId);
+                return $res;
+                break;
+        }
+        return null;
+    }
+
+    //三斤账单
+    private static function bill($chatId, $firstName, $messageId, $page = 1, $limit = 5)
+    {
+        $list = PaymentOrder::where('member_id', $chatId)
+            ->where('type', 1)
+            ->orderByDesc('created_at')
+            ->forPage($page, $limit)
+            ->get();
+
+        $count = PaymentOrder::where('member_id', $chatId)
+            ->where('type', 1)
+            ->count();
+
+
+        $text = "👤 {$firstName}({$chatId})    三斤提现记录\n\n";
+        foreach ($list as $item) {
+            $amount = floatval($item->amount);
+
+            $amount = $item->type == 2 ? "➖ {$amount}" : "➕ $amount";
+            $text .= "-------------------------------------\n";
+            $text .= "{$amount} \n";
+            $text .= "订单号:{$item->order_no}\n";
+
+            $text .= "银行:{$item->bank_name}\n";
+            $text .= "姓名:{$item->account}\n";
+            $text .= "卡号:{$item->card_no}\n";
+            $status = ['待处理', '处理中', '成功', '失败'];
+            $text .= "状态:{$status[$item->status]}\n";
+            if ($item->remark) {
+                $text .= "说明:{$item->remark}\n";
+            }
+            $text .= "日期:{$item->created_at}\n";
+        }
+
+        if ($page > 1) {
+            $keyboard[] = [
+                ['text' => "👆上一页", 'callback_data' => "withdraw@@bank_bill_" . ($page - 1)]
+            ];
+        }
+        $allPage = ceil($count / $limit);
+        if ($allPage > $page) {
+            if ($page > 1) {
+                $keyboard[count($keyboard) - 1][] = ['text' => "👇下一页", 'callback_data' => "withdraw@@bank_bill_" . ($page + 1)];
+            } else {
+                $keyboard[] = [
+                    ['text' => "👇下一页", 'callback_data' => "withdraw@@bank_bill_" . ($page + 1)]
+                ];
+            }
+        }
+        $keyboard[] = [
+            ['text' => "返回", 'callback_data' => "topUp@@home"]
+        ];
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'message_id' => $messageId,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
+        ];
+    }
+
+    //1.三斤提现
+    private static function qbApply($chatId, $messageId)
+    {
+        $three_payment_switch = Config::where('field', 'three_payment_switch')->first()->val;
+        if ($three_payment_switch != 1) {
+            $res = WalletService::getBalance($chatId);
+            $res['message_id'] = $messageId;
+            return $res;
+        }
+
+        $wallet = Wallet::where('member_id', $chatId)->first();
+        $temp = floatval($wallet->available_balance);
+        $text = "请发送提现金额\n";
+        $text .= "💰 当前余额{$temp} RMB\n";
+
+
+        Cache::put(get_step_key($chatId), StepStatus::INPUT_WITHDRAW_QB_MONEY);
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'message_id' => $messageId,
+        ];
+    }
+
+    //2.输入三斤提现金额
+    private static function inputQbAmount($chatId, $amount, $messageId)
+    {
+        if (!preg_match('/^\d+(\.\d{1,2})?$/', $amount)) {
+            return [
+                'chat_id' => $chatId,
+                'text' => "金额输入不正确,请发送提现数字",
+                'reply_to_message_id' => $messageId
+            ];
+        }
+        $amount = floatval($amount);
+        $wallet = Wallet::where('member_id', $chatId)->first();
+        $temp = floatval($wallet->available_balance);
+
+        if ($amount > $temp) {
+            return [
+                'chat_id' => $chatId,
+                'text' => "⚠️可用余额不足,请重试",
+                'reply_to_message_id' => $messageId
+            ];
+        }
+
+
+        if ($amount < 100) {
+            return [
+                'chat_id' => $chatId,
+                'text' => "⚠️提现不能少于100 RMB,请重试",
+                'reply_to_message_id' => $messageId
+            ];
+        }
+        if ($amount > 49999) {
+            return [
+                'chat_id' => $chatId,
+                'text' => "⚠️最多提现 49999 RMB,请重试",
+                'reply_to_message_id' => $messageId
+            ];
+        }
+
+
+        Cache::put("{$chatId}_WITHDRAW_MONEY", $amount);
+        $list = Bank::where('member_id', $chatId)->get();
+        $keyboard = [];
+        foreach ($list as $item) {
+            $keyboard[] = [['text' => "{$item->bank_name}({$item->card_no})", 'callback_data' => "withdrawAddress@@choose_qb_{$item->id}"]];
+        }
+        $keyboard[] = [
+            ['text' => '🏠 银行卡管理', 'callback_data' => "withdraw@@banks"],
+            ['text' => '❌取消', 'callback_data' => "message@@close"]
+        ];
+
+        $text = "请直接选择下面的地址\n";
+        $text .= "⚠️提示:请务必确认提现地址正确无误,\n否则资金丢失将无法找回请自负!";
+        Cache::put("{$chatId}_WITHDRAW_QB_MONEY", $amount);
+        Cache::put(get_step_key($chatId), StepStatus::CHOOSE_WITHDRAW_QB_ADDRESS);
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'reply_to_message_id' => $messageId,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
+        ];
+    }
+
+    //3.选择银行卡号
+    private static function chooseBank($chatId, $id)
+    {
+        $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY", '');
+        if (!$amount) return WalletService::getBalance($chatId);
+
+        $bank = Bank::where('id', $id)->first();
+        $result = PaymentOrderService::createPayout($chatId, $amount, $bank->channel, $bank->bank_name, $bank->account, $bank->card_no);
+        return $result;
+        // $text = "提交成功\n";
+        // $text .= "结果将在稍后通知您,请留意通知!!!";
+        // return [
+        //     'chat_id' => $chatId,
+        //     'text' => $text,
+        // ];
+    }
+
+    //银行卡管理
+    private static function banks($chatId, $messageId)
+    {
+        $text = "💳️ 银行卡管理\n";
+        $text .= "--------------------------\n";
+
+        $list = Bank::where('member_id', $chatId)
+            ->get();
+
+        $keyboard = [];
+        foreach ($list as $item) {
+            $keyboard[] = [['text' => "{$item->bank_name}({$item->card_no})", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
+        }
+        if (count($list) < 5) {
+            $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bank_add"]];
+        }
+        $keyboard[] = [['text' => "↩️返回", 'callback_data' => "topUp@@home"]];
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'message_id' => $messageId,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
+        ];
+    }
+
+    //银行卡详情
+    private static function bankDetails($chatId, $messageId, $id)
+    {
+
+        $text = "*银行卡管理*\n\n";
+        $bank = Bank::where('id', $id)
+            ->where('member_id', $chatId)->first();
+
+        switch ($bank->channel) {
+            case "DF001":
+                $text .= "姓名:{$bank->account}\n";
+                $text .= "银行:{$bank->bank_name}\n";
+                $text .= "卡号:{$bank->card_no}\n";
+                break;
+            case "DF002":
+                $text .= "姓名:{$bank->account}\n";
+                $text .= "银行:{$bank->bank_name}\n";
+                $text .= "账号:{$bank->card_no}\n";
+                break;
+            default:
+                $text .= "姓名:{$bank->account}\n";
+                $text .= "银行:{$bank->bank_name}\n";
+                $text .= "卡号:{$bank->card_no}\n";
+                break;
+        }
+
+
+        $keyboard = [
+            [['text' => '❌删除该地址', 'callback_data' => "withdraw@@bank_del_{$id}"]],
+            [['text' => '↩️返回列表', 'callback_data' => 'withdraw@@banks']]
+        ];
+        return [
+            'chat_id' => $chatId,
+            'parse_mode' => 'MarkdownV2',
+            'text' => $text,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
+            'message_id' => $messageId
+        ];
+    }
+
+    //删除银行卡
+    private static function bankDelete($chatId, $messageId, $id)
+    {
+        Bank::where('id', $id)
+            ->where('member_id', $chatId)->delete();
+
+        return static::banks($chatId, $messageId);
+    }
+
+    //添加银行卡
+    private static function addBank($chatId, $messageId)
+    {
+        $text = "请选择 提现通道\n";
+
+        $keyboard = [
+            [
+                ['text' => '银行卡', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF001"],
+                ['text' => '支付宝', 'callback_data' => "withdrawAddress@@bank_choose_channel_DF002"]
+            ],
+            [
+                ['text' => '❌取消', 'callback_data' => "message@@close"]
+            ]
+        ];
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'message_id' => $messageId,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
+        ];
+    }
+
+    //选择通道
+    private static function chooseChannel($chatId, $messageId, $channel)
+    {
+        Cache::put("{$chatId}_QB_WITHDRAW_CHANNEL", $channel);
+
+        switch ($channel) {
+            case "DF002"://支付宝
+                Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", '支付宝');
+                Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
+                return [
+                    'chat_id' => $chatId,
+                    'text' => "请输入支付宝账号",
+                    'message_id' => $messageId,
+                ];
+                break;
+            case "DF001"://银行卡
+                Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_BANK_NAME);
+                return [
+                    'chat_id' => $chatId,
+                    'text' => "请输入银行名称",
+                    'message_id' => $messageId,
+                ];
+                break;
+            default:
+                return [
+                    'chat_id' => $chatId,
+                    'text' => "选择通道错误",
+                    'message_id' => $messageId,
+                ];
+                break;
+        }
+
+
+    }
+
+    //输入银行名称
+    private static function inputBankName($chatId, $bankName, $messageId)
+    {
+        Cache::put("{$chatId}_QB_WITHDRAW_BANK_NAME", $bankName);
+        Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_CARD_NO);
+        return [
+            'chat_id' => $chatId,
+            'text' => "请输入银行卡号",
+            'message_id' => $messageId,
+        ];
+    }
+
+    //输入卡号
+    private static function inputCardNo($chatId, $cardNo, $messageId)
+    {
+        $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
+        if ($channel === 'DF001' && !preg_match('/^\d+$/', $cardNo)) {
+            return [
+                'chat_id' => $chatId,
+                'text' => "输入的银行卡号有误,请重新输入",
+                'reply_to_message_id' => $messageId,
+            ];
+        }
+
+
+        Cache::put("{$chatId}_QB_WITHDRAW_CARD_NO", $cardNo);
+        Cache::put(get_step_key($chatId), StepStatus::QB_INPUT_ACCOUNT);
+
+        return [
+            'chat_id' => $chatId,
+            'text' => "请输入姓名",
+            'message_id' => $messageId,
+        ];
+    }
+
+    //输入姓名,并保存到数据库
+    private static function inputAccount($chatId, $account, $messageId)
+    {
+        $channel = Cache::get("{$chatId}_QB_WITHDRAW_CHANNEL");
+        $cardNo = Cache::get("{$chatId}_QB_WITHDRAW_CARD_NO");
+        $bankName = Cache::get("{$chatId}_QB_WITHDRAW_BANK_NAME");
+        Bank::create([
+            'member_id' => $chatId,
+            'account' => $account,
+            'channel' => $channel,
+            'card_no' => $cardNo,
+            'bank_name' => $bankName
+        ]);
+        return static::banks($chatId, $messageId);
+    }
+}

+ 4 - 0
app/Services/WalletService.php

@@ -260,6 +260,10 @@ class WalletService extends BaseService
                 ['text' => '➕ 钱宝提现', 'callback_data' => "withdraw@@qb_apply"],
                 ['text' => '🧾 钱宝账单', 'callback_data' => "withdraw@@bank_bill_1"]
             ];
+            $keyboard[] = [
+                ['text' => '➕ 三斤充值', 'callback_data' => "topup@@sj_apply"],
+                ['text' => '🧾 三斤账单', 'callback_data' => "topup@@sj_bill_1"]
+            ];
         }
         $keyboard[] = [
             ['text' => '💵今日汇率💰', 'callback_data' => "todayExchangeRate@@rate"]