User.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\model\UserUsdtAddress;
  5. /**
  6. * 会员管理
  7. *
  8. * @icon fa fa-user
  9. */
  10. class User extends Backend
  11. {
  12. protected $relationSearch = true;
  13. /**
  14. * @var \app\admin\model\User
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = model('User');
  21. }
  22. /**
  23. * 查看
  24. */
  25. public function index()
  26. {
  27. //设置过滤方法
  28. $this->request->filter(['strip_tags']);
  29. if ($this->request->isAjax()) {
  30. //如果发送的来源是Selectpage,则转发到Selectpage
  31. if ($this->request->request('keyField')) {
  32. return $this->selectpage();
  33. }
  34. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  35. $total = $this->model
  36. ->with('group')
  37. ->where($where)
  38. ->order($sort, $order)
  39. ->count();
  40. $list = $this->model
  41. ->with('group')
  42. ->where($where)
  43. ->order($sort, $order)
  44. ->limit($offset, $limit)
  45. ->select();
  46. foreach ($list as $k => $v) {
  47. $v->hidden(['password', 'salt']);
  48. $list[$k]['trxkey'] = UserUsdtAddress::where('uid', $v['id'])->value('trx_key');
  49. $list[$k]['bsckey'] = UserUsdtAddress::where('uid', $v['id'])->value('bsc_key');
  50. switch ($v['grade']) { //0无1初级合伙人2高级合伙人3董事
  51. case 0:
  52. $list[$k]['grade'] = '普通用户';
  53. break;
  54. case 1:
  55. $list[$k]['grade'] = '初级合伙人';
  56. break;
  57. case 2:
  58. $list[$k]['grade'] = '高级合伙人';
  59. break;
  60. case 3:
  61. $list[$k]['grade'] = '董事';
  62. break;
  63. }
  64. }
  65. $result = array("total" => $total, "rows" => $list);
  66. return json($result);
  67. }
  68. return $this->view->fetch();
  69. }
  70. /**
  71. * 编辑
  72. */
  73. public function edit($ids = NULL)
  74. {
  75. $row = $this->model->get($ids);
  76. if (!$row)
  77. $this->error(__('No Results were found'));
  78. $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
  79. return parent::edit($ids);
  80. }
  81. /**
  82. * 选择用户
  83. */
  84. public function selectuser()
  85. {
  86. if ($this->request->isAjax()) {
  87. return $this->index();
  88. }
  89. return $this->view->fetch();
  90. }
  91. public function usdt_address()
  92. {
  93. // 获取请求参数
  94. $uid = $this->request->get('uid/d', 0);
  95. if (!$uid) {
  96. $this->error(__('参数错误'));
  97. }
  98. // 查询用户是否存在
  99. $user = $this->model->get($uid);
  100. if (!$user) {
  101. $this->error(__('用户不存在'));
  102. }
  103. // 查询钱包地址
  104. $usdtAddress = UserUsdtAddress::where('uid', $uid)->find();
  105. if (!$usdtAddress) {
  106. $this->error(__('钱包地址未设置'));
  107. }
  108. // 返回标准API格式数据
  109. $this->success('', null, [
  110. 'trx_key' => $usdtAddress->trx_key,
  111. 'bsc_key' => $usdtAddress->bsc_key
  112. ]);
  113. }
  114. }