User.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\library\Auth;
  5. use app\common\Enum\StatusEnum;
  6. use app\common\Enum\UserEnum;
  7. /**
  8. * 会员管理
  9. *
  10. * @icon fa fa-user
  11. */
  12. class User extends Backend
  13. {
  14. protected $relationSearch = true;
  15. protected $searchFields = 'id,username,nickname';
  16. /**
  17. * @var \app\admin\model\User
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\User;
  24. $this->view->assign('statusList', StatusEnum::getMap());
  25. $this->assignconfig('statusList', json_encode(StatusEnum::getMap()));
  26. $this->view->assign('genderList', UserEnum::getGenderMap());
  27. $this->assignconfig('genderList',json_encode(UserEnum::getGenderMap()));
  28. }
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //设置过滤方法
  35. $this->request->filter(['strip_tags', 'trim']);
  36. if ($this->request->isAjax()) {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField')) {
  39. return $this->selectpage();
  40. }
  41. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  42. $list = $this->model
  43. ->with('group')
  44. ->where($where)
  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. // 获取第三方登录信息
  80. $thirdList = $this->model->third()->where('user_id', $ids)->select();
  81. $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
  82. $this->view->assign('thirdList', $thirdList);
  83. return parent::edit($ids);
  84. }
  85. /**
  86. * 删除
  87. */
  88. public function del($ids = "")
  89. {
  90. if (!$this->request->isPost()) {
  91. $this->error(__("Invalid parameters"));
  92. }
  93. $ids = $ids ? $ids : $this->request->post("ids");
  94. $row = $this->model->get($ids);
  95. $this->modelValidate = true;
  96. if (!$row) {
  97. $this->error(__('No Results were found'));
  98. }
  99. Auth::instance()->delete($row['id']);
  100. $this->success();
  101. }
  102. }