quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
 
namespace app\common\model\plus\operations;
 
use app\common\model\BaseModel;
 
/**
 * 运营中心权限模型
 */
class Access extends BaseModel
{
    protected $name = 'operations_access';
    protected $pk = 'access_id';
 
    /**
     * 获取所有权限
     */
    public static function getAll($isShow = 1)
    {
        if($isShow != -1){
            $data = static::withoutGlobalScope()
                ->where('is_show', '=', $isShow)
                ->order(['sort' => 'asc', 'create_time' => 'asc'])
                ->select();
        }else{
            $data = static::withoutGlobalScope()
                ->order(['sort' => 'asc', 'create_time' => 'asc'])
                ->select();
        }
 
        return $data ? $data->toArray() : [];
    }
 
    /**
     * 根据权限ID列表获取权限
     */
    protected static function getAllByAccessIds($access_ids)
    {
        $data = static::withoutGlobalScope()
            ->where('access_id', 'in', $access_ids)
            ->order(['sort' => 'asc', 'create_time' => 'asc'])
            ->select();
        return $data ? $data->toArray() : [];
    }
 
    /**
     * 权限信息
     */
    public static function detail($where)
    {
        if(is_array($where)){
            return (new static())->where($where)->find();
        } else{
            return (new static())->where('access_id', '=', $where)->find();
        }
    }
 
    /**
     * 获取权限url集
     */
    public static function getAccessUrls($accessIds)
    {
        $urls = [];
        foreach (static::getAll(1) as $item) {
            in_array($item['access_id'], $accessIds) && $urls[] = $item['path'];
        }
        return $urls;
    }
 
    /**
     * 获取权限url集
     */
    public static function getAccessList($accessIds)
    {
        return (new static)::withoutGlobalScope()->where('access_id', 'in', $accessIds)
            ->order(['sort' => 'asc', 'create_time' => 'asc'])
            ->select();
    }
 
    /**
     * 通过插件分类id查询
     */
    public static function getListByPlusCategoryId($category_id){
        $model = new static();
        return $model::withoutGlobalScope()->where('plus_category_id', '=', $category_id)
            ->where('is_show', '=', 1)
            ->order(['sort' => 'asc', 'create_time' => 'asc'])
            ->select();
    }
}