auth->id); $res['assets'] = $chabao; $res['chabao_rate'] = $config['chabao_rate']; //茶宝汇率 $res['withdrawal_fee']= $config['withdrawal_fee'];//提现收费 $res['transfes_fee'] = $config['transfer_fee']; //转让手续费比例 $res['transfes_txt'] = $config['transfes_txt']; //转让文字表述 $res['giveaway'] = $config['giveaway']; //赠送手续费比例 $res['giveaway_txt'] = $config['giveaway_txt']; //赠送文字表述 $res['logistics_freight']= $config['logistics_freight']; //物流运费 $res['coin_list'] = [ [ 'coin_name' => '茶宝', 'coin_key' => 'token', 'amount' => $chabao, 'frozen_amount' => $this->auth->frozen_amount //冻结金额 ] ]; $this->success('', $res); } /** * 资产变动明细 * @return void */ public function coinList(LedgerWalletModel $ledgerWalletModel) { $type_id = $this->request->post('query.action'); // 账变类型 $coin_type = $this->request->post('query.coin_type'); // 資金类型 $where = [ 'user_id' => $this->auth->getTokenUserID(), ]; if ($type_id > 0) { $where['action'] = $type_id; } switch ($coin_type){ case 'usdt': $paginator = (new LedgerUsdtChangeModel()); break; case 'power': $paginator = (new LedgerPowerChangeModel()); break; case 'declaration': $paginator = (new LedgerDeclarationChange()); break; case 'etc': $paginator = (new LedgerTokenChangeModel()); break; case 'token': $paginator = (new LedgerTokenChangeModel()); break; case 'smh': $paginator = (new LedgerSmhChangeModel()); break; case 'qubic': $paginator = (new LedgerQubicChangeModel()); break; default: $this->error(__('Invalid parameters')); break; } $res['data'] = $paginator->where($where)->order('id DESC')->paginate($this->pageSize); $res['statusList'] = LedgerWalletModel::getStatusList(); $this->success('',$res); } /** * 资产变动类型 * @return void */ public function coinAction() { $coin_type = $this->request->post('coin_type'); // 資金类型 switch ($coin_type){ case 'smh': $res = (new LedgerSmhChangeModel())->pay_status;//资金变动类型列表 break; case 'qubic': $res = (new LedgerQubicChangeModel())->aciton_name;//资金变动类型列表 break; case 'aleo': $res = (new LedgerTokenChangeModel())->aciton_name;//资金变动类型列表 break; default: $res = Action::getAll($coin_type);//资金变动类型列表 break; } $this->success('',$res); } public function actionGet() { $asset = $this->request->post('type'); // 资产类型 $resp = []; switch ($asset) { case 1: $resp = [ $this->getActionValueText(Action::All), $this->getActionValueText(Action::PowerRentalPower), $this->getActionValueText(Action::PowerDirectAward), $this->getActionValueText(Action::PowerTeamAward), $this->getActionValueText(Action::PowerEqualAward), $this->getActionValueText(Action::PowerBonusAward), $this->getActionValueText(Action::PowerCommunityBonusAward), ]; break; case 2: $resp = [ $this->getActionValueText(Action::All), $this->getActionValueText(Action::UsdtRentalPower), $this->getActionValueText(Action::UsdtGenerateProfit), $this->getActionValueText(Action::UsdtWeightDividend), $this->getActionValueText(Action::UsdtWithdrawCash), $this->getActionValueText(Action::UsdtWithdrawReturn), $this->getActionValueText(Action::UsdtRegBonus), $this->getActionValueText(Action::UsdtCmmunityBonus), ]; break; case 3: $resp = [ $this->getActionValueText(Action::All), $this->getActionValueText(Action::TokenAllocateEtc), ]; break; default: $this->error(__('Invalid parameters')); break; } $this->success('', $resp); } private function getActionValueText(int $action): array { return ['value' => $action, 'text' => Action::getText($action)]; } /** * 茶宝赠送明细 * @return void */ public function chabao() { $this->success('', ['value' => getConfig('chabao_giveaway'), 'text' => getConfig('chabao_giveaway_txt')]); } /** * 茶宝赠送 * @return void */ public function chabaoGift(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $amount = $this->request->post('amount'); // 茶宝 $address = $this->request->post('address'); // 地址 if(empty($amount) || empty($address)){ $this->error(__('Parameter error')); } $real = bcsub($amount, bcmul(getConfig('chabao_giveaway'), $amount, 2), 2) ; // 手续费 // 启动事务 Db::startTrans(); try { $user = $userModel->getByAddress($address); if(empty($user)) throw new Exception(__("赠送用户不存在")); if($user['id'] == $this->auth->id) throw new Exception(__("赠送用户不能是自己")); $chabao = $ledgerWalletModel::getWalletChaBao($this->auth->id); if(bccomp($amount, $chabao, 2) > 0) throw new Exception(__("余额不足请前往充值"), 15001); // 更新USDT和账变 $ledgerWalletModel->changeWalletAccount($this->auth->id, Asset::TOKEN, -$amount, $ledgerWalletModel::GiftPay); $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $real, $ledgerWalletModel::GiftReceipt); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage(), null, $e->getCode()); } $this->success('ok'); } /** * 虚拟币明细 * @return void */ public function tokenList() { $type = $this->request->post('query.action'); // 账变类型 $where = [ 'user_id' => $this->auth->getTokenUserID(), ]; if ($type != Action::All) { $where['action'] = $type; } $paginator = (new LedgerTokenChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize); $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items())); } /** * 提现自动打款回调 * 接口回调信息格式: * * @return void */ public function withdrawCallback_my() { //post 获取过来的数据格式为:{"code":"1","data":{"orderNo":"1768","tx_hash":"xx4545"}} $parems = $this->request->post(); Log::write('提现自动打款回调参数:','info'); Log::info(json_encode($parems)); if(empty($parems)){ $this->error("回调参数为空"); } if($parems['code'] != 1){ $this->error("本次提现失败"); } $rs_data = $parems['data']; $info = (new OfflineWithdrawRecordModel()) ->where('id', $rs_data['orderNo']) ->find(); if(empty($info)){ $this->error("当前提现信息不存在"); } if($info['status'] == 2){ $this->success("更新成功"); } if($info['status'] == 5){ $is_update = (new OfflineWithdrawRecordModel()) ->where('id', $info['id']) ->update([ 'tx_hash' => $rs_data['tx_hash'], 'status' => 2, 'update_time' => time(), ]); if($is_update){ $this->success("更新成功"); }else{ $this->error("更新失败"); } } } /** * 提现自动打款回调 * 接口回调信息格式: * companyWithdrawId=126&sign=8e3c6aee53e3ea4ff974c1d80f4e8beb&status=1&txId=0x39ce05a0698ff2b7459ca707703fd48937dd958422d98ebade6b4f5188b70995 * @return void */ public function withdrawCallback() { // $body1 = file_get_contents("php://input"); // Log::write('提现自动打款回调1:' . $body1, 'info'); // // $body = $this->request->post(); $body = file_get_contents("php://input"); //$body = 'companyWithdrawId=126&sign=8e3c6aee53e3ea4ff974c1d80f4e8beb&status=1&txId=0x39ce05a0698ff2b7459ca707703fd48937dd958422d98ebade6b4f5188b70995'; Log::write('提现自动打款回调:' . $body, 'info'); if(empty($body)){ return; } $parems = explode('&', $body); $req_arr = []; foreach ($parems as $item){ $temp = explode('=', $item); $req_arr[$temp[0]] = $temp[1]; } Log::write('提现自动打款回调参数:','info'); Log::info(json_encode($req_arr)); $info = (new OfflineWithdrawRecordModel()) ->where('id', $req_arr['companyWithdrawId']) ->find(); if(empty($info)){ $this->error("当前提现信息不存在"); } if($info['status'] == OfflineWithdrawRecordModel::StatusSuccessAuto){ $this->success("更新成功"); } if($info['status'] == OfflineWithdrawRecordModel::StatusConfirm){ $is_update = (new OfflineWithdrawRecordModel()) ->where('id', $req_arr['companyWithdrawId']) ->update([ 'tx_hash' => $req_arr['txId'], 'status' => OfflineWithdrawRecordModel::StatusSuccessAuto, 'update_time' => time(), ]); if($is_update){ $this->success("更新成功"); }else{ $this->error("更新失败"); } } } // 获取充值地址 public function getAddress() { return $this->success('', ['value'=> Env::get('rental.pay_address'), 'name'=>getConfig('recharge_txt')]); } }