Identity.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller\user;
  3. use Exception;
  4. use ba\Random;
  5. use think\facade\Db;
  6. use app\common\controller\Backend;
  7. use app\admin\model\User as UserModel;
  8. use think\db\exception\PDOException;
  9. use think\exception\ValidateException;
  10. class Identity extends Backend
  11. {
  12. protected $model = null;
  13. protected $withJoinTable = ['group'];
  14. // 排除字段
  15. protected $preExcludeFields = ['lastlogintime', 'loginfailure', 'password', 'salt', 'money', 'score'];
  16. protected $quickSearchField = ['username', 'nickname', 'id'];
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. $this->model = new UserModel();
  21. }
  22. /**
  23. * 查看
  24. */
  25. public function index()
  26. {
  27. $this->request->filter(['strip_tags', 'trim']);
  28. // if ($this->request->param('select')) {
  29. // $this->select();
  30. // }
  31. list($where, $alias, $limit, $order) = $this->queryBuilder();
  32. $res = $this->model
  33. ->withoutField('password,salt')
  34. ->withJoin($this->withJoinTable, $this->withJoinType)
  35. ->alias($alias)
  36. ->where($where)
  37. ->where(['real_name_status' => [0, 2]])
  38. ->order($order)
  39. ->paginate($limit);
  40. // var_dump($res);
  41. $this->success('', [
  42. 'list' => $res->items(),
  43. 'total' => $res->total(),
  44. 'remark' => get_route_remark(),
  45. ]);
  46. }
  47. public function edit($id = null)
  48. {
  49. $row = $this->model->find($id);
  50. if (!$row) {
  51. $this->error(__('Record not found'));
  52. }
  53. // 重构:不需要修改密码,所以不需要这个字段
  54. // $row->password = '';
  55. if ($this->request->isPost()) {
  56. $password = $this->request->post('password', '');
  57. if ($password) {
  58. $this->model->resetPassword($id, $password);
  59. }
  60. parent::edit();
  61. }
  62. unset($row->salt);
  63. $row->password = '';
  64. $this->success('', [
  65. 'row' => $row
  66. ]);
  67. }
  68. /**
  69. * 重写select
  70. */
  71. // public function select()
  72. // {
  73. // $this->request->filter(['strip_tags', 'trim']);
  74. //
  75. // list($where, $alias, $limit, $order) = $this->queryBuilder();
  76. // $res = $this->model
  77. // ->withJoin($this->withJoinTable, $this->withJoinType)
  78. // ->alias($alias)
  79. // // ->where($where)
  80. // ->where(['real_name_status' => 1])
  81. // ->order($order)
  82. // ->paginate($limit);
  83. // // var_dump($res);die;
  84. // foreach ($res as $re) {
  85. // $re->nickname_text = $re->username . '(ID:' . $re->id . ')';
  86. // }
  87. //
  88. // $this->success('', [
  89. // 'list' => $res->items(),
  90. // 'total' => $res->total(),
  91. // 'remark' => get_route_remark(),
  92. // ]);
  93. // }
  94. }