|
|
@@ -6,10 +6,17 @@ use App\Services\WalletService;
|
|
|
use App\Services\ConfigService;
|
|
|
use App\Models\Config;
|
|
|
use App\Models\Recharge;
|
|
|
+use App\Models\Wallet as WalletModel;
|
|
|
+use App\Models\Withdraw;
|
|
|
+use App\Models\User;
|
|
|
+use App\Services\BalanceLogService;
|
|
|
use App\Services\Payment\SanJinService;
|
|
|
use App\Services\PaymentOrderService;
|
|
|
use App\Services\QianBaoWithdrawService;
|
|
|
use App\Services\Payment\QianBaoService;
|
|
|
+use App\Services\WithdrawService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
|
|
@@ -153,6 +160,71 @@ class Wallet extends BaseController
|
|
|
return $this->success($data);
|
|
|
}
|
|
|
|
|
|
+ public function withdraw()
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $member_id = request()->user->member_id;
|
|
|
+ $params = request()->validate([
|
|
|
+ 'amount' => ['required', 'numeric', 'min:0.01'],
|
|
|
+ 'address' => ['required', 'string'],
|
|
|
+ 'safe_word' => ['required'],
|
|
|
+ ]);
|
|
|
+ $user = User::where('member_id', $member_id)->first();
|
|
|
+ if (empty($user->payment_password)) throw new Exception(lang("请先设置资金密码"));
|
|
|
+ //校验资金密码
|
|
|
+ if (!password_verify($params['safe_word'], $user->payment_password)) {
|
|
|
+ throw new Exception(lang('资金密码错误'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $serviceCharge = (new WithdrawService())->serviceCharge;
|
|
|
+ $amount = $params['amount'];
|
|
|
+ $address = $params['address'];
|
|
|
+ $real = bcsub($amount, $serviceCharge, 10);
|
|
|
+ $real = floatval($real);
|
|
|
+
|
|
|
+ if ($amount <= $serviceCharge) {
|
|
|
+ throw new Exception(lang("提现不能少于") . "{$serviceCharge} USDT");
|
|
|
+ }
|
|
|
+
|
|
|
+ $wallet = WalletModel::where('member_id', $member_id)->first();
|
|
|
+ $temp = floatval($wallet->available_balance);
|
|
|
+ // 汇率
|
|
|
+ $rate = Config::where('field', 'exchange_rate_rmb')->first()->val ?? 1;
|
|
|
+ $exchange_rate_difference = Config::where('field', 'exchange_rate_difference')->first()->val ?? 0;
|
|
|
+ $rate = bcadd($rate, $exchange_rate_difference, 2);
|
|
|
+
|
|
|
+ $rate_usdt_amount = bcdiv($temp, $rate, 2); // 钱包可用余额 折合USDT
|
|
|
+ $rate_rmb_amount = bcmul($amount, $rate, 2); // 提现金额 折合RMB
|
|
|
+ if ($amount > $rate_usdt_amount) {
|
|
|
+ throw new Exception(lang("余额不足") . "{$serviceCharge} USDT");
|
|
|
+ }
|
|
|
+ $wallet = WalletModel::where('member_id', $member_id)->first();
|
|
|
+ $changeAmount = bcmul(($amount * -1), $rate, 2);
|
|
|
+ $beforeBalance = $wallet->available_balance;
|
|
|
+ $afterBalance = bcsub($wallet->available_balance, $rate_rmb_amount, 2);
|
|
|
+ $wallet->available_balance = $afterBalance;
|
|
|
+ $wallet->save();
|
|
|
+
|
|
|
+ $withdraw = Withdraw::create([
|
|
|
+ 'member_id' => $member_id,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'service_charge' => $serviceCharge,
|
|
|
+ 'to_account' => $real,
|
|
|
+ 'address' => $address,
|
|
|
+ 'exchange_rate' => $rate,
|
|
|
+ 'status' => 0,
|
|
|
+ 'after_balance' => $afterBalance
|
|
|
+ ]);
|
|
|
+ BalanceLogService::addLog($member_id, $changeAmount, $beforeBalance, $afterBalance, '提现', $withdraw->id, '');
|
|
|
+ return $this->success($withdraw,'提交成功');
|
|
|
+
|
|
|
+ } catch (ValidationException $e) {
|
|
|
+ return $this->error($e->validator->errors()->first());
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -162,12 +234,20 @@ class Wallet extends BaseController
|
|
|
try {
|
|
|
$params = request()->validate([
|
|
|
'amount' => ['required', 'numeric', 'min:0.01'],
|
|
|
- 'channel' => ['required', 'string'],
|
|
|
+ 'channel' => ['required', 'string', 'in:DF001,DF002,DF005'],
|
|
|
'bank_name' => ['required', 'string'],
|
|
|
'account' => ['required', 'string'],
|
|
|
'card_no' => ['required', 'string'],
|
|
|
+ 'safe_word' => ['required'],
|
|
|
]);
|
|
|
$member_id = request()->user->member_id;
|
|
|
+ $user = User::where('member_id', $member_id)->first();
|
|
|
+ if (empty($user->payment_password)) throw new Exception(lang("请先设置资金密码"));
|
|
|
+ //校验资金密码
|
|
|
+ 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,'提交成功');
|