Role.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. use app\common\util\Pinyin;
  5. class Role extends Base
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. public function data()
  12. {
  13. $param = input();
  14. $param['page'] = intval($param['page']) < 1 ? 1 : $param['page'];
  15. $param['limit'] = intval($param['limit']) < 1 ? $this->_pagesize : $param['limit'];
  16. $where = [];
  17. if (!empty($param['level'])) {
  18. $where['role_level'] = ['eq', $param['level']];
  19. }
  20. if (in_array($param['status'], ['0', '1'])) {
  21. $where['role_status'] = ['eq', $param['status']];
  22. }
  23. if (!empty($param['rid'])) {
  24. $where['role_rid'] = ['eq', $param['rid']];
  25. }
  26. if(!empty($param['pic'])){
  27. if($param['pic'] == '1'){
  28. $where['role_pic'] = ['eq',''];
  29. }
  30. elseif($param['pic'] == '2'){
  31. $where['role_pic'] = ['like','http%'];
  32. }
  33. elseif($param['pic'] == '3'){
  34. $where['role_pic'] = ['like','%#err%'];
  35. }
  36. }
  37. if(!empty($param['wd'])){
  38. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  39. $where['role_name'] = ['like','%'.$param['wd'].'%'];
  40. }
  41. $order='role_time desc';
  42. $res = model('Role')->listData($where,$order,$param['page'],$param['limit']);
  43. $this->assign('list', $res['list']);
  44. $this->assign('total', $res['total']);
  45. $this->assign('page', $res['page']);
  46. $this->assign('limit', $res['limit']);
  47. $param['page'] = '{page}';
  48. $param['limit'] = '{limit}';
  49. $this->assign('param', $param);
  50. $this->assign('title',lang('admin/role/title'));
  51. return $this->fetch('admin@role/index');
  52. }
  53. public function info()
  54. {
  55. if (Request()->isPost()) {
  56. $param = input('post.');
  57. $res = model('Role')->saveData($param);
  58. if($res['code']>1){
  59. return $this->error($res['msg']);
  60. }
  61. return $this->success($res['msg']);
  62. }
  63. $id = input('id');
  64. $tab = input('tab');
  65. $rid = input('rid');
  66. $where=[];
  67. $where['role_id'] = ['eq',$id];
  68. $res = model('Role')->infoData($where);
  69. $info = $res['info'];
  70. if(empty($info)){
  71. $info['role_rid'] = $rid;
  72. }
  73. $this->assign('info',$info);
  74. $where=[];
  75. $where['vod_id'] = ['eq', $info['role_rid'] ];
  76. $where['_recycle'] = 'all';
  77. $res = model('Vod')->infoData($where);
  78. $data = $res['info'];
  79. $this->assign('data',$data);
  80. $this->assign('title',lang('admin/role/title'));
  81. return $this->fetch('admin@role/info');
  82. }
  83. public function del()
  84. {
  85. $param = input();
  86. $ids = $param['ids'];
  87. if(!empty($ids)){
  88. $where=[];
  89. $where['role_id'] = ['in',$ids];
  90. $res = model('Role')->delData($where);
  91. if($res['code']>1){
  92. return $this->error($res['msg']);
  93. }
  94. return $this->success($res['msg']);
  95. }
  96. return $this->error(lang('param_err'));
  97. }
  98. public function field()
  99. {
  100. $param = input();
  101. $ids = $param['ids'];
  102. $col = $param['col'];
  103. $val = $param['val'];
  104. $start = $param['start'];
  105. $end = $param['end'];
  106. if(!empty($ids) && in_array($col,['role_status','role_lock','role_level','role_hits'])){
  107. $where=[];
  108. $where['role_id'] = ['in',$ids];
  109. if(empty($start)) {
  110. $res = model('Role')->fieldData($where, $col, $val);
  111. }
  112. else{
  113. if(empty($end)){$end = 9999;}
  114. $ids = explode(',',$ids);
  115. foreach($ids as $k=>$v){
  116. $val = rand($start,$end);
  117. $where['role_id'] = ['eq',$v];
  118. $res = model('Role')->fieldData($where, $col, $val);
  119. }
  120. }
  121. if($res['code']>1){
  122. return $this->error($res['msg']);
  123. }
  124. return $this->success($res['msg']);
  125. }
  126. return $this->error(lang('param_err'));
  127. }
  128. }