| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace app\admin\controller\offline;
- use app\common\controller\Backend;
- use app\common\logic\BscApi;
- use app\common\logic\KangApi;
- use app\common\logic\MyBscApi;
- use app\common\model\LedgerWalletModel;
- use app\common\model\OfflineWithdrawRecordModel;
- use app\common\model\UserModel;
- use Exception;
- use fast\Action;
- use fast\Asset;
- use fast\WithdrawStatus;
- use think\Cache;
- use think\Db;
- use think\Env;
- use think\exception\DbException;
- use think\Model;
- use app\api\controller\Offline as OfflineApi;
- use think\Lang;
- use think\response\Json;
- /**
- * 提现记录管理
- *
- * @icon fa fa-circle-o
- */
- class OfflineWithdraw extends Backend
- {
- /**
- * OfflineWithdrawRecord模型对象
- * @var \app\admin\model\OfflineWithdrawRecord
- */
- protected $model = null;
- protected $urls = null;
- protected $api_key = null;
- protected $api_secret= null;
- protected $address = null;
- protected $bnb_fee = 0.01;//最少手续费
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\OfflineWithdrawRecord;
- $this->address = Env::get('rental.out_address');
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- *
- * @return string|Json
- * @throws \think\Exception
- * @throws DbException
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- $list = $this->model->alias('r')
- ->join('user u','r.user_id=u.id')
- ->where($where)
- ->field('r.*,u.address')
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $k => $v) {
- $list[$k]['address'] = (new UserModel())->getById($v['user_id'])['address'];
- $list[$k]['symbol'] = strtoupper($v['symbol']);
- }
- $result = ['total' => $list->total(), 'rows' => $list->items(), 'total_revenue'=> 669];
- return json($result);
- }
- /**
- * 提现审核
- * @param $ids
- * @return string|void
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function approve($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- $user = (new UserModel())->getById($row['user_id']);
- if(empty($user)){
- $this->error("用户信息不存在");
- }
- if (false === $this->request->isPost()) {
- $row['address'] = !empty($user) ? $user['address'] : "";
- $this->view->assign('row', $row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
-
- $approved = in_array($params['status'], [WithdrawStatus::StatusApprove, WithdrawStatus::StatusManual]); // true:通过 false:拒绝 $params['status'] ==
-
- $update = [
- 'status' => $params['status'],
- 'tx_hash' => $approved ? $params['tx_hash'] : $row['tx_hash'],
- 'update_time' => time(),
- ];
- // 仅处理"待处理"状态的订单,"已抢单"的暂不处理
- $result = (new OfflineWithdrawRecordModel())->where('id', $row['id'])->where('status', OfflineWithdrawRecordModel::StatusDefault)->update($update);
- if (empty($result)) throw new Exception("修改订单状态失败");
-
- // 拒绝时,将提交的金额退回到用户余额里
- if ($params['status'] == OfflineWithdrawRecordModel::StatusReturn) {
- (new LedgerWalletModel())->changeWalletAccount($row['user_id'], Asset::TOKEN, $row['amount'], LedgerWalletModel::Return);
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- //获取余额
- public function getBalance()
- {
- $reqBalance = 0;
- $reqFee = 0;
- $reqAmount = (new OfflineWithdrawRecordModel())->where('status', 'in', '0,5')->sum('real_amount');
- //手续费
- $fee = (new BscApi())->getBnbBalance($this->address);
- if ($fee['code'] == 1) $reqFee = round($fee['data'], 6);
- //Usdt余额
- $balan = (new BscApi)->getTokenBalance($this->address);
- if ($fee['code'] == 1) $reqBalance = round($balan['data'], 6);
- return json(['reqBalance'=>$reqBalance, 'reqFee'=>$reqFee, 'reqAmount'=>$reqAmount]);
- }
- }
|