Admin.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Admin extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function index()
  11. {
  12. $param = input();
  13. $param['page'] = intval($param['page']) <1 ? 1 : $param['page'];
  14. $param['limit'] = intval($param['limit']) <1 ? $this->_pagesize : $param['limit'];
  15. $where=[];
  16. if(!empty($param['wd'])){
  17. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  18. $where['admin_name'] = ['like','%'.$param['wd'].'%'];
  19. }
  20. $order='admin_id desc';
  21. $res = model('Admin')->listData($where,$order,$param['page'],$param['limit']);
  22. $this->assign('list',$res['list']);
  23. $this->assign('total',$res['total']);
  24. $this->assign('page',$res['page']);
  25. $this->assign('limit',$res['limit']);
  26. $param['page'] = '{page}';
  27. $param['limit'] = '{limit}';
  28. $this->assign('admin',$this->_admin);
  29. $this->assign('param',$param);
  30. $this->assign('title','管理员管理');
  31. return $this->fetch('admin@admin/index');
  32. }
  33. public function info()
  34. {
  35. if (Request()->isPost()) {
  36. $param = input('post.');
  37. if(!in_array('index/welcome',$param['admin_auth'])){
  38. $param['admin_auth'][] = 'index/welcome';
  39. }
  40. $validate = \think\Loader::validate('Token');
  41. if(!$validate->check($param)){
  42. return $this->error($validate->getError());
  43. }
  44. $res = model('Admin')->saveData($param);
  45. if($res['code']>1){
  46. return $this->error($res['msg']);
  47. }
  48. return $this->success($res['msg']);
  49. }
  50. $id = input('id');
  51. $where=[];
  52. $where['admin_id'] = ['eq',$id];
  53. $res = model('Admin')->infoData($where);
  54. $this->assign('info',$res['info']);
  55. //权限列表
  56. $menus = @include MAC_ADMIN_COMM . 'auth.php';
  57. foreach($menus as $k1=>$v1){
  58. $all = [];
  59. $cs = [];
  60. $menus[$k1]['ck'] = '';
  61. foreach($v1['sub'] as $k2=>$v2){
  62. $one = $v2['controller'] . '/' . $v2['action'];
  63. $menus[$k1]['sub'][$k2]['url'] = url($one);
  64. $menus[$k1]['sub'][$k2]['ck']= '';
  65. $all[] = $one;
  66. if(strpos(','.$res['info']['admin_auth'],$one)>0){
  67. $cs[] = $one;
  68. $menus[$k1]['sub'][$k2]['ck'] = 'checked';
  69. }
  70. if($k2==11){
  71. $menus[$k1]['sub'][$k2]['ck'] = ' checked readonly="readonly" ';
  72. }
  73. }
  74. if($all == $cs){
  75. $menus[$k1]['ck'] = 'checked';
  76. }
  77. }
  78. $this->assign('menus',$menus);
  79. $this->assign('title','管理员信息');
  80. return $this->fetch('admin@admin/info');
  81. }
  82. public function del()
  83. {
  84. $param = input();
  85. $ids = $param['ids'];
  86. if(!empty($ids)){
  87. $where=[];
  88. $where['admin_id'] = ['in',$ids];
  89. if(!is_array($ids)) {
  90. $ids = explode(',', $ids);
  91. }
  92. if(in_array($this->_admin['admin_id'],$ids)){
  93. return $this->error('禁止删除当前登录账号');
  94. }
  95. $res = model('Admin')->delData($where);
  96. if($res['code']>1){
  97. return $this->error($res['msg']);
  98. }
  99. return $this->success($res['msg']);
  100. }
  101. return $this->error('参数错误');
  102. }
  103. public function field()
  104. {
  105. $param = input();
  106. $ids = $param['ids'];
  107. $col = $param['col'];
  108. $val = $param['val'];
  109. if(!empty($ids) && in_array($col,['admin_status']) && in_array($val,['0','1'])){
  110. $where=[];
  111. $where['admin_id'] = ['in',$ids];
  112. $res = model('Admin')->fieldData($where,$col,$val);
  113. if($res['code']>1){
  114. return $this->error($res['msg']);
  115. }
  116. return $this->success($res['msg']);
  117. }
  118. return $this->error('参数错误');
  119. }
  120. }