lan = $this->request->getLan(); } /** * 获取用户信息 * @return void */ public function userInfo() { $user = $this->auth->getUser(); $teamLevelName = ''; $teamLevelInfo = (new TeamLevelModel())->get($user['team_level_id']); if (!empty($teamLevelInfo)) { $teamLevelName = $teamLevelInfo->toArray()['name']; } $resp = [ 'id' => $user['id'], 'nickname' => $user['nickname'], 'address' => $user['address'],// 地址 'usdt' => '0', //USDT余额 'token' => '0', // 平台币余额 'name' => $user['name'], // 姓名 'phone' => $user['phone'], // 手机号 'rental_power' => '0', // 自己购买的算力 'team_power' => '0', // 团队总算里 'balance' => LedgerWalletModel::getWalletChaBao($this->auth->id), // 余额 'team_level_id' => $user['team_level_id'], // 团队等级ID 'team_level_name' => $teamLevelName, // 团队等级名称 'parent_id' => $user['parent_id'], // 上级ID 'parent_address' => '', // 上级的地址 'invite_link' => Config::get('rental.invite_domain') . '/?inviteCode=' . $user['address'], ]; $this->success('', $resp); } /** * 获取Nft列表 * @return void */ public function getNftList(ProductOrder $productOrder) { $list = $productOrder->alias('a') ->join("product_list b", "b.id = a.product_id", "left") ->join("products c", "c.id = b.type_id", "left") ->field('a.id as order_id,a.product_id,'.'b.'.$this->lan.'_name,b.images as img_url,a.price,a.status,a.type_id,c.'.$this->lan.'_title') ->where('a.user_id', $this->auth->id) ->order('a.id DESC') ->paginate($this->pageSize); $this->success('', $list); } /** * 余额记录信息 * @return void */ public function getUserBalanceLog(LedgerTokenChangeModel $ledgerTokenChangeModel, LedgerWalletModel $ledgerWalletModel) { // 启动事务 Db::startTrans(); try { $list['total'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id) ->where('action', $ledgerWalletModel::Share) ->sum("change_amount"); $list['data'] = $ledgerTokenChangeModel::where('user_id', $this->auth->id) ->where('action', $ledgerWalletModel::Share) ->order('id desc') ->paginate($this->pageSize); $list['statusList'] = $ledgerWalletModel::getStatusList(); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage()); } $this->success('', $list); } /** * 我的茶友 * @return void */ public function getChaList(UserModel $userModel) { // 总推荐数 $list['total'] = $userModel::where('parent_id', $this->auth->id)->count(); // 直推列表 $list['data'] = $userModel::where('parent_id', $this->auth->id) ->field("address,create_time,nickname, REPLACE(phone, SUBSTRING(phone, 4, 4), '****') as phone") ->order('id desc') ->paginate($this->pageSize); $this->success('', $list); } /** * 修改个人信息 * @return void */ public function setUserInfo(UserModel $userModel) { // 启动事务 Db::startTrans(); try { $param = $this->request->post(); if(!isset($param['name']) && !isset($param['nickname']) && !isset($param['phone'])) throw new Exception(__("Invalid parameters")); $resp = $userModel::where('id', $this->auth->id)->update($param); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error( $e->getMessage()); } $this->success('', $resp); } /** * 报单算力互转 * @return void */ public function declarationTransfer() { $amount = $this->request->post('amount'); // 金额 $sign = $this->request->post('sign'); // 签名信 $address = $this->request->post('address'); // 提现地址 // $sign = 'test'; if(empty($sign)){ $this->error('参数错误'); } $real = $amount; // 实际到账 $min = (new ParametersModel)->getValue('declarationMinAmount') ?? '0'; if ($amount <= 0) { $this->error('互转金额必须大于0'); } else if ($amount < $min) { $this->error('互转金额不能小于' . $min); } $uid = $this->auth->getTokenUserID(); // 用户信息 $from_user = (new UserModel())->getById($uid); if (empty($from_user)) { $this->error('用户不存在'); } $to_user = (new UserModel()) ->where('address', $address) ->find(); if (empty($to_user)) { $this->error('接收用户不存在'); } $wallet = (new LedgerWalletModel())->getWallet($from_user['id']); if (empty($wallet)) { $this->error('用户不存在'); } if($amount > $wallet['declaration']){ $this->error('余额不足'); } // 验签 $signMsg = "DeclarationWithdraw"; // 与前端约定的固定值 if (!checkSign($signMsg, $sign, $from_user['address'])) { $this->error('签名校验失败'); } // 启动事务 Db::startTrans(); try { // 更新USDT和账变 (new LedgerWalletModel())->changeWalletAccount($from_user['id'], Asset::DECLARATION, -$amount, Action::TransferOut); (new LedgerWalletModel())->changeWalletAccount($to_user['id'], Asset::DECLARATION, $amount, Action::TransferIn); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error('提交失败:' . $e->getMessage()); } $this->success('提现申请已提交'); } /** * 获取smh出款信息 * @return void */ public function smhInfo() { $user = $this->auth->getUser(); if (empty($user)) { $this->error('用户信息不存在'); } $resp = [ 'smh' => '0', // 平台币余额 'smh_min_amount' => 0, // 最低提现U数量 'tips' => "", //提现提示信息 'address' => "", // 出款地址,此地址有值时,前台不允许重新输入 'smh_price' => (new SmhWithdrawRecordModel())->getEtcPrice(), //smh价格 'smh_exchange_ratio' => (new ParametersModel())->getValue('smhExchangeRatio'), // smh兑换USDT手续费 'smh_fee_rate' => (new ParametersModel())->getValue('smhFeeRate'), // smh提现手续费 ]; $wallet = (new LedgerWalletModel())->getWallet($user['id']); if (!empty($wallet)) { $resp['smh'] = $wallet['smh']; } $config = (new ParametersModel) ->where('name', '=', 'smhMinAmount') ->find(); if(empty($config)){ $this->error('未配置SMH出款参数'); } $resp['smh_min_amount'] = $config['value']; $resp['tips'] = $config['tip']; $wallet = (new OfflineWithdrawRecordModel()) ->where('user_id', $user['id']) ->where('symbol', 'smh') ->where('status', OfflineWithdrawRecordModel::StatusSuccessHand) ->find(); if (!empty($wallet)) { $resp['address'] = $wallet['to_address']; } $this->success('', $resp); } /** * 提交出款信息 * @return void */ public function smhSubmit() { $amount = $this->request->post('amount'); // 金额 $sign = $this->request->post('sign'); // 签名信 $address = $this->request->post('address'); // 提现地址 // $sign = 'test'; if(empty($sign)){ $this->error('参数错误'); } $real = $amount; // 实际到账 $min = (new ParametersModel)->getValue('smhMinAmount') ?? '0'; if ($amount <= 0) { $this->error('提现金额必须大于0'); } else if ($amount < $min) { $this->error('提现金额不能小于' . $min); } $uid = $this->auth->getTokenUserID(); // 用户信息 $user = (new UserModel())->getById($uid); if (empty($user)) { $this->error('用户不存在'); } $wallet = (new LedgerWalletModel())->getWallet($user['id']); if (empty($wallet)) { $this->error('用户不存在'); } if($amount > $wallet['smh']){ $this->error('SMH余额不足'); } $rate = (new ParametersModel)->getValue('smhFeeRate') ?? '0'; // 扣除手续费后 if ($rate >= 0 && $rate < 1) { // 比例范围只在0-1之间 $real = bcmul($amount, bcsub(1, $rate, 6), 6); }else{ $this->error('手续费设置错误:' . $rate); } // 验签 $signMsg = "EtcWithdraw"; // 与前端约定的固定值 if (!checkSign($signMsg, $sign, $user['address'])) { $this->error('签名校验失败'); } //有过出款记录,则不能修改出款钱包地址 $wallet = (new OfflineWithdrawRecordModel()) ->where('user_id', $user['id']) ->where('symbol', 'smh') ->where('status', OfflineWithdrawRecordModel::StatusSuccessHand) ->find(); if (!empty($wallet)) { $address = $wallet['to_address']; } // 启动事务 Db::startTrans(); try { // 更新USDT和账变 (new LedgerWalletModel())->changeWalletAccount($uid, Asset::SMH, -$amount, LedgerSmhChangeModel::WithdrawCash); // 创建提现记录 $txHash = Random::uuid(); (new OfflineWithdrawRecordModel())->createWithdraw($txHash, $uid, $amount, $real, $address, 'smh'); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error('提交失败:' . $e->getMessage()); } $this->success('提现申请已提交'); } /** * 提交出款信息 * @return void */ public function smhExchange() { $amount = $this->request->post('amount'); // 金额 if($amount < 0.01){ $this->error('兑换数量太少'); } $uid = $this->auth->getTokenUserID(); // 用户信息 $user = (new UserModel())->getById($uid); if (empty($user)) { $this->error('用户不存在'); } $wallet = (new LedgerWalletModel())->getWallet($user['id']); if (empty($wallet)) { $this->error('用户不存在'); } if($amount > $wallet['smh']){ $this->error('SMH余额不足'); } $etc_ratio = (new ParametersModel())->getValue('smhExchangeRatio');//兑换手续费 $etc_price = (new SmhWithdrawRecordModel())->getEtcPrice(); //ETC价格 if($etc_ratio > 0.9){ $this->error('兑换手续费异常'); } $usdt_amount = $amount * $etc_price * (1 - $etc_ratio); // 启动事务 Db::startTrans(); try { // 更新ETC和账变 (new LedgerWalletModel())->changeWalletAccount($uid, Asset::SMH, -$amount, LedgerSmhChangeModel::Exchange); // 更新USDT和账变 (new LedgerWalletModel())->changeWalletAccount($uid, Asset::USDT, $usdt_amount, Action::EtcExchange); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error('提交失败:' . $e->getMessage()); } $this->success('提现申请已提交'); } /** * 获取aleo出款信息 * @return void */ public function aleoInfo() { $user = $this->auth->getUser(); if (empty($user)) { $this->error('用户信息不存在'); } $resp = [ 'aleo' => '0', // 平台币余额 'aleo_min_amount' => 0, // 最低提现U数量 'tips' => "", //提现提示信息 'address' => "", // 出款地址,此地址有值时,前台不允许重新输入 //'smh_price' => (new SmhWithdrawRecordModel())->getEtcPrice(), //smh价格 //'smh_exchange_ratio' => (new ParametersModel())->getValue('smhExchangeRatio'), // smh兑换USDT手续费 'aleo_fee_rate' => (new ParametersModel())->getValue('aleoFeeRate'), // smh提现手续费 ]; $wallet = (new LedgerWalletModel())->getWallet($user['id']); if (!empty($wallet)) { $resp['aleo'] = $wallet['token']; } $config = (new ParametersModel) ->where('name', '=', 'aleoMinAmount') ->find(); if(empty($config)){ $this->error('未配置Aleo出款参数'); } $resp['aleo_min_amount'] = $config['value']; $resp['tips'] = $config['tip']; $wallet = (new OfflineWithdrawRecordModel()) ->where('user_id', $user['id']) ->where('symbol', 'aleo') ->where('status', OfflineWithdrawRecordModel::StatusSuccessHand) ->find(); if (!empty($wallet)) { $resp['address'] = $wallet['to_address']; } $this->success('', $resp); } /** * 提交出款信息 * @return void */ public function aleoSubmit() { $amount = $this->request->post('amount'); // 金额 $sign = $this->request->post('sign'); // 签名信 $address = $this->request->post('address'); // 提现地址 // $sign = 'test'; if(empty($sign)){ $this->error('参数错误'); } $real = $amount; // 实际到账 $min = (new ParametersModel)->getValue('aleoMinAmount') ?? '0'; if ($amount <= 0) { $this->error('提现金额必须大于0'); } else if ($amount < $min) { $this->error('提现金额不能小于' . $min); } $uid = $this->auth->getTokenUserID(); // 用户信息 $user = (new UserModel())->getById($uid); if (empty($user)) { $this->error('用户不存在'); } $wallet = (new LedgerWalletModel())->getWallet($user['id']); if (empty($wallet)) { $this->error('用户不存在'); } if($amount > $wallet['token']){ $this->error('Aleo余额不足'); } $rate = (new ParametersModel)->getValue('aleoFeeRate') ?? '0'; // 扣除手续费后 if ($rate >= 0 && $rate < 1) { // 比例范围只在0-1之间 $real = bcmul($amount, bcsub(1, $rate, 6), 6); }else{ $this->error('手续费设置错误:' . $rate); } // 验签 $signMsg = "EtcWithdraw"; // 与前端约定的固定值 if (!checkSign($signMsg, $sign, $user['address'])) { $this->error('签名校验失败'); } //有过出款记录,则不能修改出款钱包地址 $wallet = (new OfflineWithdrawRecordModel()) ->where('user_id', $user['id']) ->where('symbol', 'aleo') ->where('status', OfflineWithdrawRecordModel::StatusSuccessHand) ->find(); if (!empty($wallet)) { $address = $wallet['to_address']; } // 启动事务 Db::startTrans(); try { // 更新USDT和账变 (new LedgerWalletModel())->changeWalletAccount($uid, Asset::TOKEN, -$amount, LedgerTokenChangeModel::WithdrawCash); // 创建提现记录 $txHash = Random::uuid(); (new OfflineWithdrawRecordModel())->createWithdraw($txHash, $uid, $amount, $real, $address, 'aleo'); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error('提交失败:' . $e->getMessage()); } $this->success('提现申请已提交'); } }