validate(['currency_type' => ['nullable', 'string', 'in:crypto,fiat']], ['currency_type.in' => '充值渠道分类仅支持crypto或fiat']); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first(), [], HttpStatus::CUSTOM_ERROR); } $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; } $list = RechargeChannel::getFormatChannel(1, $recharge_channel_group_id); if (!JdPayService::canUserRecharge(request()->user->id)) { $list = array_values(array_filter($list, function ($item) { return !JdPayService::isChannel($item['value'] ?? ''); })); } if (!NoPayService::canUserRecharge(request()->user->id)) { $list = array_values(array_filter($list, function ($item) { return !NoPayService::isRechargeChannel($item['value'] ?? ''); })); } if (!ZimuPayService::canUserRecharge(request()->user->id)) { $list = array_values(array_filter($list, function ($item) { return !ZimuPayService::isRechargeChannel($item['value'] ?? ''); })); } $currencyType = $params['currency_type'] ?? null; if ($currencyType !== null && $currencyType !== '') { $list = array_values(array_filter($list, static function ($item) use ($currencyType) { return (($item['value'] ?? '') === 'usdt') === ($currencyType === 'crypto'); })); } $list = \App\Services\RechargeBonusService::decorate($list, $this->lang, (int)request()->user->from === 1); return $this->success([ 'list' => $list, ]); } /** * 创建代收订单(自动扫码充值) */ public function createPay() { try { $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], 'payment_type' => ['required', 'string'], ]); if ($params['payment_type'] == 'rgcz') { return $this->error('参数有误'); } $member_id = request()->user->member_id; $user = User::where('member_id', $member_id)->first(); if (JdPayService::isChannel($params['payment_type']) && !JdPayService::canUserRecharge($user->id)) { throw new Exception(lang("不支持此充值方式")); } if (NoPayService::isRechargeChannel($params['payment_type']) && !NoPayService::canUserRecharge($user->id)) { throw new Exception(lang("不支持此充值方式")); } if (ZimuPayService::isRechargeChannel($params['payment_type']) && !ZimuPayService::canUserRecharge($user->id)) { throw new Exception(lang("不支持此充值方式")); } //校验是否支持此充值方式 $check = RechargeChannel::checkRechargeChannel($params['payment_type'], $user->recharge_channel_group_id); if ($check === false) { throw new Exception(lang("不支持此充值方式").$user->recharge_channel_group_id); } $res = PaymentOrderService::createPay($member_id, $params['amount'], $params['payment_type']); if ($res['code'] == 0) { return $this->success($res); } return $this->error($res['text']); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 获取充值二维码(USDT充值) */ public function scan() { try { $member_id = request()->user->member_id; $params = request()->validate([ 'type' => ['required', 'string'], ]); if (strtolower($params['type']) === "trc20") { $address = Config::where('field', 'receiving_address')->first()->val; } elseif (strtolower($params['type']) === "erc20") { $address = Config::where('field', 'receiving_address_erc20')->first()->val; } else { return $this->error(lang('充值类型错误')); } $receivingType = ConfigService::getVal("receiving_type"); //自动充值 if ($receivingType == 1) { $res = WalletService::getRechargeImageAddress($member_id); $address = $res['address']; $qrCode = $res['full_path']; } else { //手动充值 $res = WalletService::getPlatformImageAddress($address); $res['net'] = $params['type']; $qrCode = $res['full_path']; } return $this->success([ 'qrcode' => $qrCode, 'address' => $address, ] + (new UsdtRechargeConfigService())->get()); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 提交充值凭证(USDT手动充值) */ public function recharge() { try { $params = request()->validate([ 'net' => ['required', 'string'], 'amount' => ['required', 'numeric', 'min:0.01'], 'toAddress' => ['required', 'string'], 'image' => ['required', 'url'], ]); $member_id = request()->user->member_id; $user = User::where('member_id', $member_id)->first(); //校验是否支持此充值方式 $check = RechargeChannel::checkRechargeChannel('usdt', $user->recharge_channel_group_id); if ($check === false) { throw new Exception(lang("不支持此充值方式")); } $recharge = new Recharge(); $recharge->member_id = $member_id; $recharge->net = $params['net']; $recharge->coin = "USDT"; $recharge->amount = $params['amount']; $recharge->to_address = $params['toAddress']; $recharge->status = 0; $recharge->type = 2; $recharge->image = Util::replacePartInUrl($params['image']); $recharge->save(); return $this->success($recharge,'提交成功'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getMessage()); } } //支付宝、微信、银行卡手动充值 public function paymentOrder() { try { $member_id = request()->user->member_id; $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], 'payment_type' => ['required', 'integer'], ]); $member_id = request()->user->member_id; $user = User::where('member_id', $member_id)->first(); //校验是否支持此充值方式 $check = RechargeChannel::checkRechargeChannel('rgcz', $user->recharge_channel_group_id); if ($check === false) { throw new Exception(lang("不支持此充值方式")); } $data = []; $data['type'] = PaymentOrderService::TYPE_SELF_PAY; $data['order_no'] = PaymentOrderService::createOrderNo('rgcz_', $member_id); $data['member_id'] = $member_id; $data['fee'] = 0; $data['amount'] = number_format($params['amount'], 2, '.', ''); $data['payment_type'] = $params['payment_type']; $data['channel'] = 'rgcz'; $data['status'] = PaymentOrderService::STATUS_STAY; $data['remark'] = ''; // 创建待处理状态的提现记录 $info = PaymentOrder::create($data); return $this->success($info,'提交成功,请等待人工回复'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getMessage()); } } //支付宝、微信、银行卡手动充值提交图片 public function submitImage() { try { $member_id = request()->user->member_id; $params = request()->validate([ 'id' => ['required', 'integer'], 'image' => ['required', 'url'], ]); // 创建待处理状态的提现记录 $info = PaymentOrder::where('id', $params['id'])->where('member_id', $member_id)->first(); if (!$info) { return $this->error(lang('找不到此记录')); } if ($info->status != PaymentOrderService::STATUS_USER) { return $this->error(lang('待处理中,请稍后')); } $info->image = $params['image']; $info->status = PaymentOrderService::STATUS_AUDIT; $info->save(); return $this->success($info,'提交成功,请等待人工审核'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getMessage()); } } /** * 获取提现通道 */ public function withdrawChannel() { $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; } $list = RechargeChannel::getFormatChannel(2, $recharge_channel_group_id); foreach ($list as &$item) { $channel = $item['value']; $item['requires_real_name'] = true; $item['requires_bank_name'] = WithdrawalDestination::requiresBankName($channel); $item['requires_bank_branch'] = $channel === 'DF001'; if ($channel === 'DF001') { $item['bank_name_label'] = lang('银行名称'); $item['bank_branch_label'] = lang('开户行'); } if ($channel === 'rgtx') { $item['payout_methods'] = []; foreach (WithdrawalDestination::MANUAL_METHODS as $value => $label) { $method = ['value' => $value, 'label' => lang($label), 'requires_bank_name' => $value === 'bank', 'requires_card_no' => $value !== 'wechat', 'requires_bank_branch' => $value === 'bank', 'requires_qr_image' => $value !== 'bank']; if ($value === 'bank') { $method['bank_name_label'] = lang('银行名称'); $method['bank_branch_label'] = lang('开户行'); } $item['payout_methods'][] = $method; } } } return $this->success($list); } //USDT提现 public function withdraw() { $error_code = -1; 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 ($user->from == 2) { throw new Exception(lang("游客不支持提现")); } if (empty($user->payment_password)) { $error_code = 10011; throw new Exception(lang("请先设置资金密码")); } //校验资金密码 if (!password_verify($params['safe_word'], $user->payment_password)) { throw new Exception(lang('资金密码错误')); } WithdrawalName::required($user); //校验是否支持此提现方式 $check = RechargeChannel::checkWithdrawChannel('usdt', $user->recharge_channel_group_id); if ($check === false) { throw new Exception(lang("不支持此提现方式")); } $amount = $params['amount']; $address = $params['address']; //校验提现金额的限制 if ($amount < $check->min || $amount > $check->max) { throw new Exception(lang("提现金额超出限制")); } $serviceCharge = (new WithdrawService())->serviceCharge; $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"); } // 校验打码量 → 可用余额转入冻结余额 → 创建提现单 → 重置打码周期 [$withdraw] = WithdrawFundsService::hold($member_id, $rate_rmb_amount, '提现', '', WithdrawFundsService::WITHDRAWS, fn ($before, $after) => Withdraw::create([ 'member_id' => $member_id, 'amount' => $amount, 'service_charge' => $serviceCharge, 'to_account' => $real, 'address' => $address, 'exchange_rate' => $rate, 'status' => 0, 'after_balance' => $after, ])); return $this->success($withdraw,'提交成功'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage(), [], $error_code); } } /** * 提现(手动到账): DF001 支付宝转卡; DF002 支付宝转支付宝; DF005数字人民币; JDpay JD钱包; NOwithdraw NO钱包; ZIMUwithdraw 808币钱包地址提现;ZIMUcash 808人民币代付; rgtx(人工提现,手动打款) */ public function payout() { $error_code = -1; try { $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], 'channel' => ['required', 'string', 'in:' . WithdrawalName::CHANNELS], 'bank_name' => ['nullable', 'string', 'max:255'], 'bank_branch' => ['nullable', 'string', 'max:255'], 'card_no' => ['nullable', 'string', 'max:255'], 'payout_method' => ['nullable', 'string', 'in:' . implode(',', array_keys(WithdrawalDestination::MANUAL_METHODS))], 'qr_image' => ['nullable', 'string', 'max:255'], 'safe_word' => ['required'], ]); $member_id = request()->user->member_id; $user = User::where('member_id', $member_id)->first(); if ($user->from == 2) { throw new Exception(lang("游客不支持提现")); } if (empty($user->payment_password)) { $error_code = 10011; throw new Exception(lang("请先设置资金密码")); } //校验资金密码 if (!password_verify($params['safe_word'], $user->payment_password)) { throw new Exception(lang('资金密码错误')); } //校验是否支持此提现方式 $check = RechargeChannel::checkWithdrawChannel($params['channel'], $user->recharge_channel_group_id); if ($check === false) { throw new Exception(lang("不支持此提现方式")); } $channel = $params['channel']; $destination = WithdrawalDestination::resolve($channel, $params); $amount = $params['amount']; //校验提现金额的限制 if ($amount < $check->min || $amount > $check->max) { throw new Exception(lang("提现金额超出限制")); } if ($channel === 'rgtx') { try { $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'] = $destination['bank_name']; $data['bank_branch'] = $destination['bank_branch'] ?? null; $data['account'] = WithdrawalName::forPayout($user, $channel); $data['card_no'] = $destination['card_no']; $data['qr_image'] = $destination['qr_image'] ?? null; $data['status'] = PaymentOrderService::STATUS_STAY; // 校验打码量 → 冻结资金 → 创建待处理的提现记录 → 重置打码周期 [$info] = WithdrawFundsService::hold($member_id, $amount, '人工提现', '钱宝提现费率:'.($rate * 100) . '%', WithdrawFundsService::PAYMENT_ORDERS, function () use ($data, $member_id) { $pending = PaymentOrder::where('type', PaymentOrderService::TYPE_SELF_PAYOUT) ->where('member_id', $member_id)->whereIn('status', [0, 1, 4, 5]) ->lockForUpdate()->first(['id']); if ($pending) { throw new Exception(lang('您已有1笔提现订单正常处理中!'), HttpStatus::CUSTOM_ERROR); } return PaymentOrder::create($data); }); } catch (Exception $e) { if ($e->getCode() === HttpStatus::CUSTOM_ERROR) { return $this->error($e->getMessage()); } LogService::error($e); return $this->error('系统繁忙,请稍后重试!'); } return $this->success(array_replace($info->toArray(), WithdrawalDestination::manualResponse( $destination['bank_name'], $destination['card_no'], $destination['qr_image'] ?? null )), '提交成功'); } else { $res = QianBaoWithdrawService::createOrder( $member_id, $params['amount'], $channel, $destination['bank_name'], $destination['card_no'], $destination['bank_branch'] ); if ($res['code'] == 0) { return $this->success($res,'提交成功'); } return $this->error($res['text']); } } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage(), [], $error_code); } } /** * 提现(自动到账): DF001 支付宝转卡/DF002 支付宝转支付宝 */ public function autoPayout() { try { $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], 'channel' => ['required', 'string'], 'bank_name' => ['nullable', 'string', 'max:255'], 'bank_branch' => ['nullable', 'string', 'max:255'], 'card_no' => ['required', 'string', 'max:255'], ]); $member_id = request()->user->member_id; $destination = WithdrawalDestination::resolve($params['channel'], $params); $res = PaymentOrderService::autoCreatePayout( $member_id, $params['amount'], $params['channel'], $destination['bank_name'], $destination['card_no'], $destination['bank_branch'] ?? null ); if (empty($res['text'])) { return $this->success($res,'提交成功'); } return $this->error($res['text']); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getMessage()); } } public function addBank() { try { $params = request()->validate([ 'id' => 'nullable|integer', 'channel' => 'required|string|in:' . WithdrawalName::CHANNELS, 'account' => 'nullable|string', 'card_no' => 'nullable|string|max:255', 'bank_name' => 'nullable|string|max:255', 'bank_branch' => 'nullable|string|max:255', 'payout_method' => 'nullable|string|in:' . implode(',', array_keys(WithdrawalDestination::MANUAL_METHODS)), 'qr_image' => 'nullable|string|max:255', ]); $member_id = request()->user->member_id; $destination = WithdrawalDestination::resolve($params['channel'], $params); $realName = DB::transaction(function () use ($member_id, $params, $destination) { $user = User::where('member_id', $member_id)->lockForUpdate()->firstOrFail(); $accounts = Bank::where('member_id', $member_id); if (!empty($params['id'])) { $info = $accounts->where('id', $params['id'])->lockForUpdate()->first(); if (!$info) throw new Exception(lang('找不到此记录')); } else { if ($accounts->where('channel', $params['channel'])->count() >= 5) { throw new Exception(lang('已达添加上限')); } $info = new Bank(); } $name = WithdrawalName::bind($user, $params['account'] ?? null); if (!$info->fill([ 'member_id' => $member_id, 'channel' => $params['channel'], 'account' => WithdrawalName::usesOrderName($params['channel']) ? $name : '', 'card_no' => $destination['card_no'], 'bank_name' => $destination['bank_name'], 'bank_branch' => $destination['bank_branch'] ?? null, 'qr_image' => $destination['qr_image'] ?? null, ])->save()) { throw new Exception(lang('系统繁忙,请稍后重试!')); } return $user->real_name; }); return $this->success(['real_name' => $realName], '提交成功'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function delBank() { try { $params = request()->validate([ 'id' => 'required|integer', ]); $member_id = request()->user->member_id; $info = Bank::where('id', $params['id'])->where('member_id', $member_id)->first(); if (empty($info)) throw new Exception(lang('找不到此记录')); $info->delete(); return $this->success([],'删除成功'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function bankList() { try { $params = request()->validate([ 'channel' => 'nullable', ]); $member_id = request()->user->member_id; $realName = request()->user->real_name; $where = !empty($params['channel']) ? ['channel' => $params['channel']] : []; $list = Bank::where('member_id', $member_id)->where($where)->get()->toArray(); foreach ($list as &$account) { if (WithdrawalName::usesOrderName($account['channel'])) { $account['account'] = $realName ?? ''; } if ($account['channel'] === 'rgtx') { $account = array_replace($account, WithdrawalDestination::manualResponse( $account['bank_name'], $account['card_no'], $account['qr_image'] ?? null )); } } return $this->success([ 'list' => $list, 'real_name' => $realName, ]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function addAddress() { try { $params = request()->validate([ 'id' => 'nullable|integer', 'address' => 'required|string', 'account' => 'nullable|string', ]); $member_id = request()->user->member_id; $name = DB::transaction(function () use ($member_id, $params) { $user = User::where('member_id', $member_id)->lockForUpdate()->firstOrFail(); $addresses = Address::where('member_id', $member_id); if (!empty($params['id'])) { $info = $addresses->where('id', $params['id'])->lockForUpdate()->first(); if (!$info) throw new Exception(lang('找不到此记录')); } else { if ($addresses->where('address', $params['address'])->count() >= 5) { throw new Exception(lang('已达添加上限')); } $info = new Address(); } $name = WithdrawalName::bind($user, $params['account'] ?? null); if (!$info->fill([ 'member_id' => $member_id, 'address' => $params['address'], ])->save()) { throw new Exception(lang('系统繁忙,请稍后重试!')); } return $name; }); return $this->success(['real_name' => $name], '提交成功'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function delAddress() { try { $params = request()->validate([ 'id' => 'required|integer', ]); $member_id = request()->user->member_id; $info = Address::where('id', $params['id'])->where('member_id', $member_id)->first(); if (empty($info)) throw new Exception(lang('找不到此记录')); $info->delete(); return $this->success([],'删除成功'); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function address() { try { $member_id = request()->user->member_id; $list = Address::where('member_id', $member_id)->get()->toArray(); return $this->success([ 'list' => $list, 'real_name' => request()->user->real_name, ]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }