User.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. /**
  5. * 会员管理
  6. *
  7. * @icon fa fa-user
  8. */
  9. class User extends Backend
  10. {
  11. protected $relationSearch = true;
  12. /**
  13. * User模型对象
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = model('User');
  20. }
  21. /**
  22. * 查看
  23. */
  24. public function index()
  25. {
  26. //设置过滤方法
  27. $this->request->filter(['strip_tags']);
  28. if ($this->request->isAjax())
  29. {
  30. //如果发送的来源是Selectpage,则转发到Selectpage
  31. if ($this->request->request('keyField'))
  32. {
  33. return $this->selectpage();
  34. }
  35. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  36. $total = $this->model
  37. ->with('group')
  38. ->where($where)
  39. ->order($sort, $order)
  40. ->count();
  41. $list = $this->model
  42. ->with('group')
  43. ->where($where)
  44. ->order($sort, $order)
  45. ->limit($offset, $limit)
  46. ->select();
  47. foreach ($list as $k => $v)
  48. {
  49. $v->hidden(['password', 'salt']);
  50. }
  51. $result = array("total" => $total, "rows" => $list);
  52. return json($result);
  53. }
  54. return $this->view->fetch();
  55. }
  56. /**
  57. * 编辑
  58. */
  59. public function edit($ids = NULL)
  60. {
  61. $row = $this->model->get($ids);
  62. if (!$row)
  63. $this->error(__('No Results were found'));
  64. $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
  65. return parent::edit($ids);
  66. }
  67. }