|
|
@@ -0,0 +1,152 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace App\Services;
|
|
|
+
|
|
|
+
|
|
|
+use App\Constants\StepStatus;
|
|
|
+use App\Models\Bank;
|
|
|
+use App\Models\Config;
|
|
|
+use App\Models\Wallet;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
+
|
|
|
+class QianBaoWithdrawService
|
|
|
+{
|
|
|
+ //1.钱宝提现
|
|
|
+ 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.输入钱宝提现金额
|
|
|
+ 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->card_no($item->bank_name)", '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.选择银行卡号
|
|
|
+ static function chooseBank($chatId, $firstName, $messageId, $id)
|
|
|
+ {
|
|
|
+ $amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY", '');
|
|
|
+ if ($amount) return WithdrawService::index($chatId, $firstName, $messageId);
|
|
|
+
|
|
|
+ $bank = Bank::where('id', $id)->first();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @description: 创建代付订单
|
|
|
+ * @param {*} $memberId 会员
|
|
|
+ * @param {*} $amount 金额
|
|
|
+ * @param {*} $channel 提现通道 DF001 支付宝转卡/DF002 支付宝转支付宝
|
|
|
+ * @param {*} $bank_name 银行名称/支付宝
|
|
|
+ * @param {*} $account 姓名
|
|
|
+ * @param {*} $card_no 银行卡号/支付宝账号
|
|
|
+ * @return {*}
|
|
|
+ */
|
|
|
+ $result = PaymentOrderService::createPayout($chatId, $amount, $bank->channel, $bank->bank_name, $bank->account, $bank->card_no);
|
|
|
+ return [
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //银行卡管理
|
|
|
+ static function banks($chatId, $messageId)
|
|
|
+ {
|
|
|
+ $text = "🏠 银行卡管理\n";
|
|
|
+ $text .= "--------------------------\n";
|
|
|
+
|
|
|
+ $list = Bank::where('member_id', $chatId)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ $keyboard = [];
|
|
|
+ foreach ($list as $item) {
|
|
|
+ $keyboard[] = [['text' => "$item->card_no($item->bank_name)", 'callback_data' => "withdrawAddress@@bank_detail{$item->id}"]];
|
|
|
+ }
|
|
|
+ if (count($list) < 5) {
|
|
|
+ $keyboard[] = [['text' => "➕ 添加银行卡", 'callback_data' => "withdrawAddress@@bang_add"]];
|
|
|
+ }
|
|
|
+ $keyboard[] = [['text' => "↩️返回", 'callback_data' => "withdraw@@home"]];
|
|
|
+ return [
|
|
|
+ 'chat_id' => $chatId,
|
|
|
+ 'text' => $text,
|
|
|
+ 'message_id' => $messageId,
|
|
|
+ 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
|
|
|
+ ];
|
|
|
+ }
|
|
|
+}
|