|
@@ -2,12 +2,16 @@
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
+use App\Constants\HttpStatus;
|
|
|
use App\Constants\StepStatus;
|
|
use App\Constants\StepStatus;
|
|
|
use App\Models\Bank;
|
|
use App\Models\Bank;
|
|
|
use App\Models\Config;
|
|
use App\Models\Config;
|
|
|
use App\Models\PaymentOrder;
|
|
use App\Models\PaymentOrder;
|
|
|
use App\Models\Wallet;
|
|
use App\Models\Wallet;
|
|
|
|
|
+use App\Services\Payment\QianBaoService;
|
|
|
|
|
+use Exception;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use Telegram\Bot\Api;
|
|
use Telegram\Bot\Api;
|
|
|
use Telegram\Bot\Exceptions\TelegramSDKException;
|
|
use Telegram\Bot\Exceptions\TelegramSDKException;
|
|
|
|
|
|
|
@@ -182,7 +186,7 @@ class QianBaoWithdrawService
|
|
|
$channel = "DF005";
|
|
$channel = "DF005";
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
- $list = Bank::where('member_id',$chatId)->where('channel', $channel)->get();
|
|
|
|
|
|
|
+ $list = Bank::where('member_id', $chatId)->where('channel', $channel)->get();
|
|
|
$keyboard = [];
|
|
$keyboard = [];
|
|
|
foreach ($list as $item) {
|
|
foreach ($list as $item) {
|
|
|
$keyboard[] = [['text' => $item->getAlias(), 'callback_data' => "withdrawAddress@@choose_qb_{$item->getId()}"]];
|
|
$keyboard[] = [['text' => $item->getAlias(), 'callback_data' => "withdrawAddress@@choose_qb_{$item->getId()}"]];
|
|
@@ -379,11 +383,76 @@ class QianBaoWithdrawService
|
|
|
$id = Cache::get("{$chatId}_QB_BANK_ID");
|
|
$id = Cache::get("{$chatId}_QB_BANK_ID");
|
|
|
$bank = Bank::where('id', $id)->first();
|
|
$bank = Bank::where('id', $id)->first();
|
|
|
$amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY");
|
|
$amount = Cache::get("{$chatId}_WITHDRAW_QB_MONEY");
|
|
|
- $res = PaymentOrderService::createPayout($chatId, $amount, $bank->getChannel(), $bank->getBankName(), $bank->getAccount(), $bank->getCardNo());
|
|
|
|
|
|
|
+ $res = static::createOrder($chatId, $amount, $bank->getChannel(), $bank->getBankName(), $bank->getAccount(), $bank->getCardNo());
|
|
|
$res['message_id'] = $messageId;
|
|
$res['message_id'] = $messageId;
|
|
|
return $res;
|
|
return $res;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //创建提现订单
|
|
|
|
|
+ private static function createOrder($memberId, $amount, $channel, $bank_name, $account, $card_no)
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ $result['chat_id'] = $memberId;
|
|
|
|
|
+ $default_amount = $amount;
|
|
|
|
|
+ try {
|
|
|
|
|
+ $wallet = WalletService::findOne(['member_id' => $memberId]);
|
|
|
|
|
+ if (!$wallet) throw new Exception('钱包不存在', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ $balance = $wallet->available_balance;
|
|
|
|
|
+ if (bccomp($balance, $amount, 2) < 0) {
|
|
|
|
|
+ throw new Exception("您的钱包余额不足!", HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ $available_balance = bcsub($balance, $amount, 10);
|
|
|
|
|
+
|
|
|
|
|
+ // 先预扣款(锁定资金)
|
|
|
|
|
+ $wallet->available_balance = $available_balance;
|
|
|
|
|
+ if (!$wallet->save()) throw new Exception('钱包更新失败!', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ $data['type'] = PaymentOrderService::TYPE_PAYOUT;
|
|
|
|
|
+ $data['order_no'] = PaymentOrderService::createOrderNo('sj' . $data['type'] . '_', $memberId);
|
|
|
|
|
+ $data['member_id'] = $memberId;
|
|
|
|
|
+ $data['fee'] = $amount * 0.002 + 2;
|
|
|
|
|
+ $data['amount'] = number_format($amount, 2, '.', '');
|
|
|
|
|
+ $data['channel'] = $channel;
|
|
|
|
|
+ $data['bank_name'] = $bank_name;
|
|
|
|
|
+ $data['account'] = $account;
|
|
|
|
|
+ $data['card_no'] = $card_no;
|
|
|
|
|
+ $data['callback_url'] = QianBaoService::getNotifyUrl();
|
|
|
|
|
+ $data['status'] = PaymentOrderService::STATUS_STAY;
|
|
|
|
|
+ $data['remark'] = '提现费率:0.2%+2';
|
|
|
|
|
+ // 创建待处理状态的提现记录
|
|
|
|
|
+ $info = PaymentOrder::create($data);
|
|
|
|
|
+ // 记录余额变动日志
|
|
|
|
|
+ BalanceLogService::addLog(
|
|
|
|
|
+ $memberId,
|
|
|
|
|
+ $default_amount,
|
|
|
|
|
+ $balance,
|
|
|
|
|
+ $available_balance,
|
|
|
|
|
+ '三方提现',
|
|
|
|
|
+ $info->id,
|
|
|
|
|
+ '钱宝提现费率:0.2%+2'
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $balance = bcadd($available_balance, 0, 2);
|
|
|
|
|
+ $text = "✅ 提现申请已提交!\n\n";
|
|
|
|
|
+ $text .= "钱包余额:{$balance} RMB\n";
|
|
|
|
|
+ $text .= "提现金额:{$default_amount} RMB\n";
|
|
|
|
|
+ $text .= "⌛️请等待系统处理, 到账时间可能需要几分钟!\n";
|
|
|
|
|
+ $result['text'] = $text;
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ } //
|
|
|
|
|
+ catch (Exception $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ $result['text'] = "系统发生了错误,请联系管理员";
|
|
|
|
|
+ if ($e->getCode() === HttpStatus::CUSTOM_ERROR) {
|
|
|
|
|
+ $result['text'] = $e->getMessage();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//银行卡管理
|
|
//银行卡管理
|
|
|
private static function banks($chatId, $messageId, $channel = ""): array
|
|
private static function banks($chatId, $messageId, $channel = ""): array
|
|
|
{
|
|
{
|
|
@@ -546,7 +615,7 @@ class QianBaoWithdrawService
|
|
|
|
|
|
|
|
return [
|
|
return [
|
|
|
'chat_id' => $chatId,
|
|
'chat_id' => $chatId,
|
|
|
- 'text' =>lang("请输入姓名"),
|
|
|
|
|
|
|
+ 'text' => lang("请输入姓名"),
|
|
|
'message_id' => $messageId,
|
|
'message_id' => $messageId,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|