sjoinModel.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. class sjoinClassModel extends Model
  3. {
  4. private $getgroupidarr=array();
  5. //获取用户所在组Id
  6. public function getgroupid($uid, $fid='')
  7. {
  8. if($fid=='')$fid = 'id';
  9. $keys = ''.$fid.''.$uid.'';
  10. if(isset($this->getgroupidarr[$keys]))return $this->getgroupidarr[$keys];
  11. $gasql = " ( id in( select `sid` from `[Q]sjoin` where `type`='ug' and `mid`='$uid') or id in( select `mid` from `[Q]sjoin` where `type`='gu' and `sid`='$uid') )";
  12. $gsql = "select `id` from `[Q]group` where $gasql ";
  13. $rows = $this->db->getall($gsql);
  14. $ids = '0';
  15. foreach($rows as $k=>$rs)$ids.=','.$rs[$fid].'';
  16. $this->getgroupidarr[$keys] = $ids;
  17. return $ids;
  18. }
  19. //把人员加到对应组上
  20. public function addgroupuid($uid, $gid)
  21. {
  22. $where = "1=1 and ((`type`='gu' and `sid`=$uid ) or (`type`='ug' and `mid`=$uid))";
  23. $this->delete($where);
  24. if(isempt($gid))return;
  25. $this->db->insert($this->table, '`type`,`mid`,`sid`,`indate`', "select 'ug','$uid',`id`,now() from `[Q]group` where id in($gid)", true);
  26. }
  27. //获取权限菜单id
  28. public function getmenuid($uid)
  29. {
  30. $gid = $this->getgroupid($uid);
  31. $whe1 = "select `sid` from `[Q]sjoin` where ((`type`='um' and `mid`='$uid')";
  32. $whe2 = "select `mid` from `[Q]sjoin` where ((`type`='mu' and `sid`='$uid')";
  33. if($gid != '0'){
  34. $whe1.=" or (`type`='gm' and `mid` in($gid)) ";
  35. $whe2.=" or (`type`='mg' and `sid` in($gid)) ";
  36. }
  37. $whe1.= ')';
  38. $whe2.= ')';
  39. $ids = '0';
  40. $rows = $this->db->getall($whe1);
  41. foreach($rows as $k=>$rs)$ids.=','.$rs['sid'].'';
  42. $rows = $this->db->getall($whe2);
  43. foreach($rows as $k=>$rs)$ids.=','.$rs['mid'].'';
  44. return $ids;
  45. }
  46. /**
  47. * 查看菜单权限
  48. */
  49. public function getuserext($uid, $type=0)
  50. {
  51. $guid = '-1';
  52. if($type==1)return $guid;
  53. $guid = '[0]';
  54. $mid = $this->getmenuid($uid);
  55. $arss = $this->db->getall("select `id`,`pid`,(select `pid` from `[Q]menu` where `id`=a.`pid`)as `mpid` from `[Q]menu` a where (`status` =1 and `id` in($mid)) or (`status` =1 and `ispir`=0) order by `sort`");
  56. foreach($arss as $ars){
  57. $guid .= ',['.$ars['id'].']';
  58. $bpid = $ars['pid'];
  59. $bmpid = $ars['mpid'];
  60. if(!contain($guid, '['.$bpid.']')){
  61. $guid.=',['.$bpid.']';
  62. }
  63. if(!isempt($bmpid)){
  64. if(!contain($guid, '['.$bmpid.']')){
  65. $guid.=',['.$bmpid.']';
  66. }
  67. }
  68. }
  69. return $guid;
  70. }
  71. /**
  72. * 获取组列表
  73. */
  74. public function getgrouparr()
  75. {
  76. $where = '';
  77. if(ISMORECOM){
  78. $where='where `companyid` in(0,'.m('admin')->getcompanyid().')';
  79. }
  80. return $this->db->getall("select `id`,`name` from `[Q]group` $where order by `sort`");
  81. }
  82. /**
  83. * 获取组列表
  84. */
  85. public function getgrouparrs()
  86. {
  87. $where = '';
  88. if(ISMORECOM){
  89. $where='where `companyid` in(0,'.m('admin')->getcompanyid().')';
  90. }
  91. return $this->db->getall("select `id` as value,`name` from `[Q]group` $where order by `sort`");
  92. }
  93. }
粤ICP备19079148号