Role.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. $res = model('Vod')->infoData($where);
  77. $data = $res['info'];
  78. $this->assign('data',$data);
  79. $this->assign('title',lang('admin/role/title'));
  80. return $this->fetch('admin@role/info');
  81. }
  82. public function del()
  83. {
  84. $param = input();
  85. $ids = $param['ids'];
  86. if(!empty($ids)){
  87. $where=[];
  88. $where['role_id'] = ['in',$ids];
  89. $res = model('Role')->delData($where);
  90. if($res['code']>1){
  91. return $this->error($res['msg']);
  92. }
  93. return $this->success($res['msg']);
  94. }
  95. return $this->error(lang('param_err'));
  96. }
  97. public function field()
  98. {
  99. $param = input();
  100. $ids = $param['ids'];
  101. $col = $param['col'];
  102. $val = $param['val'];
  103. $start = $param['start'];
  104. $end = $param['end'];
  105. if(!empty($ids) && in_array($col,['role_status','role_lock','role_level','role_hits'])){
  106. $where=[];
  107. $where['role_id'] = ['in',$ids];
  108. if(empty($start)) {
  109. $res = model('Role')->fieldData($where, $col, $val);
  110. }
  111. else{
  112. if(empty($end)){$end = 9999;}
  113. $ids = explode(',',$ids);
  114. foreach($ids as $k=>$v){
  115. $val = rand($start,$end);
  116. $where['role_id'] = ['eq',$v];
  117. $res = model('Role')->fieldData($where, $col, $val);
  118. }
  119. }
  120. if($res['code']>1){
  121. return $this->error($res['msg']);
  122. }
  123. return $this->success($res['msg']);
  124. }
  125. return $this->error(lang('param_err'));
  126. }
  127. }