ManagerController.class.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Admin\Controller;
  3. use Common\Controller\AdminController;
  4. class ManagerController extends AdminController {
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. public function index(){
  9. $keyword = I('get.keyword','');
  10. $condition = array();
  11. if (!empty($keyword)){
  12. $condition['admin_account'] = array('LIKE','%'.$keyword.'%');
  13. $this->assign('keyword',$keyword);
  14. }
  15. $count = M('Admin')->where($condition)->count();
  16. //分页
  17. $Page = new \Think\Page($count);
  18. $show = $Page->show();
  19. $userList = M('Admin')->where($condition)->field()->order('admin_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
  20. $this->assign('page',$show);
  21. $this->assign('list',$userList);
  22. $this->display();
  23. }
  24. public function edit(){
  25. $step = I('step','');
  26. if (empty($step)){
  27. $this->display();
  28. }else if($step==2){
  29. $adminAccount = I('admin_account');
  30. $newPwd = I('new_pwd');
  31. $newRepwd = I('new_repwd');
  32. $groupId = I('group_id');
  33. if (mb_strlen($adminAccount,'UTF8')<6 || mb_strlen($adminAccount,'UTF8')>20){
  34. $this->error('用户名长度6到20之间');
  35. }
  36. if (mb_strlen($newPwd,'UTF8')<6 || mb_strlen($newPwd,'UTF8')>20){
  37. $this->error('新密码长度6到20之间');
  38. }
  39. if ($newPwd!==$newRepwd){
  40. $this->error('两次输入的新密码不一致,请重新输入');
  41. }
  42. $info = M('Admin')->where(array('admin_account'=>$adminAccount))->field('admin_id')->find();
  43. if ($info!=NULL){
  44. $this->error('用户名已经存在');
  45. }
  46. $saveData = array(
  47. 'admin_account'=>$adminAccount,
  48. 'admin_pwd'=>md5($newPwd),
  49. 'group_id'=>$groupId,
  50. 'operate_dt'=>time(),
  51. );
  52. M('Admin')->add($saveData);
  53. $this->success('创建账号成功','/admin/manager/index');
  54. }
  55. }
  56. public function del(){
  57. $adminId = I('admin_id');
  58. M('Admin')->where(array('admin_id'=>$adminId))->delete();
  59. $this->success('删除成功','/admin/manager/index');
  60. }
  61. }