| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- namespace app\api\controller;
- use app\admin\model\LedgerDeclarationChange;
- use app\common\controller\Api;
- use app\common\model\LedgerPowerChangeModel;
- use app\common\model\LedgerQubicChangeModel;
- use app\common\model\LedgerServersPowerChangeModel;
- use app\common\model\LedgerSmhChangeModel;
- use app\common\model\LedgerTokenChangeModel;
- use app\common\model\LedgerUsdtChangeModel;
- use app\common\model\LedgerWalletModel;
- use app\common\model\OfflineWithdrawRecordModel;
- use fast\Action;
- use think\Log;
- use think\Env;
- /**
- * 首页接口
- */
- class Ledger extends Api
- {
- protected array $noNeedLogin = ['withdrawCallback'];
- /**
- * 资产首页
- */
- public function assets()
- {
- $chabao = LedgerWalletModel::getWalletChaBao($this->auth->id);
- $res['assets'] = $chabao;
- $res['chabao_rate'] = getConfig('chabao_rate'); //茶宝汇率
- $res['withdrawal_fee']= getConfig('withdrawal_fee');//提现收费
- $res['transfes_fee'] = getConfig('transfer_fee'); //转让手续费比例
- $res['transfes_txt'] = config('transfes_txt'); //转让文字表述
- $res['giveaway'] = getConfig('giveaway'); //赠送手续费比例
- $res['giveaway_txt'] = getConfig('giveaway_txt'); //赠送文字表述
- $res['coin_list'] = [
- [
- 'coin_name' => '茶宝',
- 'coin_key' => 'cha_bao',
- 'amount' => $chabao,
- 'frozen_amount' => $this->auth->frozen_amount //冻结金额
- ]
- ];
- $this->success('', $res);
- }
- /**
- * 资产变动明细
- * @return void
- */
- public function coinList()
- {
- $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 'server':
- // $paginator = (new LedgerServersPowerChangeModel());
- // break;
- case 'declaration':
- $paginator = (new LedgerDeclarationChange());
- break;
- case 'etc':
- $paginator = (new LedgerTokenChangeModel());
- break;
- case 'aleo':
- $paginator = (new LedgerTokenChangeModel());
- break;
- case 'smh':
- $paginator = (new LedgerSmhChangeModel());
- break;
- case 'qubic':
- $paginator = (new LedgerQubicChangeModel());
- break;
- default:
- $this->error(__('Invalid parameters'));
- break;
- }
- $paginator = $paginator->where($where)->order('id DESC')->paginate($this->pageSize);
- foreach ($paginator as $key => $item){
- $paginator[$key]['change_amount'] = round($item['change_amount'], 4);
- $paginator[$key]['present_amount'] = round($item['present_amount'], 4);
- if($coin_type == 'smh'){
- $paginator[$key]['action_name'] = (new LedgerSmhChangeModel())->pay_status[$item['action']];
- }elseif($coin_type == 'qubic'){
- $paginator[$key]['action_name'] = (new LedgerQubicChangeModel())->aciton_name[$item['action']];
- }elseif($coin_type == 'aleo'){
- $paginator[$key]['action_name'] = (new LedgerTokenChangeModel())->aciton_name[$item['action']];
- }else{
- $paginator[$key]['action_name'] = Action::getText($item['action']);
- }
- }
- $res = $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items());
- $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 powerList()
- {
- $type = $this->request->post('query.action'); // 账变类型
- $where = [
- 'user_id' => $this->auth->getTokenUserID(),
- ];
- if ($type != Action::All) {
- $where['action'] = $type;
- }
- $paginator = (new LedgerPowerChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
- $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
- }
- /**
- * USDT明细
- * @return void
- */
- public function usdtList()
- {
- $type = $this->request->post('query.action'); // 账变类型
- $where = [
- 'user_id' => $this->auth->getTokenUserID(),
- ];
- if ($type != Action::All) {
- $where['action'] = $type;
- }
- $paginator = (new LedgerUsdtChangeModel())->where($where)->order('id DESC')->paginate($this->pageSize);
- foreach ($paginator as $key => $item){
- $paginator[$key]['action_name'] = Action::getText($item['action']);
- }
- $this->success('', $this->buildResp($paginator->total(), $paginator->currentPage(), $paginator->items()));
- }
- /**
- * 虚拟币明细
- * @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')]);
- }
- }
|