User.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Think.Admin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://think.ctolog.com
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/Think.Admin
  12. // +----------------------------------------------------------------------
  13. namespace app\admin\controller;
  14. use controller\BasicAdmin;
  15. use library\Data;
  16. use think\Db;
  17. /**
  18. * 系统用户管理控制器
  19. * Class User
  20. * @package app\admin\controller
  21. * @author Anyon <zoujingli@qq.com>
  22. * @date 2017/02/15 18:12
  23. */
  24. class User extends BasicAdmin {
  25. /**
  26. * 指定当前数据表
  27. * @var string
  28. */
  29. protected $table = 'SystemUser';
  30. /**
  31. * 用户列表
  32. */
  33. public function index() {
  34. $this->title = '系统用户管理';
  35. $db = Db::name($this->table)->where('is_deleted', '0');
  36. parent::_list($db);
  37. }
  38. /**
  39. * 授权管理
  40. * @return type
  41. */
  42. public function auth() {
  43. return $this->_form($this->table, 'auth');
  44. }
  45. /**
  46. * 用户添加
  47. */
  48. public function add() {
  49. return $this->_form($this->table, 'form');
  50. }
  51. /**
  52. * 用户编辑
  53. */
  54. public function edit() {
  55. return $this->add();
  56. }
  57. /**
  58. * 用户密码修改
  59. */
  60. public function pass() {
  61. if (in_array('10000', explode(',', $this->request->post('id')))) {
  62. $this->error('系统超级账号禁止操作!');
  63. }
  64. if ($this->request->isGet()) {
  65. $this->assign('verify', false);
  66. return $this->_form($this->table, 'pass');
  67. }
  68. $data = $this->request->post();
  69. if ($data['password'] !== $data['repassword']) {
  70. $this->error('两次输入的密码不一致!');
  71. }
  72. if (Data::save($this->table, ['id' => $data['id'], 'password' => md5($data['password'])], 'id')) {
  73. $this->success('密码修改成功,下次请使用新密码登录!', '');
  74. } else {
  75. $this->error('密码修改失败,请稍候再试!');
  76. }
  77. }
  78. /**
  79. * 表单数据默认处理
  80. * @param type $data
  81. */
  82. public function _form_filter(&$data) {
  83. if ($this->request->isPost()) {
  84. if (isset($data['authorize']) && is_array($data['authorize'])) {
  85. $data['authorize'] = join(',', $data['authorize']);
  86. }
  87. if (isset($data['id'])) {
  88. unset($data['username']);
  89. } elseif (Db::name($this->table)->where('username', $data['username'])->find()) {
  90. $this->error('用户账号已经存在,请使用其它账号!');
  91. }
  92. } else {
  93. $data['authorize'] = explode(',', isset($data['authorize']) ? $data['authorize'] : '');
  94. $this->assign('authorizes', Db::name('SystemAuth')->select());
  95. }
  96. }
  97. /**
  98. * 删除用户
  99. */
  100. public function del() {
  101. if (in_array('10000', explode(',', $this->request->post('id')))) {
  102. $this->error('系统超级账号禁止删除!');
  103. }
  104. if (Data::update($this->table)) {
  105. $this->success("用户删除成功!", '');
  106. } else {
  107. $this->error("用户删除失败,请稍候再试!");
  108. }
  109. }
  110. /**
  111. * 用户禁用
  112. */
  113. public function forbid() {
  114. if (in_array('10000', explode(',', $this->request->post('id')))) {
  115. $this->error('系统超级账号禁止操作!');
  116. }
  117. if (Data::update($this->table)) {
  118. $this->success("用户禁用成功!", '');
  119. } else {
  120. $this->error("用户禁用失败,请稍候再试!");
  121. }
  122. }
  123. /**
  124. * 用户禁用
  125. */
  126. public function resume() {
  127. if (Data::update($this->table)) {
  128. $this->success("用户启用成功!", '');
  129. } else {
  130. $this->error("用户启用失败,请稍候再试!");
  131. }
  132. }
  133. }