Skip to content

接口

信息平台


gm_account/ma/role/create 创建角色

接口描述: 信息平台新建角色

请求方法: POST

请求参数:
    name                    M           int                角色名称
    type                   O           int                角色类型:1:通用,2:站点
    visible_station_id      O           str                可见station站点
    description             O           str                角色描述
    permission_ids          M           list[int]           权限id的列表


响应:
    id                  M               int             创建的角色id

示例
    request
        https://manage.guanmai.cn/gm_account/ma/role/create
    response
    {
        code: 0
        data: {id: 4006}
        msg: "ok"
        }
逻辑
    校验传入type类型,只有站点下的superadmin才可以创建通用角色。
    检验传入type为站点类型时,是否传入了有效的visible_station_id
    校验该用户是否拥有这些权限

    创建新角色

    返回角色id

gm_account/ma/role/search 查看角色

接口描述: 查看和本身可见站点相同或者更小的角色

请求方法: GET

请求参数: 
        search_text         O       str         角色名字


响应: 
    roles           M           list(dict) [{
                                                id                      M           int             角色id
                                                name                    M           str             角色名称
                                                type                     M           int             角色类型
                                                visible_station_id        M          str             可见station站点
                                                description             O           str             角色描述
                                                create_date             M           date            创建日期
                                                }
                                             ....
                                            ]


示例
    request
        https://manage.guanmai.cn/gm_account/ma/role/search
    response
        {
            "code": 0,
            "data": {
                "roles": [
                    {
                        "create_date": null,
                        "name": "saas测试站点",
                        "id": 124,
                        "type": 2,
                        "visible_station_id": "T123",
                        "description": "1"
                    },
                    {
                        "create_date": "2018-01-05",
                        "name": "好人",
                        "type": 1,
                        "visible_station_id": "",
                        "id": 932,
                        "description": "我是好人"
                    }
                ]
            },
            "msg": "ok"
        }

逻辑:
    搜索角色名、返回搜索角色或者该用户可见的角色

gm_account/ma/role/detail 角色详情

接口描述: 查看角色详情

请求方法: GET

请求参数: 
        id                      M               int             角色id

响应: 
    id                      M           int             角色id
    name                    M           str             角色名称
    type                     M           int             角色类型
    visible_station_id        M          str             可见station站点
    description             O           str             角色描述
    permission_ids             M           list(int)            权限id

示例
    request
        https://manage.guanmai.cn/gm_account/ma/role/detail

    response
        {
            "code": 0,
            "data": {
                "role": {
                    "name": "好人",
                    "type": 2
                    "visible_station_id": "T123"
                    "description": "我是好人"
                    "permission_ids": [
                        69,
                        106
                    ],
                }
            },
            "msg": "ok"
        }

逻辑:
    请求角色id、返回角色详情

gm_account/ma/user/search 查看用户

接口描述: 查看和本身可见站点相同或者更小的用户

请求方法: GET

请求参数: 
        is_valid    O   bool
        role_id     O   int
        search_text O   str 用户名
        is_admin    O   bool (0 或 1)    是否是管理员
        // 分页
        offset      O   int 默认 0
        limit       O   int 默认 20

响应: 
    users           M       list(dict)  [
                                            {
                                                id              M       int           用户id  
                                                username        M       str           用户名
                                                is_admin        M       bool          是否为管理员
                                                name            M       str           姓名
                                                create_date     M       str or null   创建日期
                                                is_valid        M       bool          是否有效
                                                roles           M       list({
                                                                                id      角色id
                                                                                name    角色名
                                                                            })
                                                visible_stations    M   list({
                                                                                id      站点id
                                                                                name    站点名称
                                                                            })
                                            }
                                        ]

示例
    request
        https://manage.guanmai.cn/gm_account/ma/user/search
    response
        {
            data: {
                users: [
                    {
                        id              M   int
                        username        M   str
                        roles: [
                            {
                                id: 123,
                                name: '角色名'
                            }
                        ],
                        visible_stations: [
                            {
                                id: 'T12345',
                                name: '某某站点'
                            }
                        ],
                        is_admin        M   bool
                        name            M   str
                        create_date     M   str or null
                        is_valid        M   bool
                    }
                ]
            },
            msg: 'OK',
            code: 0,
        }

逻辑
    - request 里不传的字段代表全部
    - 如果某个用户没有查到可见站点的话(employee_station_limit[mongo] 表),那么认为这个用户所属加盟商旗下的所有站点都是这个用户的可见站点

gm_account/ma/role/permission/search 查看权限

接口描述: 查看的范围修改为当前账号的所有权限

请求方法: GET

请求参数: 
        level_1_id      int         O       一级权限的id,不传代表全部一级权限
        level_2_id      int         O       二级,同上
        search_text     string      O       要搜索的权限名,不传代表全部

响应: 
        permissions           M       list(dict)  [
                                        {
                                            id              M       int           权限id  
                                            name            M       str           权限名称
                                            role_names           M       list(str)  角色名称
                                            user_count      M       int            拥有权限的用户数
                                            role_count      M       int            拥有权限的角色数
                                            level_1_name      M       str            一级权限名称
                                            level_2_name      M       str            二级权限名称
                                        }
                                    ]
示例:
    request
        https://manage.guanmai.cn/gm_account/ma/role/permission/search

    response
        {
            "code": 0,
            "data": {
                "permissions": [
                    {
                        "id": 1,
                        "name": "增加权限",
                        role_names": [  // role_names 最多有 11 条数据
                            "经理1",
                            "经理2",
                            "经理3",
                            "经理4",
                            "经理5",
                            "经理6",
                            "经理7",
                            "经理8",
                            "经理9",
                            "经理10",
                            "经理11"
                        ],
                        "user_count": 23,
                        "role_count": 49,
                        "level_1_name": "用户权限管理",
                        "level_2_name": "权限"
                    }
                ]
            },
            "msg": "ok"
        }

逻辑:
    查询出该加盟商的所有权限
    查询登录用户的可见站点、统计并过滤单条权限对应的用户数和角色

    返回所有权限和对应的信息

    特殊:
        1. user_count 和 role_count 只统计登录用户(MA管理员)所在加盟商下面的且小于等于该用户可见站点的
        2. user_count 只统计「有效」的用户,不统计「无效」的用户

gm_account/ma/meta_info meta_info

接口描述: 返回可见的站点和角色

请求方法: GET

请求参数: 
        stations            bool        O       查看可见站点(0 或 1)
        roles               bool        O       查看角色(0 或 1)
        ma_permissions      bool        O       查看权限(0 或 1)

响应: {
        role: [
            {
                id                  M           int         角色id
                name                M           str         角色名称
                type                       M       int         角色类型
                visible_station_id          M          str             可见station站点
            }
        。。。
        ]
        stations: [
            {
                id              M           str             站点id
                name            M           str             站点名称
            }
        。。。
        ]
        ma_permissions:[
            {
                id              M           id             一级权限id
                name            M           str             一级权限名称
                content         M           list(dict)[ 
                                                            id              M           id             二级权限id
                                                            name            M           str             二级权限名称
                                                            permissions     M           list(dict) [    
                                                                                                        id    M   id  权限id
                                                                                                        name  M   str 权限名称
                                                                                                    ]
                                                        ]
            }
        ]
        is_superadmin                 M                 bool        是否为加盟商的管理账号(superadmin)
}

示例:
    request
    https://manage.guanmai.cn/gm_account/ma/meta_info

    response

            data:{  stations: [ // 登录的加盟商管理员 对应的加盟商 旗下的所有站点
                        {
                            id:     123
                            name:   "测试站点"
                        }
                    ],
                    roles: [
                        {
                            id:     123
                            name:   这个橘色
                            type:   2
                            visible_station_id:   "T456"
                        }
                    ],
                    ma_permissions: [
                        {
                            "id": 1,                        // level 1 id
                            "name": "AAA",                  // level 1 name
                            "content": [
                                {
                                    "id": 4,                // level 2 id
                                    "name": "BBB",          // level 2 name
                                    "permissions": [
                                        {
                                            "id": 4,        // permission id
                                            "name": "CCC",  // permission name
                                        },
                                    ]
                                },
                            ]
                        },
                    ]
                    is_superadmin:   1
                    }