$v) { foreach($product as $pv) { if ($k == $pv['type']) { $config = $pv; } } $list[] = [ 'label' => lang($v), 'value' => $k, 'config' => $config ?? [], ]; } return $this->success([ 'list' => $list, ]); } /** * 创建代收订单 */ public function createPay() { try { $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], 'payment_type' => ['required', 'string'], ]); $member_id = request()->user->member_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); $qrCode = $res['full_path']; } else { //手动充值 $res = WalletService::getPlatformImageAddress($address); $res['net'] = $params['type']; $qrCode = $res['full_path']; } return $this->success([ 'qrcode' => $qrCode, // 'photo' => InputFile::create($qrCode), ]); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 提交充值凭证 */ 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; $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 = $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 withdrawChannel() { $list = QianBaoService::withdrawChannel(); $data[] = ['label' => 'USDT', 'value' => 'USDT']; foreach ($list as $key => $item) { $data[] = ['label' => $item, 'value' => $key]; } 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()); } } /** * 提现(手动到账): DF001 支付宝转卡; DF002 支付宝转支付宝; DF005数字人民币 */ public function payout() { try { $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], '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,'提交成功'); } return $this->error($res['text']); } catch (ValidationException $e) { return $this->error($e->validator->errors()->first()); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 提现(自动到账): DF001 支付宝转卡/DF002 支付宝转支付宝 */ public function autoPayout() { try { $params = request()->validate([ 'amount' => ['required', 'numeric', 'min:0.01'], 'channel' => ['required', 'string'], 'bank_name' => ['required', 'string'], 'account' => ['required', 'string'], 'card_no' => ['required', 'string'], ]); $member_id = request()->user->member_id; $res = PaymentOrderService::autoCreatePayout($member_id, $params['amount'], $params['channel'], $params['bank_name'], $params['account'], $params['card_no']); 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', 'account' => 'required', 'card_no' => 'required', 'bank_name' => 'required', 'alias' => 'nullable', ]); $member_id = request()->user->member_id; if (!empty($params['id'])) { $info = Bank::where('id', $params['id'])->where('member_id', $member_id)->first(); if (empty($info)) throw new Exception(lang('找不到此记录')); $info->channel = $params['channel']; $info->account = $params['account']; $info->card_no = $params['card_no']; $info->bank_name = $params['bank_name']; $info->alias = $params['alias'] ?? ''; $info->save(); } else { $count = Bank::where('member_id', $member_id)->where('channel', $params['channel'])->count(); if ($count >= 5) throw new Exception(lang('已达添加上限')); Bank::create([ 'member_id' => $member_id, 'channel' => $params['channel'], 'account' => $params['account'], 'card_no' => $params['card_no'], 'bank_name' => $params['bank_name'], 'alias' => $params['alias'] ?? '', ]); } return $this->success([],'提交成功'); } 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; $where = !empty($params['channel']) ? ['channel' => $params['channel']] : []; $list = Bank::where('member_id', $member_id)->where($where)->get()->toArray(); return $this->success([ 'list' => $list, ]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } public function addAddress() { try { $params = request()->validate([ 'id' => 'nullable|integer', 'address' => 'required', 'alias' => 'nullable', ]); $member_id = request()->user->member_id; if (!empty($params['id'])) { $info = Address::where('id', $params['id'])->where('member_id', $member_id)->first(); if (empty($info)) throw new Exception(lang('找不到此记录')); $info->address = $params['address']; $info->alias = $params['alias'] ?? ''; $info->save(); } else { $count = Address::where('member_id', $member_id)->where('address', $params['address'])->count(); if ($count >= 5) throw new Exception(lang('已达添加上限')); Address::create([ 'member_id' => $member_id, 'address' => $params['address'], 'alias' => $params['alias'] ?? '', ]); } return $this->success([],'提交成功'); } 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, ]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }