getConfig('withdraw_desc'), //提现说明 'usdt' => '0', // 系统余额(U) 'withdraw_min_amount' => getConfig('withdraw_min_amount'), // 最低提现U数量 'withdrawal_next_fee' => getConfig('withdrawal_next_fee'), // 600以下手续费 'withdrawal_up_fee' => getConfig('withdrawal_up_fee') // 600以上手续费比例 ]; $this->success('', $resp); } /** * 提现 * @return void */ public function withdrawCash() { $amount = $this->request->post('amount'); // 金额 $sign = $this->request->post('sign'); // 签名信 $address = $this->request->post('to_address'); // 地址 if(empty($sign) || empty($address)){ $this->error(__('Invalid parameters')); } $min = getConfig('withdraw_min_amount'); if ($amount <= 0) { $this->error(__('The withdrawal amount must be greater than 0')); } else if ($amount < $min) { $this->error(__('The withdrawal amount cannot be less than') . $min); } // 扣除手续费后 $rate = getConfig('convert_rate'); if($amount < config('withdraw_in_amount')){ $feeRate = getConfig('withdrawal_next_fee'); $real = bcsub($amount, $feeRate,6); //扣除茶宝之后金额 $usdt = bcdiv($real, $rate, 6); // 折合转换 U = 1 $fee = $feeRate.'茶宝'; } else{ $feeRate= getConfig('withdrawal_up_fee'); $real = bcmul($amount, bcsub(1, $feeRate, 6), 6); // 折合转换 U = 1 $usdt = bcdiv($real, $rate, 6); // 扣除手续费后 $fee = ($feeRate*100).'%'; } $uid = $this->auth->getTokenUserID(); // 用户信息 $user = (new UserModel())->getById($uid); if($user['is_withdraw']){ $this->error(__('Withdrawal failed, please contact customer service.')); } // 验签 $signMsg = "withdraw"; // 与前端约定的固定值 if (!checkSign($signMsg, $sign, $address)) { $this->error(__('Signature verification failed')); } // 启动事务 Db::startTrans(); try { // 更新USDT和账变 (new LedgerWalletModel())->changeWalletAccount($uid, Asset::TOKEN, -$amount, LedgerTokenChangeModel::Withdraw); // 创建提现记录 $txHash = Random::uuid(); (new OfflineWithdrawRecordModel())->createWithdraw($txHash, $uid, $amount, $real, $address, 'usdt', $usdt, $rate, $fee); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error( $e->getMessage()); } $this->success('ok'); } /** * 提现地址 * @return void */ public function withdrawList() { $where = ['user_id' => $this->auth->getTokenUserID()]; $paginator = (new OfflineWithdrawRecordModel)->where($where)->order('id DESC')->paginate($this->pageSize); $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items())); } /** * 充值记录 * @return void */ public function rechargeList() { $where = ['user_id' => $this->auth->getTokenUserID()]; $paginator = (new OfflineRechargeRecordModel)->where($where)->order('id DESC')->paginate($this->pageSize); $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items())); } /** * 获取签名-带连接符号 * @return string */ protected static function getSignKey(array $arr, string $secretKey)//: string { ksort($arr); $arr['apiSecret'] = $secretKey; $string = ''; foreach ($arr as $key => $value) $string .= '&'.$key .'='.$value; return ltrim($string, '&'); } }