User.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\common\library\Auth;
  5. use think\response\Json;
  6. /**
  7. * 会员管理
  8. *
  9. * @icon fa fa-user
  10. */
  11. class User extends Backend
  12. {
  13. protected $relationSearch = true;
  14. protected $searchFields = 'id,username,nickname';
  15. /**
  16. * @var \app\admin\model\User
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = model('User');
  23. }
  24. /**
  25. * 查看
  26. */
  27. public function index()
  28. {
  29. //设置过滤方法
  30. $this->request->filter(['strip_tags', 'trim']);
  31. if ($this->request->isAjax()) {
  32. //如果发送的来源是Selectpage,则转发到Selectpage
  33. if ($this->request->request('keyField')) {
  34. $data = $this->selectpage()->getData();
  35. if(!$this->request->request('keyValue'))
  36. $data['list'] = array_merge([['id'=>0,'nickname'=>'无','pid'=>0]],$data['list']);
  37. $data['total'] ++;
  38. return $data;
  39. }
  40. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. /**
  42. * 获取企业信息
  43. */
  44. $where1 = is_sys_admin('user');
  45. $list = $this->model
  46. ->with('group')
  47. ->where($where)->where($where1)
  48. ->order($sort, $order)
  49. ->paginate($limit);
  50. foreach ($list as $k => $v) {
  51. $v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
  52. $v->hidden(['password', 'salt']);
  53. }
  54. $result = array("total" => $list->total(), "rows" => $list->items());
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 添加
  61. */
  62. public function add()
  63. {
  64. if ($this->request->isPost()) {
  65. $this->token();
  66. }
  67. return parent::add();
  68. }
  69. /**
  70. * 编辑
  71. */
  72. public function edit($ids = null)
  73. {
  74. if ($this->request->isPost()) {
  75. $this->token();
  76. }
  77. $row = $this->model->get($ids);
  78. $this->modelValidate = true;
  79. if (!$row) {
  80. $this->error(__('No Results were found'));
  81. }
  82. $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
  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. }