Org.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Db;
  4. class Org extends Auth
  5. {
  6. public function index(){
  7. $tree = model('Org')->showAllTree();
  8. $this->assign('tree',$tree);
  9. return $this->fetch();
  10. }
  11. /**
  12. * 新增
  13. */
  14. public function add($pid=0,$t=0){
  15. if(request()->isPost()){
  16. $res = model('Org')->addSave();
  17. if($res){
  18. $this->success('操作成功',url('index'));
  19. }else{
  20. $this->error(model('Org')->getError());
  21. }
  22. }else{
  23. $this->assign('pid',$pid);
  24. $this->assign('t',$t);
  25. return $this->fetch();
  26. }
  27. }
  28. /**
  29. * 编辑
  30. */
  31. public function edit($id=0){
  32. if(request()->isPost()){
  33. $res = model('Org')->editSave();
  34. if($res){
  35. $this->success('操作成功',url('index'));
  36. }else{
  37. $this->error(model('Org')->getError());
  38. }
  39. }else{
  40. $info = db('org')->where('id',$id)->find();
  41. $info['location'] = '';
  42. if($info && $info['lat'] && $info['lng']){
  43. $info['location'] = $info['lat'].'-'.$info['lng'];
  44. }
  45. $this->assign('info',$info);
  46. $this->assign('t',$info['type']);
  47. return $this->fetch();
  48. }
  49. }
  50. public function changeEnable($id=0,$enable=0){
  51. if($id <= 0){
  52. $this->error('参数错误');
  53. }
  54. $ret = Db::name('org')->where('id',$id)->setField('enable',$enable);
  55. if(!$ret){
  56. $this->error('操作失败');
  57. }
  58. $this->success('操作成功');
  59. }
  60. /**
  61. * 删除记录
  62. * @param int $id
  63. */
  64. public function del($id=0){
  65. if(!$id){
  66. $this->error('参数错误');
  67. }
  68. // 检查是否有子级
  69. $ret = Db::name('org')->where('parent_id',$id)->where('del',0)->find();
  70. if($ret){
  71. $this->error('有子级不能删除');
  72. }
  73. $res = Db::name('org')->where('id',$id)->setField('del',1);
  74. if($res){
  75. $this->success('删除成功');
  76. }else{
  77. $this->error('删除失败');
  78. }
  79. }
  80. /**
  81. * 授权
  82. */
  83. public function auth(){
  84. if(request()->isPost()){
  85. $res = model('Org')->authSave();
  86. if($res){
  87. $this->success('操作成功',url('index'));
  88. }else{
  89. $this->error(model('Org')->getError());
  90. }
  91. }else{
  92. $orgId = input('id/d',0);
  93. $meuns = model('Menu')->getAllMenuTree();
  94. $this->assign('menus',$meuns);
  95. $sauth = model('Org')->getOrgAuths($orgId,1);
  96. $this->assign('sauth',$sauth);
  97. $appauths = model('AppIcon')->getAllIconTree();
  98. $this->assign('appauths',$appauths);
  99. $sappauth = model('Org')->getOrgAuths($orgId,2);
  100. $this->assign('sappauth',$sappauth);
  101. $this->assign('orgId',$orgId);
  102. return $this->fetch();
  103. }
  104. }
  105. }