Usererji.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\library\Auth;
  5. /**
  6. * 会员管理
  7. *
  8. * @icon fa fa-user
  9. */
  10. class Usererji extends Backend
  11. {
  12. protected $relationSearch = true;
  13. protected $searchFields = 'id,username,nickname';
  14. /**
  15. * @var \app\admin\model\User
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('User');
  22. }
  23. /**
  24. * 查看
  25. */
  26. public function index()
  27. {
  28. //设置过滤方法
  29. $this->request->filter(['strip_tags', 'trim']);
  30. $parent_id = $this->request->request('parent_id');
  31. if ($this->request->isAjax()) {
  32. //如果发送的来源是Selectpage,则转发到Selectpage
  33. if ($this->request->request('keyField')) {
  34. return $this->selectpage();
  35. }
  36. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  37. if($parent_id > 0) {
  38. $whereExt = [];
  39. $whereExt["pre_userid"] = $parent_id;
  40. }
  41. $list = $this->model
  42. ->with(['noble'])
  43. ->where($where)
  44. ->where($whereExt)
  45. ->order($sort, $order)
  46. ->paginate($limit);
  47. foreach ($list as $k => $v) {
  48. $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
  49. $v->hidden(['password', 'salt']);
  50. }
  51. $result = array("total" => $list->total(), "rows" => $list->items());
  52. return json($result);
  53. }
  54. return $this->view->fetch();
  55. }
  56. /**
  57. * 添加
  58. */
  59. public function add()
  60. {
  61. if ($this->request->isPost()) {
  62. $this->token();
  63. }
  64. return parent::add();
  65. }
  66. /**
  67. * 编辑
  68. */
  69. public function edit($ids = null)
  70. {
  71. if ($this->request->isPost()) {
  72. $this->token();
  73. }
  74. $row = $this->model->get($ids);
  75. $this->modelValidate = true;
  76. if (!$row) {
  77. $this->error(__('No Results were found'));
  78. }
  79. return parent::edit($ids);
  80. }
  81. /**
  82. * 删除
  83. */
  84. public function del($ids = "")
  85. {
  86. if (!$this->request->isPost()) {
  87. $this->error(__("Invalid parameters"));
  88. }
  89. $ids = $ids ? $ids : $this->request->post("ids");
  90. $row = $this->model->get($ids);
  91. $this->modelValidate = true;
  92. if (!$row) {
  93. $this->error(__('No Results were found'));
  94. }
  95. Auth::instance()->delete($row['id']);
  96. $this->success();
  97. }
  98. }