Group.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Group extends Base
  5. {
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. public function index()
  11. {
  12. $param = input();
  13. $where=[];
  14. if(in_array($param['status'],['0','1'],true)){
  15. $where['group_status'] = ['eq',$param['status']];
  16. }
  17. if(!empty($param['wd'])){
  18. $param['wd'] = htmlspecialchars(urldecode($param['wd']));
  19. $where['group_name'] = ['like','%'.$param['wd'].'%'];
  20. }
  21. $order='group_id asc';
  22. $res = model('Group')->listData($where,$order);
  23. $this->assign('list',$res['list']);
  24. $this->assign('total',$res['total']);
  25. $this->assign('param',$param);
  26. $this->assign('title',lang('admin/group/title'));
  27. return $this->fetch('admin@group/index');
  28. }
  29. public function info()
  30. {
  31. if (Request()->isPost()) {
  32. $param = input('post.');
  33. if($GLOBALS['config']['user']['reg_group'] == $param['group_id']){
  34. $param['group_status'] = 1;
  35. }
  36. $res = model('Group')->saveData($param);
  37. if($res['code']>1){
  38. return $this->error($res['msg']);
  39. }
  40. return $this->success($res['msg']);
  41. }
  42. $id = input('id');
  43. $where=[];
  44. $where['group_id'] = ['eq',$id];
  45. $res = model('Group')->infoData($where);
  46. $this->assign('info',$res['info']);
  47. $type_tree = model('Type')->getCache('type_tree');
  48. $this->assign('type_tree',$type_tree);
  49. $this->assign('title',lang('admin/group/title'));
  50. return $this->fetch('admin@group/info');
  51. }
  52. public function del()
  53. {
  54. $param = input();
  55. $ids = $param['ids'];
  56. if(!empty($ids)){
  57. if(strpos(','.$ids.',', ','.$GLOBALS['config']['user']['reg_group'].',')!==false){
  58. return $this->error(lang('admin/group/reg_group_del_err'));
  59. }
  60. $where=[];
  61. $where['group_id'] = ['in',$ids];
  62. $res = model('Group')->delData($where);
  63. if($res['code']>1){
  64. return $this->error($res['msg']);
  65. }
  66. return $this->success($res['msg']);
  67. }
  68. return $this->error(lang('param_err'));
  69. }
  70. public function field()
  71. {
  72. $param = input();
  73. $ids = $param['ids'];
  74. $col = $param['col'];
  75. $val = $param['val'];
  76. if(!empty($ids) && in_array($col,['group_status']) && in_array($val,['0','1'])){
  77. $where=[];
  78. $where['group_id'] = ['in',$ids];
  79. $res = model('Group')->fieldData($where,$col,$val);
  80. if($res['code']>1){
  81. return $this->error($res['msg']);
  82. }
  83. return $this->success($res['msg']);
  84. }
  85. return $this->error(lang('param_err'));
  86. }
  87. }