Permission.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Permission extends Model
  5. {
  6. public function getTree($condition, $root_id)
  7. {
  8. $excep = $this->exception_condition($root_id);
  9. $all = self::where($condition)->order('pid desc, sort asc')->select()->toArray();
  10. $arr = [];
  11. $company_id = Company::where('root_id', '=', $root_id)->value('id');
  12. $wework_setting = WeworksingleCompanySetting::where('company_id', '=', $company_id)->find();
  13. $wework_per = self::where('auth_name', 'in', ['企微管理', '企业微信'])->column('id');
  14. foreach ($all as $item) {
  15. ///直播开通 menu 展示
  16. if ($excep && isset($item['auth_name']) && in_array($item['auth_name'],[ '新建直播', '营销获客', '聊天管理', '业绩考核', '获客看板', '我的订单' ])) {
  17. continue;
  18. }
  19. if (!$excep && isset($item['auth_name']) && in_array($item['auth_name'],[ '直播管理' ])) {
  20. continue;
  21. }
  22. // 没开通企业微信隐藏模块功能
  23. /* if (empty($wework_setting) && (in_array($item['id'], $wework_per) || in_array($item['pid'], $wework_per))) {
  24. continue;
  25. } */
  26. if (in_array($item['id'], $wework_per) || in_array($item['pid'], $wework_per)) {
  27. continue;
  28. }
  29. /*if (empty($wework_setting) && isset($item['auth_name']) && in_array($item['auth_name'], ['企微客户', '企微管理', '企微群发', '企业微信', '客户运营', '客户群管理', '数据统计'])) {
  30. continue;
  31. }*/
  32. ///
  33. if (isset($arr[$item['id']])) {
  34. $item['child'] = $arr[$item['id']];
  35. unset($arr[$item['id']]);
  36. }
  37. $arr[$item['pid']][] = $item;
  38. }
  39. $data = [];
  40. foreach($arr as $item){
  41. $data = array_merge($data, $item);
  42. }
  43. return $data;
  44. }
  45. private function exception_condition($root_id){
  46. $condition = [
  47. ['root_id' ,'=', $root_id],
  48. ['end_at', '>', date('Y-m-d'). ' 00:00:00']
  49. ];
  50. $companybossopened = CompanyBossOpen::where($condition)->find();
  51. if(!$companybossopened){
  52. return true;
  53. }else{
  54. return false;
  55. }
  56. }
  57. }