admins.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class admins extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '管理员列表');
  12. $lists = $this->model()->select()->from('admin')->fetchAll();
  13. $data += array('lists' => $lists);
  14. $this->put('admlist.php', $data);
  15. }
  16. public function save()
  17. {
  18. $data = array();
  19. if (isset($_POST)) {
  20. foreach ($_POST as $key => $val) {
  21. if ($key != 'adminname' && $key != 'adminpass' && $key != 'cirpwd' && $key != 'is_state') {
  22. $data[$key] = $this->req->post($key);
  23. }
  24. }
  25. }
  26. $uname = $this->req->post('adminname');
  27. $upass = $this->req->post('adminpass');
  28. $cirpwd = $this->req->post('cirpwd');
  29. $is_state = $this->req->post('is_state');
  30. $limit_ip = $this->req->post('limit_ip');
  31. $is_limit_ip = $this->req->post('is_limit_ip');
  32. if ($uname == '' || $upass == '' || $cirpwd == '') {
  33. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  34. exit;
  35. }
  36. if ($this->model()->select()->from('admin')->where(array('fields' => 'adminname=?', 'values' => array($uname)))->count()) {
  37. echo json_encode(array('status' => 0, 'msg' => $uname . ' 账号已存在'));
  38. exit;
  39. }
  40. if (strlen($upass) < 6 || strlen($upass) > 20) {
  41. echo json_encode(array('status' => 0, 'msg' => '登录密码长度在6-20位之间'));
  42. exit;
  43. }
  44. if ($upass != $cirpwd) {
  45. echo json_encode(array('status' => 0, 'msg' => '两次输入的密码匹配'));
  46. exit;
  47. }
  48. $data = array('adminname' => $uname, 'adminpass' => sha1($upass), 'is_state' => $is_state, 'limits' => json_encode($data), 'token' => sha1($this->res->getRandomString(40)), 'limit_ip' => $limit_ip, 'is_limit_ip' => $is_limit_ip);
  49. if ($this->model()->from('admin')->insertData($data)->insert()) {
  50. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'admins'));
  51. exit;
  52. }
  53. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  54. exit;
  55. }
  56. public function edit()
  57. {
  58. $data = array('title' => '编辑账号信息');
  59. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  60. $admin = $this->model()->select()->from('admin')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  61. $admin['limits'] = json_decode($admin['limits'], true);
  62. $this->put('admlistedit.php', $data += array('data' => $admin));
  63. }
  64. public function editsave()
  65. {
  66. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  67. $data = array();
  68. if (isset($_POST)) {
  69. foreach ($_POST as $key => $val) {
  70. if ($key != 'adminname' && $key != 'adminpass' && $key != 'cirpwd' && $key != 'is_state') {
  71. $data[$key] = $this->req->post($key);
  72. }
  73. }
  74. }
  75. $upass = $this->req->post('adminpass');
  76. $cirpwd = $this->req->post('cirpwd');
  77. $is_state = $this->req->post('is_state');
  78. $limit_ip = $this->req->post('limit_ip');
  79. $is_limit_ip = $this->req->post('is_limit_ip');
  80. $data = array('is_state' => $is_state, 'limits' => json_encode($data), 'limit_ip' => $limit_ip, 'is_limit_ip' => $is_limit_ip);
  81. if ($upass) {
  82. if (strlen($upass) < 6 || strlen($upass) > 20) {
  83. echo json_encode(array('status' => 0, 'msg' => '登录密码长度在6-20位之间'));
  84. exit;
  85. }
  86. if ($upass != $cirpwd) {
  87. echo json_encode(array('status' => 0, 'msg' => '两次输入的密码匹配'));
  88. exit;
  89. }
  90. $data += array('adminpass' => sha1($upass));
  91. }
  92. if ($this->model()->from('admin')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  93. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'admins'));
  94. exit;
  95. }
  96. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  97. exit;
  98. }
  99. public function del()
  100. {
  101. $id = $this->req->get('id');
  102. if ($id) {
  103. if ($this->model()->from('admin')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  104. echo json_encode(array('status' => 1));
  105. exit;
  106. }
  107. }
  108. echo json_encode(array('status' => 0));
  109. exit;
  110. }
  111. }