Index.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\user\controller;
  3. use app\base\controller\Base;
  4. use app\user\model\Role;
  5. use app\user\model\RoleRule;
  6. class Index extends Base{
  7. private $adminModel;
  8. public function _initialize(){
  9. parent::_initialize();
  10. $this->adminModel = new \app\user\model\Admin();
  11. }
  12. public function index(){
  13. $p = $this->request->get('page', 0);
  14. $nick = $this->request->get('n');
  15. $where = [];
  16. if($nick) $where['nickname'] = ['like', "%$nick%"];
  17. $info = $this->adminModel->getInfo($p, $where);
  18. $page = $this->adminModel->getPage($where);
  19. $this->assign("info", $info);
  20. $this->assign("page", $page);
  21. return $this->fetch();
  22. }
  23. public function edit(){
  24. $id = $this->request->get('id');
  25. $info = $this->adminModel->getAdminById($id);
  26. $this->assign("info", $info);
  27. return $this->fetch('edit');
  28. }
  29. public function reset(){
  30. $id = $this->request->get('id');
  31. $this->assign("id", $id);
  32. return $this->fetch('reset');
  33. }
  34. public function pass(){
  35. $res = $this->adminModel->resetPwd();
  36. if(is_int($res)){
  37. $this->success('更改成功!', 'index');
  38. }else{
  39. $this->error('更改失败!'.$res);
  40. }
  41. }
  42. public function group(){
  43. $id = $this->request->get('id');
  44. $admin = $this->adminModel->getAdminById($id);
  45. $role = new Role();
  46. $info = $role->getAllRole();
  47. $rule = new RoleRule();
  48. $array = $rule->getRidByAid($id);
  49. $this->assign('array', $array);
  50. $this->assign('admin', $admin);
  51. $this->assign('info', $info);
  52. return $this->fetch();
  53. }
  54. public function rule(){
  55. $info = new RoleRule();
  56. $info->addAndSave();
  57. $this->success('保存成功!', 'index');
  58. }
  59. public function delete(){
  60. $res = $this->adminModel->remove();
  61. if($res){
  62. $this->success('删除成功!', 'index');
  63. }else{
  64. $this->error('删除失败!');
  65. }
  66. }
  67. public function save(){
  68. $res = $this->adminModel->addAndSave();
  69. if($res){
  70. $this->success('保存成功!', 'index');
  71. }else{
  72. $this->error('保存失败!');
  73. }
  74. }
  75. }