Index.php 2.0 KB

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