|
|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Http\Controllers\api;
|
|
|
|
|
|
use App\Constants\Util;
|
|
|
+use App\Constants\HttpStatus;
|
|
|
use App\Services\WalletService;
|
|
|
use App\Services\ConfigService;
|
|
|
use App\Models\Config;
|
|
|
@@ -17,8 +18,8 @@ use App\Models\PaymentOrder;
|
|
|
use App\Services\BalanceLogService;
|
|
|
use App\Services\PaymentOrderService;
|
|
|
use App\Services\QianBaoWithdrawService;
|
|
|
-use App\Services\Payment\QianBaoService;
|
|
|
use App\Services\WithdrawService;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -41,7 +42,7 @@ class Wallet extends BaseController
|
|
|
} else {
|
|
|
$recharge_channel_group_id = request()->user->recharge_channel_group_id;
|
|
|
}
|
|
|
- $list = RechargeChannel::getFormatChannel($recharge_channel_group_id);
|
|
|
+ $list = RechargeChannel::getFormatChannel(1, $recharge_channel_group_id);
|
|
|
return $this->success([
|
|
|
'list' => $list,
|
|
|
]);
|
|
|
@@ -213,14 +214,17 @@ class Wallet extends BaseController
|
|
|
*/
|
|
|
public function withdrawChannel()
|
|
|
{
|
|
|
- $list = QianBaoService::withdrawChannel();
|
|
|
- $data[] = ['label' => 'USDT', 'value' => 'USDT'];
|
|
|
- foreach ($list as $key => $item) {
|
|
|
- $data[] = ['label' => $item, 'value' => $key];
|
|
|
+ $member_id = request()->user->member_id;
|
|
|
+ if (empty(request()->user->recharge_channel_group_id)) {
|
|
|
+ $recharge_channel_group_id = User::where('member_id', $member_id)->value('recharge_channel_group_id');
|
|
|
+ } else {
|
|
|
+ $recharge_channel_group_id = request()->user->recharge_channel_group_id;
|
|
|
}
|
|
|
- return $this->success($data);
|
|
|
+ $list = RechargeChannel::getFormatChannel(2, $recharge_channel_group_id);
|
|
|
+ return $this->success($list);
|
|
|
}
|
|
|
|
|
|
+ //USDT提现
|
|
|
public function withdraw()
|
|
|
{
|
|
|
try {
|
|
|
@@ -289,13 +293,13 @@ class Wallet extends BaseController
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 提现(手动到账): DF001 支付宝转卡; DF002 支付宝转支付宝; DF005数字人民币
|
|
|
+ * 提现(手动到账): DF001 支付宝转卡; DF002 支付宝转支付宝; DF005数字人民币; rgtx(人工提现,手动打款)
|
|
|
*/
|
|
|
public function payout() {
|
|
|
try {
|
|
|
$params = request()->validate([
|
|
|
'amount' => ['required', 'numeric', 'min:0.01'],
|
|
|
- 'channel' => ['required', 'string', 'in:DF001,DF002,DF005'],
|
|
|
+ 'channel' => ['required', 'string', 'in:DF001,DF002,DF005,rgtx'],
|
|
|
'bank_name' => ['required', 'string'],
|
|
|
'account' => ['required', 'string'],
|
|
|
'card_no' => ['required', 'string'],
|
|
|
@@ -308,12 +312,56 @@ class Wallet extends BaseController
|
|
|
if (!password_verify($params['safe_word'], $user->payment_password)) {
|
|
|
throw new Exception(lang('资金密码错误'));
|
|
|
}
|
|
|
-
|
|
|
- $res = QianBaoWithdrawService::createOrder($member_id, $params['amount'], $params['channel'], $params['bank_name'], $params['account'], $params['card_no']);
|
|
|
- if ($res['code'] == 0) {
|
|
|
- return $this->success($res,'提交成功');
|
|
|
+ if ($params['channel'] == 'rgtx') {
|
|
|
+ DB::beginTransaction();
|
|
|
+ $amount = $params['amount'];
|
|
|
+ try {
|
|
|
+ $wallet = WalletService::findOne(['member_id' => $member_id]);
|
|
|
+ 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);
|
|
|
+
|
|
|
+ $rate = RechargeChannel::where('type', 'rgtx')->value('rate');
|
|
|
+ $rate = $rate ?? 1;
|
|
|
+ $data = [];
|
|
|
+ $data['type'] = PaymentOrderService::TYPE_SELF_PAYOUT;
|
|
|
+ $data['order_no'] = PaymentOrderService::createOrderNo('rgtx' . $data['type'] . '_', $member_id);
|
|
|
+ $data['member_id'] = $member_id;
|
|
|
+ $data['fee'] = $amount * $rate;
|
|
|
+ $data['amount'] = number_format($amount, 2, '.', '');
|
|
|
+ $data['channel'] = $params['channel'];
|
|
|
+ $data['bank_name'] = $params['bank_name'];
|
|
|
+ $data['account'] = $params['account'];
|
|
|
+ $data['card_no'] = $params['card_no'];
|
|
|
+ $data['status'] = PaymentOrderService::STATUS_STAY;
|
|
|
+ // 创建待处理状态的提现记录
|
|
|
+ $info = PaymentOrder::create($data);
|
|
|
+ // 记录余额变动日志
|
|
|
+ BalanceLogService::addLog($member_id, $amount * -1, $balance, $available_balance, '人工提现', $info->id, '钱宝提现费率:'.($rate * 100) . '%');
|
|
|
+
|
|
|
+ $balance = bcadd($available_balance, 0, 2);
|
|
|
+ DB::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ if ($e->getCode() === HttpStatus::CUSTOM_ERROR) {
|
|
|
+ return $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $this->success($info,'提交成功');
|
|
|
+ } else {
|
|
|
+ $res = QianBaoWithdrawService::createOrder($member_id, $params['amount'], $params['channel'], $params['bank_name'], $params['account'], $params['card_no']);
|
|
|
+ if ($res['code'] == 0) {
|
|
|
+ return $this->success($res,'提交成功');
|
|
|
+ }
|
|
|
+ return $this->error($res['text']);
|
|
|
}
|
|
|
- return $this->error($res['text']);
|
|
|
} catch (ValidationException $e) {
|
|
|
return $this->error($e->validator->errors()->first());
|
|
|
} catch (\Exception $e) {
|