User.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * @var \app\admin\model\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. //如果发送的来源是Selectpage,则转发到Selectpage
  30. if ($this->request->request('keyField')) {
  31. return $this->selectpage();
  32. }
  33. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  34. $total = $this->model
  35. ->with('group')
  36. ->where($where)
  37. ->order($sort, $order)
  38. ->count();
  39. $list = $this->model
  40. ->with('group')
  41. ->where($where)
  42. ->order($sort, $order)
  43. ->limit($offset, $limit)
  44. ->select();
  45. foreach ($list as $k => $v) {
  46. $v->hidden(['password', 'salt']);
  47. }
  48. $result = array("total" => $total, "rows" => $list);
  49. return json($result);
  50. }
  51. return $this->view->fetch();
  52. }
  53. /**
  54. * 编辑
  55. */
  56. public function edit($ids = NULL)
  57. {
  58. $row = $this->model->get(['id'=>$ids]);
  59. if (!$row)
  60. $this->error(__('No Results were found'));
  61. $this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
  62. return parent::edit(['id'=>$ids]);
  63. }
  64. }