User.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\model\LedgerWalletModel;
  5. use app\common\model\LedgerTokenChangeModel;
  6. use app\common\model\LedgerFrozenChangeModel;
  7. use Exception;
  8. use fast\GoogleAuthenticator;
  9. use fast\Asset;
  10. use fast\Common;
  11. use app\common\model\LedgerTeacChangeModel;
  12. use think\Db;
  13. use think\exception\DbException;
  14. /**
  15. * 用户管理
  16. *
  17. * @icon fa fa-user
  18. */
  19. class User extends Backend
  20. {
  21. /**
  22. * User模型对象
  23. * @var \app\admin\model\User
  24. */
  25. protected $model = null;
  26. protected $multiFields = ['is_login','is_withdraw'];
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. $this->model = new \app\admin\model\User;
  31. $this->view->assign("statusList", $this->model->getStatusList());
  32. }
  33. /**
  34. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  35. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  36. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  37. */
  38. /**
  39. * 查看
  40. *
  41. * @return string|Json
  42. * @throws \think\Exception
  43. * @throws DbException
  44. */
  45. public function index()
  46. {
  47. //设置过滤方法
  48. $this->request->filter(['strip_tags', 'trim']);
  49. if (false === $this->request->isAjax()) {
  50. return $this->view->fetch();
  51. }
  52. //如果发送的来源是 Selectpage,则转发到 Selectpage
  53. if ($this->request->request('keyField')) {
  54. return $this->selectpage();
  55. }
  56. [$where, $sort, $order, $offset, $limit] = $this->buildparams();
  57. $list = $this->model->with('ledgerWallet')->where($where)->order($sort, $order)->paginate($limit);
  58. $result = ['total' => $list->total(), 'rows' => $list->items()];
  59. return json($result);
  60. }
  61. /**
  62. * 茶宝调整
  63. * @param $ids
  64. * @return string
  65. * @throws DbException
  66. * @throws \think\Exception
  67. */
  68. public function approve($ids = null)
  69. {
  70. $ids = intval($ids);
  71. $row = $this->model->get($ids);
  72. if (!$row) {
  73. $this->error(__('No Results were found'));
  74. }
  75. $adminIds = $this->getDataLimitAdminIds();
  76. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  77. $this->error(__('You have no permission'));
  78. }
  79. if (false === $this->request->isPost()) {
  80. $wallet = (new LedgerWalletModel())->get($ids);
  81. $row['token'] = $wallet['token'] ?? "-";
  82. $row['frozen'] = $wallet['frozen'] ?? "-";
  83. $row['teac'] = $wallet['teac'] ?? "-";
  84. //$google=new GoogleAuthenticator();
  85. //生成验证秘钥
  86. //$secret=$google->createSecret();
  87. //$qrCodeUrl = $google->getQRCodeGoogleUrl('RWACHA', config('google_secret'));
  88. $this->view->assign('row', $row);
  89. return $this->view->fetch();
  90. }
  91. $params = $this->request->post('row/a');
  92. if (empty($params)) {
  93. $this->error(__('Parameter %s can not be empty', ''));
  94. }
  95. $params = $this->preExcludeFields($params);
  96. $google=new GoogleAuthenticator();
  97. $checkResult = $google->verifyCode(config('google_secret'), $params['code'], 6);
  98. if (!$checkResult) $this->error('谷歌验证码错误');
  99. //资金
  100. $newPower = bcadd($params['new_power'], 0, 6);
  101. // 启动事务
  102. Db::startTrans();
  103. try {
  104. // 更新资金
  105. if (bccomp($newPower, 0, 6) !== 0) {
  106. if (empty($params['type_id'])) {
  107. (new LedgerWalletModel)->changeWalletAccount($ids, Asset::TOKEN, $newPower, LedgerTokenChangeModel::System);
  108. }elseif($params['type_id'] == 1){
  109. (new LedgerWalletModel)->changeWalletAccount($ids, Asset::FROZEN, $newPower, LedgerFrozenChangeModel::System);
  110. }else{
  111. (new LedgerWalletModel)->changeWalletAccount($ids, Asset::TEAC, $newPower, LedgerTeacChangeModel::System);
  112. }
  113. }
  114. // 提交事务
  115. Db::commit();
  116. } catch (Exception $e) {
  117. // 回滚事务
  118. Db::rollback();
  119. $this->error('调整失败:' . $e->getMessage());
  120. }
  121. $this->success('调整成功');
  122. }
  123. //搜索条件
  124. private function _where(array $filter): array
  125. {
  126. $map = [];
  127. $pid = 0;
  128. $algebra = 0;
  129. if (isset($filter['id'])) $map['a.id'] = ['=', $filter['id']];
  130. if (isset($filter['address'])) $map['a.address'] = ['like', $filter['address']];
  131. if (isset($filter['parent_id'])) $map['parent_id'] = ['=', $filter['parent_id']];
  132. if (isset($filter['create_time'])) {
  133. $arr = explode(' - ', $filter['create_time']);
  134. $map['a.create_time']= ['between time',[$arr[0], $arr[1]]];
  135. }
  136. //团队等级
  137. if (isset($filter['team_level_id'])) $map['a.team_level_id'] = ['=', $filter['team_level_id']];
  138. //人数
  139. if (isset($filter['team_num'])) $map['a.team_num'] = ['=', $filter['team_num']];
  140. //直推
  141. if (isset($filter['direct_num'])) $map['a.direct_num'] = ['=', $filter['direct_num']];
  142. //代数
  143. if(isset($filter['parent_id'])) {
  144. if(isset($filter['algebra']) && $filter['algebra'] > 0){
  145. $pid = $filter['parent_id'];
  146. $algebra = $filter['algebra'];
  147. }else{
  148. $pid = $filter['parent_id'];
  149. $algebra = -1;
  150. }
  151. }
  152. return [$map, $pid, $algebra];
  153. }
  154. }